9 #include "plugin_proc.h"
11 #define RRD_TYPE_NET_IPVS "ipvs"
12 #define RRD_TYPE_NET_IPVS_LEN strlen(RRD_TYPE_NET_IPVS)
14 int do_proc_net_ip_vs_stats(int update_every, unsigned long long dt) {
15 static int do_bandwidth = -1, do_sockets = -1, do_packets = -1;
16 static procfile *ff = NULL;
18 if(do_bandwidth == -1) do_bandwidth = config_get_boolean("plugin:proc:/proc/net/ip_vs_stats", "IPVS bandwidth", 1);
19 if(do_sockets == -1) do_sockets = config_get_boolean("plugin:proc:/proc/net/ip_vs_stats", "IPVS connections", 1);
20 if(do_packets == -1) do_packets = config_get_boolean("plugin:proc:/proc/net/ip_vs_stats", "IPVS packets", 1);
25 char filename[FILENAME_MAX + 1];
26 snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/ip_vs_stats");
27 ff = procfile_open(config_get("plugin:proc:/proc/net/ip_vs_stats", "filename to monitor", filename), " \t,:|", PROCFILE_FLAG_DEFAULT);
31 ff = procfile_readall(ff);
32 if(!ff) return 0; // we return 0, so that we will retry to open it next time
34 // make sure we have 3 lines
35 if(procfile_lines(ff) < 3) return 1;
37 // make sure we have 5 words on the 3rd line
38 if(procfile_linewords(ff, 2) < 5) return 1;
40 unsigned long long entries, InPackets, OutPackets, InBytes, OutBytes;
42 entries = strtoull(procfile_lineword(ff, 2, 0), NULL, 16);
43 InPackets = strtoull(procfile_lineword(ff, 2, 1), NULL, 16);
44 OutPackets = strtoull(procfile_lineword(ff, 2, 2), NULL, 16);
45 InBytes = strtoull(procfile_lineword(ff, 2, 3), NULL, 16);
46 OutBytes = strtoull(procfile_lineword(ff, 2, 4), NULL, 16);
50 // --------------------------------------------------------------------
53 st = rrdset_find(RRD_TYPE_NET_IPVS ".sockets");
55 st = rrdset_create(RRD_TYPE_NET_IPVS, "sockets", NULL, RRD_TYPE_NET_IPVS, "IPVS New Connections", "connections/s", 1001, update_every, RRDSET_TYPE_LINE);
57 rrddim_add(st, "connections", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
61 rrddim_set(st, "connections", entries);
65 // --------------------------------------------------------------------
68 st = rrdset_find(RRD_TYPE_NET_IPVS ".packets");
70 st = rrdset_create(RRD_TYPE_NET_IPVS, "packets", NULL, RRD_TYPE_NET_IPVS, "IPVS Packets", "packets/s", 1002, update_every, RRDSET_TYPE_LINE);
72 rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
73 rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
77 rrddim_set(st, "received", InPackets);
78 rrddim_set(st, "sent", OutPackets);
82 // --------------------------------------------------------------------
85 st = rrdset_find(RRD_TYPE_NET_IPVS ".net");
87 st = rrdset_create(RRD_TYPE_NET_IPVS, "net", NULL, RRD_TYPE_NET_IPVS, "IPVS Bandwidth", "kilobits/s", 1000, update_every, RRDSET_TYPE_AREA);
89 rrddim_add(st, "received", NULL, 8, 1024 * update_every, RRDDIM_INCREMENTAL);
90 rrddim_add(st, "sent", NULL, -8, 1024 * update_every, RRDDIM_INCREMENTAL);
94 rrddim_set(st, "received", InBytes);
95 rrddim_set(st, "sent", OutBytes);