diff --git a/src/damon-backend-salt.c b/src/damon-backend-salt.c index 504ce3b..6c6b0ed 100644 --- a/src/damon-backend-salt.c +++ b/src/damon-backend-salt.c @@ -48,6 +48,8 @@ static int _refresh_status_parse_diskusage_volume(DaMon * damon, char const * hostname, char const * volume, json_t * json); static int _refresh_status_parse_loadavg(DaMon * damon, char const * hostname, json_t * json); +static int _refresh_status_parse_procs(DaMon * damon, char const * hostname, + json_t * json); static int _refresh_status_parse_w(DaMon * damon, char const * hostname, json_t * json); @@ -127,6 +129,9 @@ static int _refresh_status_parse(DaMon * damon, json_t * json) else if(strcmp("loadavg", status) == 0) _refresh_status_parse_loadavg(damon, hostname, value); + else if(strcmp("procs", status) == 0) + _refresh_status_parse_procs(damon, hostname, + value); else if(strcmp("w", status) == 0) _refresh_status_parse_w(damon, hostname, value); } @@ -225,6 +230,30 @@ static int _refresh_status_parse_loadavg(DaMon * damon, char const * hostname, return ret; } +static int _refresh_status_parse_procs(DaMon * damon, char const * hostname, + json_t * json) +{ + int ret; + uint64_t count = 0; + size_t index; + json_t * value; + char * rrd; + +#ifdef DEBUG + fprintf(stderr, "DEBUG: %s(\"%s\", %d)\n", __func__, hostname, + json_typeof(json)); +#endif + if(!json_is_array(json)) + return -1; + json_array_foreach(json, index, value) + count++; + if((rrd = string_new_append(hostname, "/procs.rrd", NULL)) == NULL) + return -1; + ret = damon_update(damon, RRDTYPE_PROCS, rrd, 1, count); + string_delete(rrd); + return ret; +} + static int _refresh_status_parse_w(DaMon * damon, char const * hostname, json_t * json) { diff --git a/src/rrd.c b/src/rrd.c index 7622dbe..4dd9506 100644 --- a/src/rrd.c +++ b/src/rrd.c @@ -81,6 +81,15 @@ int rrd_create(RRDType type, char const * filename) argv[12] = RRD_AVERAGE_4WEEK; argv[13] = NULL; break; + case RRDTYPE_PROCS: + argv[5] = "--step"; + argv[6] = "300"; + argv[7] = "DS:procs:GAUGE:600:0:U"; + argv[8] = RRD_AVERAGE_DAY; + argv[9] = RRD_AVERAGE_WEEK; + argv[10] = RRD_AVERAGE_4WEEK; + argv[11] = NULL; + break; case RRDTYPE_USERS: argv[5] = "--step"; argv[6] = "300"; diff --git a/src/rrd.h b/src/rrd.h index b62f8b5..2d1254e 100644 --- a/src/rrd.h +++ b/src/rrd.h @@ -27,6 +27,7 @@ typedef enum _RRDType { RRDTYPE_UNKNOWN = 0, RRDTYPE_LOAD, + RRDTYPE_PROCS, RRDTYPE_USERS, RRDTYPE_VOLUME } RRDType;