X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fvserver.c;h=42577652697046059896b6d9a67746ad5333bc3c;hb=a802557560543782e606fa1d90f1b2d7b9c4ee9e;hp=a6befa7eef2bfbbaf69c82608eb02f354587306b;hpb=5e70f2e08a23dd7c05d6124200bc030b30b11ebc;p=collectd.git diff --git a/src/vserver.c b/src/vserver.c index a6befa7e..42577652 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -43,29 +43,65 @@ # define VSERVER_HAVE_READ 0 #endif /* defined(KERNEL_LINUX) */ -static char *rrd_socket = "vserver-%s/socket.rrd"; -static char *rrd_thread = "vserver-%s/threads.rrd"; +static char *rrd_unix = "vserver-%s/traffic-unix.rrd"; +static char *rrd_inet = "vserver-%s/traffic-inet.rrd"; +static char *rrd_inet6 = "vserver-%s/traffic-inet6.rrd"; +static char *rrd_other = "vserver-%s/traffic-other.rrd"; +static char *rrd_unspec = "vserver-%s/traffic-unspec.rrd"; + +static char *rrd_thread = "vserver-%s/vs_threads.rrd"; + static char *rrd_load = "vserver-%s/load.rrd"; -static char *rrd_procs = "vserver-%s/processes.rrd"; -static char *rrd_memory = "vserver-%s/memory.rrd"; + +static char *rrd_procs = "vserver-%s/vs_processes.rrd"; +static char *rrd_memory = "vserver-%s/vs_memory.rrd"; /* 9223372036854775807 == LLONG_MAX */ /* bytes transferred */ -static char *ds_def_socket[] = +static char *ds_def_unix[] = +{ + "DS:incoming:COUNTER:25:0:9223372036854775807", + "DS:outgoing:COUNTER:25:0:9223372036854775807", + "DS:failed:COUNTER:25:0:9223372036854775807", + NULL +}; +static int ds_num_unix = 3; + +static char *ds_def_inet[] = +{ + "DS:incoming:COUNTER:25:0:9223372036854775807", + "DS:outgoing:COUNTER:25:0:9223372036854775807", + "DS:failed:COUNTER:25:0:9223372036854775807", + NULL +}; +static int ds_num_inet = 3; + +static char *ds_def_inet6[] = +{ + "DS:incoming:COUNTER:25:0:9223372036854775807", + "DS:outgoing:COUNTER:25:0:9223372036854775807", + "DS:failed:COUNTER:25:0:9223372036854775807", + NULL +}; +static int ds_num_inet6 = 3; + +static char *ds_def_other[] = +{ + "DS:incoming:COUNTER:25:0:9223372036854775807", + "DS:outgoing:COUNTER:25:0:9223372036854775807", + "DS:failed:COUNTER:25:0:9223372036854775807", + NULL +}; +static int ds_num_other = 3; + +static char *ds_def_unspec[] = { - "DS:unix_in:COUNTER:25:0:9223372036854775807", - "DS:unix_out:COUNTER:25:0:9223372036854775807", - "DS:inet_in:COUNTER:25:0:9223372036854775807", - "DS:inet_out:COUNTER:25:0:9223372036854775807", - "DS:inet6_in:COUNTER:25:0:9223372036854775807", - "DS:inet6_out:COUNTER:25:0:9223372036854775807", - "DS:other_in:COUNTER:25:0:9223372036854775807", - "DS:other_out:COUNTER:25:0:9223372036854775807", - "DS:unspec_in:COUNTER:25:0:9223372036854775807", - "DS:unspec_out:COUNTER:25:0:9223372036854775807", + "DS:incoming:COUNTER:25:0:9223372036854775807", + "DS:outgoing:COUNTER:25:0:9223372036854775807", + "DS:failed:COUNTER:25:0:9223372036854775807", NULL }; -static int ds_num_socket = 10; +static int ds_num_unspec = 3; static char *ds_def_threads[] = { @@ -79,9 +115,9 @@ static int ds_num_threads = 4; static char *ds_def_load[] = { - "DS:avg1:GAUGE:25:0:100", - "DS:avg5:GAUGE:25:0:100", - "DS:avg15:GAUGE:25:0:100", + "DS:shortterm:GAUGE:25:0:100", + "DS:midterm:GAUGE:25:0:100", + "DS:longterm:GAUGE:25:0:100", NULL }; static int ds_num_load = 3; @@ -115,16 +151,60 @@ static void vserver_init (void) return; } /* static void vserver_init(void) */ -static void vserver_socket_write (char *host, char *inst, char *val) +static void vserver_unix_write (char *host, char *inst, char *val) +{ + int len; + char filename[BUFSIZE]; + + len = snprintf (filename, BUFSIZE, rrd_unix, inst); + if ((len > 0) && (len < BUFSIZE)) + rrd_update_file (host, filename, val, ds_def_unix, ds_num_unix); + return; +} /* static void vserver_unix_write(char *host, char *inst, char *val) */ + +static void vserver_inet_write (char *host, char *inst, char *val) { int len; char filename[BUFSIZE]; - len = snprintf (filename, BUFSIZE, rrd_socket, inst); + len = snprintf (filename, BUFSIZE, rrd_inet, inst); if ((len > 0) && (len < BUFSIZE)) - rrd_update_file (host, filename, val, ds_def_socket, ds_num_socket); + rrd_update_file (host, filename, val, ds_def_inet, ds_num_inet); return; -} /* static void vserver_socket_write(char *host, char *inst, char *val) */ +} /* static void vserver_inet_write(char *host, char *inst, char *val) */ + +static void vserver_inet6_write (char *host, char *inst, char *val) +{ + int len; + char filename[BUFSIZE]; + + len = snprintf (filename, BUFSIZE, rrd_inet6, inst); + if ((len > 0) && (len < BUFSIZE)) + rrd_update_file (host, filename, val, ds_def_inet6, ds_num_inet6); + return; +} /* static void vserver_inet6_write(char *host, char *inst, char *val) */ + +static void vserver_other_write (char *host, char *inst, char *val) +{ + int len; + char filename[BUFSIZE]; + + len = snprintf (filename, BUFSIZE, rrd_other, inst); + if ((len > 0) && (len < BUFSIZE)) + rrd_update_file (host, filename, val, ds_def_other, ds_num_other); + return; +} /* static void vserver_other_write(char *host, char *inst, char *val) */ + +static void vserver_unspec_write (char *host, char *inst, char *val) +{ + int len; + char filename[BUFSIZE]; + + len = snprintf (filename, BUFSIZE, rrd_unspec, inst); + if ((len > 0) && (len < BUFSIZE)) + rrd_update_file (host, filename, val, ds_def_unspec, ds_num_unspec); + return; +} /* static void vserver_unspec_write(char *host, char *inst, char *val) */ static void vserver_threads_write (char *host, char *inst, char *val) { @@ -172,9 +252,11 @@ static void vserver_memory_write (char *host, char *inst, char *val) #if VSERVER_HAVE_READ static void vserver_submit (char *inst, long long unix_in, long long unix_out, - long long inet_in, long long inet_out, long long inet6_in, - long long inet6_out, long long other_in, long long other_out, - long long unspec_in, long long unspec_out, int t_total, int t_running, + long long unix_failed, long long inet_in, long long inet_out, + long long inet_failed, long long inet6_in, long long inet6_out, + long long inet6_failed, long long other_in, long long other_out, + long long other_failed, long long unspec_in, long long unspec_out, + long long unspec_failed, int t_total, int t_running, int t_uninterruptible, int t_onhold, double avg1, double avg5, double avg15, int p_total, long long vm, long long vml, long long rss, long long anon) @@ -183,12 +265,38 @@ static void vserver_submit (char *inst, long long unix_in, long long unix_out, char buffer[BUFSIZE]; len = snprintf (buffer, BUFSIZE, - "N:%lld:%lld:%lld:%lld:%lld:%lld:%lld:%lld:%lld:%lld", - unix_in, unix_out, inet_in, inet_out, inet6_in, inet6_out, - other_in, other_out, unspec_in, unspec_out); + "N:%lld:%lld:%lld", unix_in, unix_out, unix_failed); + + if ((len > 0) && (len < BUFSIZE)) + plugin_submit ("vserver_unix", inst, buffer); + + + len = snprintf (buffer, BUFSIZE, + "N:%lld:%lld:%lld", inet_in, inet_out, inet_failed); + + if ((len > 0) && (len < BUFSIZE)) + plugin_submit ("vserver_inet", inst, buffer); + + + len = snprintf (buffer, BUFSIZE, + "N:%lld:%lld:%lld", inet6_in, inet6_out, inet6_failed); + + if ((len > 0) && (len < BUFSIZE)) + plugin_submit ("vserver_inet6", inst, buffer); + + + len = snprintf (buffer, BUFSIZE, + "N:%lld:%lld:%lld", other_in, other_out, other_failed); + + if ((len > 0) && (len < BUFSIZE)) + plugin_submit ("vserver_other", inst, buffer); + + + len = snprintf (buffer, BUFSIZE, + "N:%lld:%lld:%lld", unspec_in, unspec_out, unspec_failed); if ((len > 0) && (len < BUFSIZE)) - plugin_submit ("vserver_socket", inst, buffer); + plugin_submit ("vserver_unspec", inst, buffer); len = snprintf (buffer, BUFSIZE, "N:%d:%d:%d:%d", @@ -250,7 +358,11 @@ static void vserver_read (void) char *cols[4]; - long long socket[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; + long long unix_s[3] = {-1, -1, -1}; + long long inet[3] = {-1, -1, -1}; + long long inet6[3] = {-1, -1, -1}; + long long other[3] = {-1, -1, -1}; + long long unspec[3] = {-1, -1, -1}; int threads[4] = {-1, -1, -1, -1}; double load[3] = {-1, -1, -1}; /* Just to be consistent ;-) */ @@ -277,28 +389,33 @@ static void vserver_read (void) } while (NULL != fgets (buffer, BUFSIZE, fh)) { - if (strsplit (buffer, cols, 3) < 3) + if (strsplit (buffer, cols, 4) < 4) continue; if (0 == strcmp (cols[0], "UNIX:")) { - socket[0] = __get_sock_bytes (cols[1]); - socket[1] = __get_sock_bytes (cols[2]); + unix_s[0] = __get_sock_bytes (cols[1]); + unix_s[1] = __get_sock_bytes (cols[2]); + unix_s[2] = __get_sock_bytes (cols[3]); } else if (0 == strcmp (cols[0], "INET:")) { - socket[2] = __get_sock_bytes (cols[1]); - socket[3] = __get_sock_bytes (cols[2]); + inet[0] = __get_sock_bytes (cols[1]); + inet[1] = __get_sock_bytes (cols[2]); + inet[2] = __get_sock_bytes (cols[3]); } else if (0 == strcmp (cols[0], "INET6:")) { - socket[4] = __get_sock_bytes (cols[1]); - socket[5] = __get_sock_bytes (cols[2]); + inet6[0] = __get_sock_bytes (cols[1]); + inet6[1] = __get_sock_bytes (cols[2]); + inet6[2] = __get_sock_bytes (cols[3]); } else if (0 == strcmp (cols[0], "OTHER:")) { - socket[6] = __get_sock_bytes (cols[1]); - socket[7] = __get_sock_bytes (cols[2]); + other[0] = __get_sock_bytes (cols[1]); + other[1] = __get_sock_bytes (cols[2]); + other[2] = __get_sock_bytes (cols[3]); } else if (0 == strcmp (cols[0], "UNSPEC:")) { - socket[8] = __get_sock_bytes (cols[1]); - socket[9] = __get_sock_bytes (cols[2]); + unspec[0] = __get_sock_bytes (cols[1]); + unspec[1] = __get_sock_bytes (cols[2]); + unspec[2] = __get_sock_bytes (cols[3]); } } @@ -378,11 +495,12 @@ static void vserver_read (void) /* XXX What to do in case of an error (i.e. some value is * still -1)? */ - vserver_submit (dent->d_name, socket[0], socket[1], socket[2], - socket[3], socket[4], socket[5], socket[6], socket[7], - socket[8], socket[9], threads[0], threads[1], threads[2], - threads[3], load[0], load[1], load[2], procs[0], memory[0], - memory[1], memory[2], memory[3]); + vserver_submit (dent->d_name, unix_s[0], unix_s[1], unix_s[2], + inet[0], inet[1], inet[2], inet6[0], inet6[1], inet6[2], + other[0], other[1], other[2], unspec[0], unspec[1], unspec[2], + threads[0], threads[1], threads[2], threads[3], load[0], + load[1], load[2], procs[0], memory[0], memory[1], memory[2], + memory[3]); } closedir (proc); @@ -395,7 +513,11 @@ static void vserver_read (void) void module_register (void) { plugin_register (MODULE_NAME, vserver_init, vserver_read, NULL); - plugin_register ("vserver_socket", NULL, NULL, vserver_socket_write); + plugin_register ("vserver_unix", NULL, NULL, vserver_unix_write); + plugin_register ("vserver_inet", NULL, NULL, vserver_inet_write); + plugin_register ("vserver_inet6", NULL, NULL, vserver_inet6_write); + plugin_register ("vserver_other", NULL, NULL, vserver_other_write); + plugin_register ("vserver_unspec", NULL, NULL, vserver_unspec_write); plugin_register ("vserver_threads", NULL, NULL, vserver_threads_write); plugin_register ("vserver_load", NULL, NULL, vserver_load_write); plugin_register ("vserver_procs", NULL, NULL, vserver_procs_write);