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