Implemented volume information fetching (potential buffer overflows though)
This commit is contained in:
parent
fbcec89034
commit
f292ba2346
34
src/damon.c
34
src/damon.c
|
@ -19,6 +19,7 @@ typedef struct _Host
|
||||||
AppClient * appclient;
|
AppClient * appclient;
|
||||||
char * hostname;
|
char * hostname;
|
||||||
char ** ifaces;
|
char ** ifaces;
|
||||||
|
char ** vols;
|
||||||
} Host;
|
} Host;
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,6 +144,7 @@ static int _hosts_host(Config * config, Host * host, char * h, unsigned int pos)
|
||||||
|
|
||||||
host->appclient = NULL;
|
host->appclient = NULL;
|
||||||
host->ifaces = NULL;
|
host->ifaces = NULL;
|
||||||
|
host->vols = NULL;
|
||||||
if((host->hostname = malloc(pos+1)) == NULL)
|
if((host->hostname = malloc(pos+1)) == NULL)
|
||||||
return _damon_error("malloc", 1);
|
return _damon_error("malloc", 1);
|
||||||
strncpy(host->hostname, h, pos);
|
strncpy(host->hostname, h, pos);
|
||||||
|
@ -152,6 +154,8 @@ static int _hosts_host(Config * config, Host * host, char * h, unsigned int pos)
|
||||||
#endif
|
#endif
|
||||||
if((p = config_get(config, host->hostname, "interfaces")) != NULL)
|
if((p = config_get(config, host->hostname, "interfaces")) != NULL)
|
||||||
host->ifaces = _host_comma(p);
|
host->ifaces = _host_comma(p);
|
||||||
|
if((p = config_get(config, host->hostname, "volumes")) != NULL)
|
||||||
|
host->vols = _host_comma(p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,6 +228,7 @@ static int _refresh_swap(AppClient * ac, Host * host, char * rrd);
|
||||||
static int _refresh_procs(AppClient * ac, Host * host, char * rrd);
|
static int _refresh_procs(AppClient * ac, Host * host, char * rrd);
|
||||||
static int _refresh_users(AppClient * ac, Host * host, char * rrd);
|
static int _refresh_users(AppClient * ac, Host * host, char * rrd);
|
||||||
static int _refresh_ifaces(AppClient * ac, Host * host, char * rrd);
|
static int _refresh_ifaces(AppClient * ac, Host * host, char * rrd);
|
||||||
|
static int _refresh_vols(AppClient * ac, Host * host, char * rrd);
|
||||||
static int _damon_refresh(DaMon * damon)
|
static int _damon_refresh(DaMon * damon)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
@ -251,7 +256,8 @@ static int _damon_refresh(DaMon * damon)
|
||||||
|| _refresh_swap(ac, &hosts[i], rrd) != 0
|
|| _refresh_swap(ac, &hosts[i], rrd) != 0
|
||||||
|| _refresh_procs(ac, &hosts[i], rrd) != 0
|
|| _refresh_procs(ac, &hosts[i], rrd) != 0
|
||||||
|| _refresh_users(ac, &hosts[i], rrd) != 0
|
|| _refresh_users(ac, &hosts[i], rrd) != 0
|
||||||
|| _refresh_ifaces(ac, &hosts[i], rrd) != 0)
|
|| _refresh_ifaces(ac, &hosts[i], rrd) != 0
|
||||||
|
|| _refresh_vols(ac, &hosts[i], rrd) != 0)
|
||||||
{
|
{
|
||||||
appclient_delete(ac);
|
appclient_delete(ac);
|
||||||
hosts[i].appclient = NULL;
|
hosts[i].appclient = NULL;
|
||||||
|
@ -374,6 +380,32 @@ static int _ifaces_if(AppClient * ac, Host * host, char * rrd, char * iface)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _vols_vol(AppClient * ac, Host * host, char * rrd, char * vol);
|
||||||
|
static int _refresh_vols(AppClient * ac, Host * host, char * rrd)
|
||||||
|
{
|
||||||
|
char ** p = host->vols;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if(p == NULL)
|
||||||
|
return 0;
|
||||||
|
for(; *p != NULL; p++)
|
||||||
|
ret+=_vols_vol(ac, host, rrd, *p);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _vols_vol(AppClient * ac, Host * host, char * rrd, char * vol)
|
||||||
|
{
|
||||||
|
int res[2];
|
||||||
|
|
||||||
|
if((res[0] = appclient_call(ac, "voltotal", 1, vol)) == -1
|
||||||
|
|| (res[1] = appclient_call(ac, "volfree", 1, vol))
|
||||||
|
== -1)
|
||||||
|
return 1;
|
||||||
|
sprintf(rrd, "%s%s%s", host->hostname, vol, ".rrd"); /* FIXME */
|
||||||
|
_rrd_update(rrd, 2, res[0], res[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int _exec(char * argv[]);
|
static int _exec(char * argv[]);
|
||||||
static int _rrd_update(char * file, int args_cnt, ...)
|
static int _rrd_update(char * file, int args_cnt, ...)
|
||||||
{
|
{
|
||||||
|
|
34
src/probe.c
34
src/probe.c
|
@ -517,6 +517,40 @@ int iftxbytes(char * dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int voltotal(char * vol)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < probe.volinfo_cnt
|
||||||
|
&& string_compare(probe.volinfo[i].name, vol) != 0;
|
||||||
|
i++);
|
||||||
|
if(i == probe.volinfo_cnt)
|
||||||
|
return -1;
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("%s%s%s%u%s", "Volume ", probe.volinfo[i].name, " total: ",
|
||||||
|
probe.volinfo[i].total, "\n");
|
||||||
|
#endif
|
||||||
|
return probe.volinfo[i].total;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int volfree(char * vol)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < probe.volinfo_cnt
|
||||||
|
&& string_compare(probe.volinfo[i].name, vol) != 0;
|
||||||
|
i++);
|
||||||
|
if(i == probe.volinfo_cnt)
|
||||||
|
return -1;
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("%s%s%s%u%s", "Volume ", probe.volinfo[i].name, " free: ",
|
||||||
|
probe.volinfo[i].free, "\n");
|
||||||
|
#endif
|
||||||
|
return probe.volinfo[i].free;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* main */
|
/* main */
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user