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