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;
|
||||
char * hostname;
|
||||
char ** ifaces;
|
||||
char ** vols;
|
||||
} Host;
|
||||
|
||||
|
||||
|
@ -143,6 +144,7 @@ static int _hosts_host(Config * config, Host * host, char * h, unsigned int pos)
|
|||
|
||||
host->appclient = NULL;
|
||||
host->ifaces = NULL;
|
||||
host->vols = NULL;
|
||||
if((host->hostname = malloc(pos+1)) == NULL)
|
||||
return _damon_error("malloc", 1);
|
||||
strncpy(host->hostname, h, pos);
|
||||
|
@ -152,6 +154,8 @@ static int _hosts_host(Config * config, Host * host, char * h, unsigned int pos)
|
|||
#endif
|
||||
if((p = config_get(config, host->hostname, "interfaces")) != NULL)
|
||||
host->ifaces = _host_comma(p);
|
||||
if((p = config_get(config, host->hostname, "volumes")) != NULL)
|
||||
host->vols = _host_comma(p);
|
||||
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_users(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)
|
||||
{
|
||||
unsigned int i;
|
||||
|
@ -251,7 +256,8 @@ static int _damon_refresh(DaMon * damon)
|
|||
|| _refresh_swap(ac, &hosts[i], rrd) != 0
|
||||
|| _refresh_procs(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);
|
||||
hosts[i].appclient = NULL;
|
||||
|
@ -374,6 +380,32 @@ static int _ifaces_if(AppClient * ac, Host * host, char * rrd, char * iface)
|
|||
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 _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 */
|
||||
int main(void)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user