3 static inline char *softnet_column_name(uint32_t column) {
4 static char buf[4] = "c00";
8 case 0: s = "total"; break;
9 case 1: s = "dropped"; break;
10 case 2: s = "squeezed"; break;
11 case 8: s = "collisions"; break;
13 uint32_t c = column + 1;
14 buf[1] = '0' + ( c / 10); c = c % 10;
24 int do_proc_net_softnet_stat(int update_every, unsigned long long dt) {
27 static procfile *ff = NULL;
28 static int do_per_core = -1;
29 static uint32_t allocated_lines = 0, allocated_columns = 0, *data = NULL;
31 if(do_per_core == -1) do_per_core = config_get_boolean("plugin:proc:/proc/net/softnet_stat", "softnet_stat per core", 1);
34 char filename[FILENAME_MAX + 1];
35 snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/softnet_stat");
36 ff = procfile_open(config_get("plugin:proc:/proc/net/softnet_stat", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
40 ff = procfile_readall(ff);
41 if(!ff) return 0; // we return 0, so that we will retry to open it next time
43 uint32_t lines = procfile_lines(ff), l;
44 uint32_t words = procfile_linewords(ff, 0), w;
46 if(!lines || !words) {
47 error("Cannot read /proc/net/softnet_stat, %u lines and %u columns reported.", lines, words);
51 if(lines > 200) lines = 200;
52 if(words > 50) words = 50;
54 if(unlikely(!data || lines > allocated_lines || words > allocated_columns)) {
56 allocated_lines = lines;
57 allocated_columns = words;
58 data = mallocz((allocated_lines + 1) * allocated_columns * sizeof(uint32_t));
62 bzero(data, (allocated_lines + 1) * allocated_columns * sizeof(uint32_t));
65 for(l = 0; l < lines ;l++) {
66 words = procfile_linewords(ff, l);
69 if(words > allocated_columns) words = allocated_columns;
71 for(w = 0; w < words ; w++) {
72 uint32_t t = strtoul(procfile_lineword(ff, l, w), NULL, 16);
74 data[((l + 1) * allocated_columns) + w] = t;
78 if(data[(lines * allocated_columns)] == 0)
83 // --------------------------------------------------------------------
85 st = rrdset_find_bytype("system", "softnet_stat");
87 st = rrdset_create("system", "softnet_stat", NULL, "softnet_stat", NULL, "System softnet_stat", "events/s", 955, update_every, RRDSET_TYPE_LINE);
88 for(w = 0; w < allocated_columns ;w++)
89 rrddim_add(st, softnet_column_name(w), NULL, 1, 1, RRDDIM_INCREMENTAL);
93 for(w = 0; w < allocated_columns ;w++)
94 rrddim_set(st, softnet_column_name(w), data[w]);
99 for(l = 0; l < lines ;l++) {
101 snprintfz(id, 50, "cpu%d_softnet_stat", l);
103 st = rrdset_find_bytype("cpu", id);
106 snprintfz(title, 100, "CPU%d softnet_stat", l);
108 st = rrdset_create("cpu", id, NULL, "softnet_stat", NULL, title, "events/s", 4101 + l, update_every, RRDSET_TYPE_LINE);
109 for(w = 0; w < allocated_columns ;w++)
110 rrddim_add(st, softnet_column_name(w), NULL, 1, 1, RRDDIM_INCREMENTAL);
112 else rrdset_next(st);
114 for(w = 0; w < allocated_columns ;w++)
115 rrddim_set(st, softnet_column_name(w), data[((l + 1) * allocated_columns) + w]);