Add support for process count

This commit is contained in:
Pierre Pronchery 2016-02-05 00:49:06 +01:00
parent 2d675dbf40
commit bbc9ff99cb
3 changed files with 39 additions and 0 deletions

View File

@ -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)
{

View File

@ -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";

View File

@ -27,6 +27,7 @@ typedef enum _RRDType
{
RRDTYPE_UNKNOWN = 0,
RRDTYPE_LOAD,
RRDTYPE_PROCS,
RRDTYPE_USERS,
RRDTYPE_VOLUME
} RRDType;