]> arthur.barton.de Git - netdata.git/blob - src/proc_net_ip_vs_stats.c
Merge pull request #1594 from ktsaou/master
[netdata.git] / src / proc_net_ip_vs_stats.c
1 #include "common.h"
2
3 #define RRD_TYPE_NET_IPVS           "ipvs"
4
5 int do_proc_net_ip_vs_stats(int update_every, usec_t dt) {
6     static int do_bandwidth = -1, do_sockets = -1, do_packets = -1;
7     static procfile *ff = NULL;
8
9     if(do_bandwidth == -1)  do_bandwidth    = config_get_boolean("plugin:proc:/proc/net/ip_vs_stats", "IPVS bandwidth", 1);
10     if(do_sockets == -1)    do_sockets      = config_get_boolean("plugin:proc:/proc/net/ip_vs_stats", "IPVS connections", 1);
11     if(do_packets == -1)    do_packets      = config_get_boolean("plugin:proc:/proc/net/ip_vs_stats", "IPVS packets", 1);
12
13     if(dt) {};
14
15     if(!ff) {
16         char filename[FILENAME_MAX + 1];
17         snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/ip_vs_stats");
18         ff = procfile_open(config_get("plugin:proc:/proc/net/ip_vs_stats", "filename to monitor", filename), " \t,:|", PROCFILE_FLAG_DEFAULT);
19     }
20     if(!ff) return 1;
21
22     ff = procfile_readall(ff);
23     if(!ff) return 0; // we return 0, so that we will retry to open it next time
24
25     // make sure we have 3 lines
26     if(procfile_lines(ff) < 3) return 1;
27
28     // make sure we have 5 words on the 3rd line
29     if(procfile_linewords(ff, 2) < 5) return 1;
30
31     unsigned long long entries, InPackets, OutPackets, InBytes, OutBytes;
32
33     entries     = strtoull(procfile_lineword(ff, 2, 0), NULL, 16);
34     InPackets   = strtoull(procfile_lineword(ff, 2, 1), NULL, 16);
35     OutPackets  = strtoull(procfile_lineword(ff, 2, 2), NULL, 16);
36     InBytes     = strtoull(procfile_lineword(ff, 2, 3), NULL, 16);
37     OutBytes    = strtoull(procfile_lineword(ff, 2, 4), NULL, 16);
38
39     RRDSET *st;
40
41     // --------------------------------------------------------------------
42
43     if(do_sockets) {
44         st = rrdset_find(RRD_TYPE_NET_IPVS ".sockets");
45         if(!st) {
46             st = rrdset_create(RRD_TYPE_NET_IPVS, "sockets", NULL, RRD_TYPE_NET_IPVS, NULL, "IPVS New Connections", "connections/s", 3101, update_every, RRDSET_TYPE_LINE);
47
48             rrddim_add(st, "connections", NULL, 1, 1, RRDDIM_INCREMENTAL);
49         }
50         else rrdset_next(st);
51
52         rrddim_set(st, "connections", entries);
53         rrdset_done(st);
54     }
55
56     // --------------------------------------------------------------------
57
58     if(do_packets) {
59         st = rrdset_find(RRD_TYPE_NET_IPVS ".packets");
60         if(!st) {
61             st = rrdset_create(RRD_TYPE_NET_IPVS, "packets", NULL, RRD_TYPE_NET_IPVS, NULL, "IPVS Packets", "packets/s", 3102, update_every, RRDSET_TYPE_LINE);
62
63             rrddim_add(st, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
64             rrddim_add(st, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
65         }
66         else rrdset_next(st);
67
68         rrddim_set(st, "received", InPackets);
69         rrddim_set(st, "sent", OutPackets);
70         rrdset_done(st);
71     }
72
73     // --------------------------------------------------------------------
74
75     if(do_bandwidth) {
76         st = rrdset_find(RRD_TYPE_NET_IPVS ".net");
77         if(!st) {
78             st = rrdset_create(RRD_TYPE_NET_IPVS, "net", NULL, RRD_TYPE_NET_IPVS, NULL, "IPVS Bandwidth", "kilobits/s", 3100, update_every, RRDSET_TYPE_AREA);
79
80             rrddim_add(st, "received", NULL, 8, 1024, RRDDIM_INCREMENTAL);
81             rrddim_add(st, "sent", NULL, -8, 1024, RRDDIM_INCREMENTAL);
82         }
83         else rrdset_next(st);
84
85         rrddim_set(st, "received", InBytes);
86         rrddim_set(st, "sent", OutBytes);
87         rrdset_done(st);
88     }
89
90     return 0;
91 }