Collector slabinfo (#6800)
### Summary Provide new collector parsing `/proc/slabinfo` to provide details on kernel slab structures. Asked by issue #13 (very happy for the oldest issue in backlog) ##### Component Name collectors/slabinfo.plugin ##### Additional Information This slabinfo details allows to have clues on actions done on your system. In the following screenshot, you can clearly see a `find` done on a ext4 filesystem (the number of `ext4_inode_cache` & `dentry` are rising fast), and a few seconds later, an admin issued a `echo 3 > /proc/sys/vm/drop_cached` as their count dropped.
Adrien Mahieux committed
Sep 18, 2019 at 14:13 UTC
0942680f85a3fb0a03bc8c211fcc9d286572c242
16 files changed
+527
-2
.gitignore
+3
@@ -59,6 +59,9 @@ xenstat.plugin
59
perf.plugin
60
!perf.plugin/
61
62
+slabinfo.plugin
63
+!slabinfo.plugin/
64
+
65
cgroup-network
66
!cgroup-network/
67
CMakeLists.txt
+21
@@ -400,6 +400,10 @@ set(PERF_PLUGIN_FILES
400
collectors/perf.plugin/perf_plugin.c
401
)
402
403
+set(SLABINFO_PLUGIN_FILES
404
+ collectors/slabinfo.plugin/slabinfo.c
405
+ )
406
+
407
set(PROC_PLUGIN_FILES
408
collectors/proc.plugin/ipc.c
409
collectors/proc.plugin/plugin_proc.c
@@ -728,6 +732,7 @@ IF(LINUX)
732
SET(ENABLE_PLUGIN_CGROUP_NETWORK True)
733
SET(ENABLE_PLUGIN_APPS True)
734
SET(ENABLE_PLUGIN_PERF True)
735
+ SET(ENABLE_PLUGIN_SLABINFO True)
736
737
ELSEIF(FREEBSD)
738
add_executable(netdata config.h ${NETDATA_FILES} ${FREEBSD_PLUGIN_FILES})
@@ -737,6 +742,7 @@ ELSEIF(FREEBSD)
742
SET(ENABLE_PLUGIN_CGROUP_NETWORK False)
743
SET(ENABLE_PLUGIN_APPS True)
744
SET(ENABLE_PLUGIN_PERF False)
745
+ SET(ENABLE_PLUGIN_SLABINFO False)
746
747
ELSEIF(MACOS)
748
add_executable(netdata config.h ${NETDATA_FILES} ${MACOS_PLUGIN_FILES})
@@ -746,6 +752,7 @@ ELSEIF(MACOS)
752
SET(ENABLE_PLUGIN_CGROUP_NETWORK False)
753
SET(ENABLE_PLUGIN_APPS False)
754
SET(ENABLE_PLUGIN_PERF False)
755
+ SET(ENABLE_PLUGIN_SLABINFO False)
756
757
ENDIF()
758
@@ -843,6 +850,20 @@ ELSE()
850
ENDIF()
851
852
853
+# -----------------------------------------------------------------------------
854
+# slabinfo.plugin
855
+
856
+IF(ENABLE_PLUGIN_SLABINFO)
857
+ message(STATUS "slabinfo.plugin: enabled")
858
+ add_executable(slabinfo.plugin config.h ${SLABINFO_PLUGIN_FILES})
859
+ target_link_libraries (slabinfo.plugin libnetdata ${NETDATA_COMMON_LIBRARIES})
860
+ target_include_directories(slabinfo.plugin PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS})
861
+ target_compile_options(slabinfo.plugin PUBLIC ${NETDATA_COMMON_CFLAGS})
862
+ELSE()
863
+ message(STATUS "slabinfo.plugin: disabled")
864
+ENDIF()
865
+
866
+
867
# -----------------------------------------------------------------------------
868
# cgroup-network
869
Makefile.am
+13
@@ -236,6 +236,11 @@ NFACCT_PLUGIN_FILES = \
236
$(LIBNETDATA_FILES) \
237
$(NULL)
238
239
+SLABINFO_PLUGIN_FILES = \
240
+ collectors/slabinfo.plugin/slabinfo.c \
241
+ $(LIBNETDATA_FILES)
242
+ $(NULL)
243
+
244
XENSTAT_PLUGIN_FILES = \
245
collectors/xenstat.plugin/xenstat_plugin.c \
246
$(LIBNETDATA_FILES) \
@@ -600,6 +605,14 @@ if ENABLE_PLUGIN_PERF
605
$(NULL)
606
endif
607
608
+if ENABLE_PLUGIN_SLABINFO
609
+ plugins_PROGRAMS += slabinfo.plugin
610
+ slabinfo_plugin_SOURCES = $(SLABINFO_PLUGIN_FILES)
611
+ slabinfo_plugin_LDADD = \
612
+ $(NETDATA_COMMON_LIBS) \
613
+ $(NULL)
614
+endif
615
+
616
if ENABLE_BACKEND_KINESIS
617
netdata_SOURCES += $(KINESIS_BACKEND_FILES)
618
netdata_LDADD += $(OPTIONAL_KINESIS_LIBS)
collectors/Makefile.am
+1
@@ -22,6 +22,7 @@ SUBDIRS = \
22
node.d.plugin \
23
proc.plugin \
24
python.d.plugin \
25
+ slabinfo.plugin \
26
statsd.plugin \
27
tc.plugin \
28
$(NULL)
collectors/README.md
+1
@@ -42,6 +42,7 @@ To minimize the number of processes spawn for data collection, Netdata also supp
42
|[plugins.d](plugins.d/)|`C`|any|internal|-|implements the **external plugins** API and serves external plugins|
43
|[proc.plugin](proc.plugin/)|`C`|linux|internal|yes|collects resource usage and performance data on Linux systems|
44
|[python.d.plugin](python.d.plugin/)|`python` v2+|any|external|yes|a **plugin orchestrator** for data collection modules written in `python` v2 or v3 (both are supported).|
45
+|[slabinfo.plugin](slabinfo.plugin/)|`C`|linux|external|-|collects kernel SLAB details on Linux systems|
46
|[statsd.plugin](statsd.plugin/)|`C`|any|internal|-|implements a high performance **statsd** server for Netdata|
47
|[tc.plugin](tc.plugin/)|`C`|linux|internal|-|collects traffic QoS metrics (`tc`) of Linux network interfaces|
48
collectors/apps.plugin/apps_groups.conf
+1
@@ -85,6 +85,7 @@ tc-qos-helper: *tc-qos-helper.sh*
85
fping: fping
86
ioping: ioping
87
go.d.plugin: *go.d.plugin*
88
+slabinfo.plugin: slabinfo.plugin
89
90
# -----------------------------------------------------------------------------
91
# authentication/authorization related servers
collectors/plugins.d/README.md
+1
@@ -18,6 +18,7 @@ from external processes, thus allowing Netdata to use **external plugins**.
18
|[perf.plugin](../perf.plugin/)|`C`|linux|collects CPU performance metrics using performance monitoring units (PMU).|
19
|[node.d.plugin](../node.d.plugin/)|`node.js`|all|a **plugin orchestrator** for data collection modules written in `node.js`.|
20
|[python.d.plugin](../python.d.plugin/)|`python`|all|a **plugin orchestrator** for data collection modules written in `python` v2 or v3 (both are supported).|
21
+|[slabinfo.plugin](../slabinfo.plugin/)|`C`|linux|collects kernel internal cache objects (SLAB) metrics.|
22
23
Plugin orchestrators may also be described as **modular plugins**. They are modular since they accept custom made modules to be included. Writing modules for these plugins is easier than accessing the native Netdata API directly. You will find modules already available for each orchestrator under the directory of the particular modular plugin (e.g. under python.d.plugin for the python orchestrator).
24
Each of these modular plugins has each own methods for defining modules. Please check the examples and their documentation.
collectors/slabinfo.plugin/Makefile.am
new
+14
@@ -0,0 +1,14 @@
1
+# SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+AUTOMAKE_OPTIONS = subdir-objects
4
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
5
+CLEANFILES = \
6
+ slabinfo.plugin \
7
+ $(NULL)
8
+
9
+include $(top_srcdir)/build/subst.inc
10
+SUFFIXES = .in
11
+
12
+dist_noinst_DATA = \
13
+ README.md \
14
+ $(NULL)
collectors/slabinfo.plugin/README.md
new
+22
@@ -0,0 +1,22 @@
1
+# slabinfo.plugin
2
+
3
+SLAB is a cache mechanism used by the Kernel to avoid fragmentation.
4
+
5
+Each internal structure (process, file descriptor, inode...) is stored within a SLAB.
6
+
7
+
8
+## configuring Netdata for slabinfo
9
+
10
+There is currently no configuration needed.
11
+
12
+As `/proc/slabinfo` is only readable by root, this plugin is setuid root.
13
+
14
+## For what use
15
+
16
+This slabinfo details allows to have clues on actions done on your system.
17
+In the following screenshot, you can clearly see a `find` done on a ext4 filesystem (the number of `ext4_inode_cache` & `dentry` are rising fast), and a few seconds later, an admin issued a `echo 3 > /proc/sys/vm/drop_cached` as their count dropped.
18
+
19
+
20
+
21
+
22
+[](<>)
collectors/slabinfo.plugin/slabinfo.c
new
+419
@@ -0,0 +1,419 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#include "libnetdata/libnetdata.h"
4
+#include "daemon/common.h"
5
+
6
+// For PAGE_SIZE
7
+#include <sys/user.h>
8
+
9
+#define PLUGIN_SLABINFO_NAME "slabinfo.plugin"
10
+#define PLUGIN_SLABINFO_PROCFILE "/proc/slabinfo"
11
+
12
+#define CHART_TYPE "mem"
13
+#define CHART_FAMILY "slab"
14
+#define CHART_PRIO 3000
15
+
16
+// As we're talking about kernel-pagesize, there's no hugepage.
17
+// So it's reliable to use it as an arch constant
18
+#define SLAB_PAGE_SIZE PAGE_SIZE
19
+
20
+// #define slabdebug(...) if (debug) { fprintf(stderr, __VA_ARGS__); }
21
+#define slabdebug(args...) if (debug) { \
22
+ fprintf(stderr, "slabinfo.plugin DEBUG (%04d@%-10.10s:%-15.15s)::", __LINE__, __FILE__, __FUNCTION__); \
23
+ fprintf(stderr, ##args); \
24
+ fprintf(stderr, "\n"); }
25
+
26
+
27
+// ----------------------------------------------------------------------------
28
+
29
+// callback required by fatal()
30
+void netdata_cleanup_and_exit(int ret) {
31
+ exit(ret);
32
+}
33
+
34
+void send_statistics(const char *action, const char *action_result, const char *action_data) {
35
+ (void) action;
36
+ (void) action_result;
37
+ (void) action_data;
38
+ return;
39
+}
40
+
41
+// callbacks required by popen()
42
+void signals_block(void) {};
43
+void signals_unblock(void) {};
44
+void signals_reset(void) {};
45
+
46
+// callback required by eval()
47
+int health_variable_lookup(const char *variable, uint32_t hash, struct rrdcalc *rc, calculated_number *result) {
48
+ (void)variable;
49
+ (void)hash;
50
+ (void)rc;
51
+ (void)result;
52
+ return 0;
53
+};
54
+
55
+// required by get_system_cpus()
56
+char *netdata_configured_host_prefix = "";
57
+
58
+
59
+int running = 1;
60
+int debug = 0;
61
+
62
+// ----------------------------------------------------------------------------
63
+
64
+// Slabinfo format :
65
+// format 2.1 Was provided by 57ed3eda977a215f054102b460ab0eb5d8d112e6 (2.6.24-rc6) as:
66
+// seq_puts(m, "# name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab>");
67
+// seq_puts(m, " : tunables <limit> <batchcount> <sharedfactor>");
68
+// seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>");
69
+//
70
+// With max values:
71
+// seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d",
72
+// cache_name(s), sinfo.active_objs, sinfo.num_objs, s->size, sinfo.objects_per_slab, (1 << sinfo.cache_order));
73
+// seq_printf(m, " : tunables %4u %4u %4u",
74
+// sinfo.limit, sinfo.batchcount, sinfo.shared);
75
+// seq_printf(m, " : slabdata %6lu %6lu %6lu",
76
+// sinfo.active_slabs, sinfo.num_slabs, sinfo.shared_avail);
77
+//
78
+// If CONFIG_DEBUG_SLAB is set, it will also add columns from slabinfo_show_stats (for SLAB only):
79
+// seq_printf(m, " : globalstat %7lu %6lu %5lu %4lu %4lu %4lu %4lu %4lu %4lu",
80
+// allocs, high, grown, reaped, errors, max_freeable, node_allocs, node_frees, overflows);
81
+// seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
82
+// allochit, allocmiss, freehit, freemiss);
83
+//
84
+// Implementation choices:
85
+// - Iterates through a linked list of kmem_cache.
86
+// - Name is a char* from struct kmem_cache (mm/slab.h).
87
+// - max name size found is 24:
88
+// grep -roP 'kmem_cache_create\(".+"'| awk '{split($0,a,"\""); print a[2],length(a[2]); }' | sort -k2 -n
89
+// - Using uint64 everywhere, as types fits and allows to use standard helpers
90
+
91
+struct slabinfo {
92
+ // procfile fields
93
+ const char *name;
94
+ uint64_t active_objs;
95
+ uint64_t num_objs;
96
+ uint64_t obj_size;
97
+ uint64_t obj_per_slab;
98
+ uint64_t pages_per_slab;
99
+ uint64_t tune_limit;
100
+ uint64_t tune_batchcnt;
101
+ uint64_t tune_shared_factor;
102
+ uint64_t data_active_slabs;
103
+ uint64_t data_num_slabs;
104
+ uint64_t data_shared_avail;
105
+
106
+ // Calculated fields
107
+ uint64_t mem_usage;
108
+ uint64_t mem_waste;
109
+ uint8_t obj_filling;
110
+
111
+ uint32_t hash;
112
+ struct slabinfo *next;
113
+} *slabinfo_root = NULL, *slabinfo_next = NULL, *slabinfo_last_used = NULL;
114
+
115
+// The code is very inspired from "proc_net_dev.c" and "perf_plugin.c"
116
+
117
+// Get the existing object, or create a new one
118
+static struct slabinfo *get_slabstruct(const char *name) {
119
+ struct slabinfo *s;
120
+
121
+ slabdebug("--> Requested slabstruct %s", name);
122
+
123
+ uint32_t hash = simple_hash(name);
124
+
125
+ // Search it, from the next to the end
126
+ for (s = slabinfo_next; s; s = s->next) {
127
+ if ((hash = s->hash) && !strcmp(name, s->name)) {
128
+ slabdebug("<-- Found existing slabstruct after %s", slabinfo_last_used->name);
129
+ // Prepare the next run
130
+ slabinfo_next = s->next;
131
+ slabinfo_last_used = s;
132
+ return s;
133
+ }
134
+ }
135
+
136
+ // Search it from the begining to the last position we used
137
+ for (s = slabinfo_root; s != slabinfo_last_used; s = s->next) {
138
+ if (hash == s->hash && !strcmp(name, s->name)) {
139
+ slabdebug("<-- Found existing slabstruct after root %s", slabinfo_root->name);
140
+ slabinfo_next = s->next;
141
+ slabinfo_last_used = s;
142
+ return s;
143
+ }
144
+ }
145
+
146
+ // Create a new one
147
+ s = callocz(1, sizeof(struct slabinfo));
148
+ s->name = strdupz(name);
149
+ s->hash = hash;
150
+
151
+ // Add it to the current postion
152
+ if (slabinfo_root) {
153
+ slabdebug("<-- Creating new slabstruct after %s", slabinfo_last_used->name);
154
+ s->next = slabinfo_last_used->next;
155
+ slabinfo_last_used->next = s;
156
+ slabinfo_last_used = s;
157
+ }
158
+ else {
159
+ slabdebug("<-- Creating new slabstruct as root");
160
+ slabinfo_root = slabinfo_last_used = s;
161
+ }
162
+
163
+ return s;
164
+}
165
+
166
+
167
+// Read a full pass of slabinfo to update the structs
168
+struct slabinfo *read_file_slabinfo() {
169
+
170
+ slabdebug("-> Reading procfile %s", PLUGIN_SLABINFO_PROCFILE);
171
+
172
+ static procfile *ff = NULL;
173
+
174
+ if(unlikely(!ff)) {
175
+ ff = procfile_reopen(ff, PLUGIN_SLABINFO_PROCFILE, " ,:" , PROCFILE_FLAG_DEFAULT);
176
+ if(unlikely(!ff)) {
177
+ error("<- Cannot open file '%s", PLUGIN_SLABINFO_PROCFILE);
178
+ exit(1);
179
+ }
180
+ }
181
+
182
+ ff = procfile_readall(ff);
183
+ if(unlikely(!ff)) {
184
+ error("<- Cannot read file '%s'", PLUGIN_SLABINFO_PROCFILE);
185
+ exit(0);
186
+ }
187
+
188
+
189
+ // Iterate on all lines to populate / update the slabinfo struct
190
+ size_t lines = procfile_lines(ff), l;
191
+
192
+ slabdebug(" Read %lu lines from procfile", (unsigned long)lines);
193
+ for(l = 2; l < lines; l++) {
194
+ if (unlikely(procfile_linewords(ff, l) < 14)) {
195
+ slabdebug(" Line %lu has only %lu words, skipping", (unsigned long)l, procfile_linewords(ff,l));
196
+ continue;
197
+ }
198
+
199
+ char *name = procfile_lineword(ff, l, 0);
200
+ struct slabinfo *s = get_slabstruct(name);
201
+
202
+ s->active_objs = str2uint64_t(procfile_lineword(ff, l, 1));
203
+ s->num_objs = str2uint64_t(procfile_lineword(ff, l, 2));
204
+ s->obj_size = str2uint64_t(procfile_lineword(ff, l, 3));
205
+ s->obj_per_slab = str2uint64_t(procfile_lineword(ff, l, 4));
206
+ s->pages_per_slab = str2uint64_t(procfile_lineword(ff, l, 5));
207
+
208
+ s->tune_limit = str2uint64_t(procfile_lineword(ff, l, 7));
209
+ s->tune_batchcnt = str2uint64_t(procfile_lineword(ff, l, 8));
210
+ s->tune_shared_factor = str2uint64_t(procfile_lineword(ff, l, 9));
211
+
212
+ s->data_active_slabs = str2uint64_t(procfile_lineword(ff, l, 11));
213
+ s->data_num_slabs = str2uint64_t(procfile_lineword(ff, l, 12));
214
+ s->data_shared_avail = str2uint64_t(procfile_lineword(ff, l, 13));
215
+
216
+ uint32_t memperslab = s->pages_per_slab * SLAB_PAGE_SIZE;
217
+ // Internal fragmentation: loss per slab, due to objects not being a multiple of pagesize
218
+ //uint32_t lossperslab = memperslab - s->obj_per_slab * s->obj_size;
219
+
220
+ // Total usage = slabs * pages per slab * page size
221
+ s->mem_usage = (uint64_t)(s->data_num_slabs * memperslab);
222
+
223
+ // Wasted memory (filling): slabs allocated but not filled: sum total slab - sum total objects
224
+ s->mem_waste = s->mem_usage - (uint64_t)(s->active_objs * s->obj_size);
225
+ //if (s->data_num_slabs > 1)
226
+ // s->mem_waste += s->data_num_slabs * lossperslab;
227
+
228
+
229
+ // Slab filling efficiency
230
+ if (s->num_objs > 0)
231
+ s->obj_filling = 100 * s->active_objs / s->num_objs;
232
+ else
233
+ s->obj_filling = 0;
234
+
235
+ slabdebug(" Updated slab %s: %lu %lu %lu %lu %lu / %lu %lu %lu / %lu %lu %lu / %lu %lu %hhu",
236
+ name, s->active_objs, s->num_objs, s->obj_size, s->obj_per_slab, s->pages_per_slab,
237
+ s->tune_limit, s->tune_batchcnt, s->tune_shared_factor,
238
+ s->data_active_slabs, s->data_num_slabs, s->data_shared_avail,
239
+ s->mem_usage, s->mem_waste, s->obj_filling);
240
+ }
241
+
242
+ return slabinfo_root;
243
+}
244
+
245
+
246
+
247
+unsigned int do_slab_stats(int update_every) {
248
+
249
+ static unsigned int loops = 0;
250
+ struct slabinfo *sactive = NULL, *s = NULL;
251
+
252
+ // Main processing loop
253
+ while (running) {
254
+
255
+ sactive = read_file_slabinfo();
256
+
257
+ // Init Charts
258
+ if (unlikely(loops == 0)) {
259
+ // Memory Usage
260
+ printf("CHART %s.%s '' 'Memory Usage' 'B' '%s' '' line %d %d %s\n"
261
+ , CHART_TYPE
262
+ , "slabmemory"
263
+ , CHART_FAMILY
264
+ , CHART_PRIO
265
+ , update_every
266
+ , PLUGIN_SLABINFO_NAME
267
+ );
268
+ for (s = sactive; s; s = s->next) {
269
+ printf("DIMENSION %s '' absolute 1 1\n", s->name);
270
+ }
271
+
272
+ // Slab active usage (filling)
273
+ printf("CHART %s.%s '' 'Object Filling' '%%' '%s' '' line %d %d %s\n"
274
+ , CHART_TYPE
275
+ , "slabfilling"
276
+ , CHART_FAMILY
277
+ , CHART_PRIO + 1
278
+ , update_every
279
+ , PLUGIN_SLABINFO_NAME
280
+ );
281
+ for (s = sactive; s; s = s->next) {
282
+ printf("DIMENSION %s '' absolute 1 1\n", s->name);
283
+ }
284
+
285
+ // Memory waste
286
+ printf("CHART %s.%s '' 'Memory waste' 'B' '%s' '' line %d %d %s\n"
287
+ , CHART_TYPE
288
+ , "slabwaste"
289
+ , CHART_FAMILY
290
+ , CHART_PRIO + 2
291
+ , update_every
292
+ , PLUGIN_SLABINFO_NAME
293
+ );
294
+ for (s = sactive; s; s = s->next) {
295
+ printf("DIMENSION %s '' absolute 1 1\n", s->name);
296
+ }
297
+ }
298
+
299
+
300
+ //
301
+ // Memory usage
302
+ //
303
+ printf("BEGIN %s.%s\n"
304
+ , CHART_TYPE
305
+ , "slabmemory"
306
+ );
307
+ for (s = sactive; s; s = s->next) {
308
+ printf("SET %s = %lu\n"
309
+ , s->name
310
+ , s->mem_usage
311
+ );
312
+ }
313
+ printf("END\n");
314
+
315
+ //
316
+ // Slab active usage
317
+ //
318
+ printf("BEGIN %s.%s\n"
319
+ , CHART_TYPE
320
+ , "slabfilling"
321
+ );
322
+ for (s = sactive; s; s = s->next) {
323
+ printf("SET %s = %u\n"
324
+ , s->name
325
+ , s->obj_filling
326
+ );
327
+ }
328
+ printf("END\n");
329
+
330
+ //
331
+ // Memory waste
332
+ //
333
+ printf("BEGIN %s.%s\n"
334
+ , CHART_TYPE
335
+ , "slabwaste"
336
+ );
337
+ for (s = sactive; s; s = s->next) {
338
+ printf("SET %s = %lu\n"
339
+ , s->name
340
+ , s->mem_waste
341
+ );
342
+ }
343
+ printf("END\n");
344
+
345
+
346
+ loops++;
347
+
348
+ sleep(update_every);
349
+ }
350
+
351
+ return loops;
352
+}
353
+
354
+
355
+
356
+
357
+// ----------------------------------------------------------------------------
358
+// main
359
+
360
+void usage(void) {
361
+ fprintf(stderr, "%s\n", program_name);
362
+ exit(1);
363
+}
364
+
365
+int main(int argc, char **argv) {
366
+
367
+ program_name = argv[0];
368
+ program_version = "0.1";
369
+ error_log_syslog = 0;
370
+
371
+ int update_every = 1, i, n, freq = 0;
372
+
373
+ for (i = 1; i < argc; i++) {
374
+ // Frequency parsing
375
+ if(isdigit(*argv[i]) && !freq) {
376
+ n = (int) str2l(argv[i]);
377
+ if (n > 0) {
378
+ if (n >= UPDATE_EVERY_MAX) {
379
+ error("Invalid interval value: %s", argv[i]);
380
+ exit(1);
381
+ }
382
+ freq = n;
383
+ }
384
+ }
385
+ else if (strcmp("debug", argv[i]) == 0) {
386
+ debug = 1;
387
+ continue;
388
+ }
389
+ else {
390
+ fprintf(stderr,
391
+ "netdata slabinfo.plugin %s\n"
392
+ "This program is a data collector plugin for netdata.\n"
393
+ "\n"
394
+ "Available command line options:\n"
395
+ "\n"
396
+ " COLLECTION_FREQUENCY data collection frequency in seconds\n"
397
+ " minimum: %d\n"
398
+ "\n"
399
+ " debug enable verbose output\n"
400
+ " default: disabled\n"
401
+ "\n",
402
+ program_version,
403
+ update_every
404
+ );
405
+ exit(1);
406
+ }
407
+ }
408
+
409
+ if(freq >= update_every)
410
+ update_every = freq;
411
+ else if(freq)
412
+ error("update frequency %d seconds is too small for slabinfo. Using %d.", freq, update_every);
413
+
414
+
415
+ // Call the main function. Time drift to be added
416
+ do_slab_stats(update_every);
417
+
418
+ return 0;
419
+}
configure.ac
+14
@@ -773,6 +773,19 @@ AC_MSG_RESULT([${enable_plugin_perf}])
773
AM_CONDITIONAL([ENABLE_PLUGIN_PERF], [test "${enable_plugin_perf}" = "yes"])
774
775
776
+# -----------------------------------------------------------------------------
777
+# slabinfo.plugin
778
+
779
+AC_MSG_CHECKING([if slabinfo.plugin should be enabled])
780
+if test "${build_target}" == "linux"; then
781
+ enable_plugin_slabinfo="yes"
782
+else
783
+ enable_plugin_slabinfo="no"
784
+fi
785
+AC_MSG_RESULT([${enable_plugin_slabinfo}])
786
+AM_CONDITIONAL([ENABLE_PLUGIN_SLABINFO], [test "${enable_plugin_slabinfo}" = "yes"])
787
+
788
+
789
# -----------------------------------------------------------------------------
790
# AWS Kinesis backend - libaws-cpp-sdk-kinesis, libaws-cpp-sdk-core, libssl, libcrypto, libcurl
791
@@ -1147,6 +1160,7 @@ AC_CONFIG_FILES([
1160
collectors/plugins.d/Makefile
1161
collectors/proc.plugin/Makefile
1162
collectors/python.d.plugin/Makefile
1163
+ collectors/slabinfo.plugin/Makefile
1164
collectors/statsd.plugin/Makefile
1165
collectors/tc.plugin/Makefile
1166
collectors/xenstat.plugin/Makefile
contrib/debian/rules
+1
@@ -107,6 +107,7 @@ override_dh_fixperms:
107
chmod 0754 $(TOP)/usr/libexec/netdata/plugins.d/apps.plugin
108
chmod 0754 $(TOP)/usr/libexec/netdata/plugins.d/freeipmi.plugin
109
chmod 0754 $(TOP)/usr/libexec/netdata/plugins.d/perf.plugin
110
+ chmod 0754 $(TOP)/usr/libexec/netdata/plugins.d/slabinfo.plugin
111
chmod 0750 $(TOP)/usr/libexec/netdata/plugins.d/go.d.plugin
112
113
# Support script for configuration file management
docs/Add-more-charts-to-netdata.md
+4
-1
@@ -70,6 +70,7 @@ To control which plugins Netdata run, edit `netdata.conf` and check the `[plugin
70
# apps = yes
71
# xenstat = yes
72
# perf = no
73
+ # slabinfo = no
74
```
75
76
The default for all plugins is the option `enable running new plugins`. So, setting this to `no` will disable all the plugins, except the ones specifically enabled.
@@ -96,7 +97,7 @@ sudo su -s /bin/bash netdata
97
```
98
99
Similarly, you can use `charts.d.plugin` for BASH plugins and `node.d.plugin` for node.js plugins.
99
-Other plugins (like `apps.plugin`, `freeipmi.plugin`, `fping.plugin`, `ioping.plugin`, `nfacct.plugin`, `xenstat.plugin`, `perf.plugin`) use the native Netdata plugin API and can be run directly.
100
+Other plugins (like `apps.plugin`, `freeipmi.plugin`, `fping.plugin`, `ioping.plugin`, `nfacct.plugin`, `xenstat.plugin`, `perf.plugin`, `slabinfo.plugin`) use the native Netdata plugin API and can be run directly.
101
102
If you need to configure a Netdata plugin or module, all user supplied configuration is kept at `/etc/netdata` while the stock versions of all files is at `/usr/lib/netdata/conf.d`.
103
To copy a stock file and edit it, run `/etc/netdata/edit-config`. Running this command without an argument, will list the available stock files.
@@ -126,6 +127,7 @@ This is a map of the all supported configuration options:
127
| `proc.plugin`<br/>(internal plugin for monitoring Linux system resources)|`C`|`netdata.conf` section `[plugin:proc]`|one section for each module `[plugin:proc:MODULE]`. Each module may provide additional sections in the form of `[plugin:proc:MODULE:SUBSECTION]`.|
128
| `python.d.plugin`<br/>(external plugin orchestrator for running python modules)|`python`<br/>v2 or v3<br/>both are supported|`python.d.conf`|a file for each module in `/etc/netdata/python.d/`.|
129
| `statsd.plugin`<br/>(internal plugin for collecting statsd metrics)|`C`|`netdata.conf` section `[statsd]`|Synthetic statsd charts can be configured with files in `/etc/netdata/statsd.d/`.|
130
+| `slabinfo.plugin`<br/>(external plugin for monitoring Kernel SLAB cache on Linux)|`C`|`netdata.conf` section `[plugin:slabinfo]`|N/A|
131
| `tc.plugin`<br/>(internal plugin for collecting Linux traffic QoS)|`C`|`netdata.conf` section `[plugin:tc]`|The plugin runs an external helper called `tc-qos-helper.sh` to interface with the `tc` command. This helper supports a few additional options using `tc-qos-helper.conf`.|
132
133
## writing data collection modules
@@ -316,6 +318,7 @@ These are all the data collection plugins currently available.
318
| cpu_apps|BASH<br/>Shell Script|Collects the CPU utilization of select apps.<br/><br/>DEPRECATED IN FAVOR OF `apps.plugin`. It is still supplied only as an example module to shell scripting plugins.<br/> <br/>Netdata plugin: [charts.d.plugin](../collectors/charts.d.plugin#chartsdplugin)<br/>plugin module: [cpu_apps.chart.sh](../collectors/charts.d.plugin/cpu_apps)<br/>configuration file: [charts.d/cpu_apps.conf](../collectors/charts.d.plugin/cpu_apps)|
319
| load_average|BASH<br/>Shell Script|Collects the current system load average.<br/><br/>DEPRECATED IN FAVOR OF THE NETDATA INTERNAL ONE. It is still supplied only as an example module to shell scripting plugins.<br/> <br/>Netdata plugin: [charts.d.plugin](../collectors/charts.d.plugin#chartsdplugin)<br/>plugin module: [load_average.chart.sh](../collectors/charts.d.plugin/load_average)<br/>configuration file: [charts.d/load_average.conf](../collectors/charts.d.plugin/load_average)|
320
| mem_apps|BASH<br/>Shell Script|Collects the memory footprint of select applications.<br/><br/>DEPRECATED IN FAVOR OF `apps.plugin`. It is still supplied only as an example module to shell scripting plugins.<br/> <br/>Netdata plugin: [charts.d.plugin](../collectors/charts.d.plugin#chartsdplugin)<br/>plugin module: [mem_apps.chart.sh](../collectors/charts.d.plugin/mem_apps)<br/>configuration file: [charts.d/mem_apps.conf](../collectors/charts.d.plugin/mem_apps)|
321
+| slabinfo|C|`slabinfo.plugin` collects Kernel SLAB cache metrics on Linux .<br/> <br/>[Documentation of `slabinfo.plugin`](../collectors/slabinfo.plugin/).<br/> <br/>Netdata plugin: [`slabinfo_plugin.c`](../collectors/slabinfo.plugin)|
322
323
---
324
docs/generator/buildyaml.sh
+2
-1
@@ -250,6 +250,7 @@ navpart 3 collectors/freeipmi.plugin
250
navpart 3 collectors/nfacct.plugin
251
navpart 3 collectors/xenstat.plugin
252
navpart 3 collectors/perf.plugin
253
+navpart 3 collectors/slabinfo.plugin
254
255
256
echo -ne " - 'docs/Third-Party-Plugins.md'
@@ -285,4 +286,4 @@ navpart 2 packaging/makeself "" "" 4
286
navpart 2 libnetdata "" "libnetdata" 4
287
navpart 2 contrib
288
navpart 2 tests "" "" 2
288
-navpart 2 diagrams/data_structures
\ No newline at end of file
289
+navpart 2 diagrams/data_structures
netdata-installer.sh
+5
@@ -752,6 +752,11 @@ if [ "${UID}" -eq 0 ]; then
752
run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
753
fi
754
755
+ if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin" ]; then
756
+ run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
757
+ run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
758
+ fi
759
+
760
if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
761
run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
762
run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
netdata.spec.in
+5
@@ -279,6 +279,9 @@ install -m 4750 -p perf.plugin "${RPM_BUILD_ROOT}%{_libexecdir}/%{name}/plugins.
279
# Install cups.plugin
280
install -m 0750 -p cups.plugin "${RPM_BUILD_ROOT}%{_libexecdir}/%{name}/plugins.d/cups.plugin"
281
282
+# ###########################################################
283
+# Install slabinfo.plugin
284
+install -m 4750 -p slabinfo.plugin "${RPM_BUILD_ROOT}%{_libexecdir}/%{name}/plugins.d/slabinfo.plugin"
285
286
# ###########################################################
287
# Install registry directory
@@ -451,6 +454,8 @@ rm -rf "${RPM_BUILD_ROOT}"
454
# perf plugin
455
%caps(cap_setuid=ep) %attr(4750,root,netdata) %{_libexecdir}/%{name}/plugins.d/perf.plugin
456
457
+# perf plugin
458
+%caps(cap_setuid=ep) %attr(4550,root,netdata) %{_libexecdir}/%{name}/plugins.d/slabinfo.plugin
459
460
# freeipmi files
461
%caps(cap_setuid=ep) %attr(4550,root,netdata) %{_libexecdir}/%{name}/plugins.d/freeipmi.plugin