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