@cryptotaxi247 / netdata-1 / commits / b792a9acc

remove proc zfspools (#18389)

Ilya Mashchenko committed Aug 21, 2024 at 20:53 UTC b792a9accaf5f363d20753e9855730f7979ae538
4 files changed -321
src/collectors/proc.plugin/metadata.yaml
-92
@@ -4495,98 +4495,6 @@ modules:
4495 - name: valid
4496 - name: invalid
4497 - name: retransmits
4498 - - meta:
4499 - plugin_name: proc.plugin
4500 - module_name: /proc/spl/kstat/zfs
4501 - monitored_instance:
4502 - name: ZFS Pools
4503 - link: ""
4504 - categories:
4505 - - data-collection.linux-systems.filesystem-metrics.zfs
4506 - icon_filename: "filesystem.svg"
4507 - related_resources:
4508 - integrations:
4509 - list: []
4510 - info_provided_to_referring_integrations:
4511 - description: ""
4512 - keywords:
4513 - - zfs pools
4514 - - pools
4515 - - zfs
4516 - - filesystem
4517 - most_popular: false
4518 - overview:
4519 - data_collection:
4520 - metrics_description: "This integration provides metrics about the state of ZFS pools."
4521 - method_description: ""
4522 - supported_platforms:
4523 - include: []
4524 - exclude: []
4525 - multi_instance: true
4526 - additional_permissions:
4527 - description: ""
4528 - default_behavior:
4529 - auto_detection:
4530 - description: ""
4531 - limits:
4532 - description: ""
4533 - performance_impact:
4534 - description: ""
4535 - setup:
4536 - prerequisites:
4537 - list: []
4538 - configuration:
4539 - file:
4540 - name: ""
4541 - description: ""
4542 - options:
4543 - description: ""
4544 - folding:
4545 - title: ""
4546 - enabled: true
4547 - list: []
4548 - examples:
4549 - folding:
4550 - enabled: true
4551 - title: ""
4552 - list: []
4553 - troubleshooting:
4554 - problems:
4555 - list: []
4556 - alerts:
4557 - - name: zfs_pool_state_warn
4558 - link: https://github.com/netdata/netdata/blob/master/src/health/health.d/zfs.conf
4559 - metric: zfspool.state
4560 - info: ZFS pool ${label:pool} state is degraded
4561 - - name: zfs_pool_state_crit
4562 - link: https://github.com/netdata/netdata/blob/master/src/health/health.d/zfs.conf
4563 - metric: zfspool.state
4564 - info: ZFS pool ${label:pool} state is faulted or unavail
4565 - metrics:
4566 - folding:
4567 - title: Metrics
4568 - enabled: false
4569 - description: ""
4570 - availability: []
4571 - scopes:
4572 - - name: zfs pool
4573 - description: ""
4574 - labels:
4575 - - name: pool
4576 - description: TBD
4577 - metrics:
4578 - - name: zfspool.state
4579 - description: ZFS pool state
4580 - unit: "boolean"
4581 - chart_type: line
4582 - dimensions:
4583 - - name: online
4584 - - name: degraded
4585 - - name: faulted
4586 - - name: offline
4587 - - name: removed
4588 - - name: unavail
4589 - - name: suspended
4498 - meta:
4499 plugin_name: proc.plugin
4500 module_name: /proc/spl/kstat/zfs/arcstats
src/collectors/proc.plugin/plugin_proc.c
-1
@@ -62,7 +62,6 @@ static struct proc_module {
62
63 // ZFS metrics
64 {.name = "/proc/spl/kstat/zfs/arcstats", .dim = "zfs_arcstats", .func = do_proc_spl_kstat_zfs_arcstats},
65 - {.name = "/proc/spl/kstat/zfs/pool/state",.dim = "zfs_pool_state",.func = do_proc_spl_kstat_zfs_pool_state},
65
66 // BTRFS metrics
67 {.name = "/sys/fs/btrfs", .dim = "btrfs", .func = do_sys_fs_btrfs},
src/collectors/proc.plugin/plugin_proc.h
-1
@@ -37,7 +37,6 @@ int do_proc_sys_devices_system_edac_mc(int update_every, usec_t dt);
37 int do_proc_sys_devices_pci_aer(int update_every, usec_t dt);
38 int do_proc_sys_devices_system_node(int update_every, usec_t dt);
39 int do_proc_spl_kstat_zfs_arcstats(int update_every, usec_t dt);
40 -int do_proc_spl_kstat_zfs_pool_state(int update_every, usec_t dt);
40 int do_sys_fs_btrfs(int update_every, usec_t dt);
41 int do_proc_net_sockstat(int update_every, usec_t dt);
42 int do_proc_net_sockstat6(int update_every, usec_t dt);
src/collectors/proc.plugin/proc_spl_kstat_zfs.c
-227
@@ -200,230 +200,3 @@ int do_proc_spl_kstat_zfs_arcstats(int update_every, usec_t dt) {
200
201 return 0;
202 }
203 -
204 -struct zfs_pool {
205 - RRDSET *st;
206 -
207 - RRDDIM *rd_online;
208 - RRDDIM *rd_degraded;
209 - RRDDIM *rd_faulted;
210 - RRDDIM *rd_offline;
211 - RRDDIM *rd_removed;
212 - RRDDIM *rd_unavail;
213 - RRDDIM *rd_suspended;
214 -
215 - int updated;
216 - int disabled;
217 -
218 - int online;
219 - int degraded;
220 - int faulted;
221 - int offline;
222 - int removed;
223 - int unavail;
224 - int suspended;
225 -};
226 -
227 -struct deleted_zfs_pool {
228 - char *name;
229 - struct deleted_zfs_pool *next;
230 -} *deleted_zfs_pools = NULL;
231 -
232 -DICTIONARY *zfs_pools = NULL;
233 -
234 -void disable_zfs_pool_state(struct zfs_pool *pool)
235 -{
236 - if (pool->st)
237 - rrdset_is_obsolete___safe_from_collector_thread(pool->st);
238 -
239 - pool->st = NULL;
240 -
241 - pool->rd_online = NULL;
242 - pool->rd_degraded = NULL;
243 - pool->rd_faulted = NULL;
244 - pool->rd_offline = NULL;
245 - pool->rd_removed = NULL;
246 - pool->rd_unavail = NULL;
247 - pool->rd_suspended = NULL;
248 -
249 - pool->disabled = 1;
250 -}
251 -
252 -int update_zfs_pool_state_chart(const DICTIONARY_ITEM *item, void *pool_p, void *update_every_p) {
253 - const char *name = dictionary_acquired_item_name(item);
254 - struct zfs_pool *pool = (struct zfs_pool *)pool_p;
255 - int update_every = *(int *)update_every_p;
256 -
257 - if (pool->updated) {
258 - pool->updated = 0;
259 -
260 - if (!pool->disabled) {
261 - if (unlikely(!pool->st)) {
262 - char chart_id[MAX_CHART_ID + 1];
263 - snprintf(chart_id, MAX_CHART_ID, "state_%s", name);
264 -
265 - pool->st = rrdset_create_localhost(
266 - "zfspool",
267 - chart_id,
268 - NULL,
269 - "state",
270 - "zfspool.state",
271 - "ZFS pool state",
272 - "boolean",
273 - PLUGIN_PROC_NAME,
274 - ZFS_PROC_POOLS,
275 - NETDATA_CHART_PRIO_ZFS_POOL_STATE,
276 - update_every,
277 - RRDSET_TYPE_LINE);
278 -
279 - pool->rd_online = rrddim_add(pool->st, "online", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
280 - pool->rd_degraded = rrddim_add(pool->st, "degraded", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
281 - pool->rd_faulted = rrddim_add(pool->st, "faulted", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
282 - pool->rd_offline = rrddim_add(pool->st, "offline", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
283 - pool->rd_removed = rrddim_add(pool->st, "removed", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
284 - pool->rd_unavail = rrddim_add(pool->st, "unavail", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
285 - pool->rd_suspended = rrddim_add(pool->st, "suspended", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
286 -
287 - rrdlabels_add(pool->st->rrdlabels, "pool", name, RRDLABEL_SRC_AUTO);
288 - }
289 -
290 - rrddim_set_by_pointer(pool->st, pool->rd_online, pool->online);
291 - rrddim_set_by_pointer(pool->st, pool->rd_degraded, pool->degraded);
292 - rrddim_set_by_pointer(pool->st, pool->rd_faulted, pool->faulted);
293 - rrddim_set_by_pointer(pool->st, pool->rd_offline, pool->offline);
294 - rrddim_set_by_pointer(pool->st, pool->rd_removed, pool->removed);
295 - rrddim_set_by_pointer(pool->st, pool->rd_unavail, pool->unavail);
296 - rrddim_set_by_pointer(pool->st, pool->rd_suspended, pool->suspended);
297 - rrdset_done(pool->st);
298 - }
299 - } else {
300 - disable_zfs_pool_state(pool);
301 - struct deleted_zfs_pool *new = callocz(1, sizeof(struct deleted_zfs_pool));
302 - new->name = strdupz(name);
303 - new->next = deleted_zfs_pools;
304 - deleted_zfs_pools = new;
305 - }
306 -
307 - return 0;
308 -}
309 -
310 -int do_proc_spl_kstat_zfs_pool_state(int update_every, usec_t dt)
311 -{
312 - (void)dt;
313 -
314 - static int do_zfs_pool_state = -1;
315 - static char *dirname = NULL;
316 -
317 - int pool_found = 0, state_file_found = 0;
318 -
319 - if (unlikely(do_zfs_pool_state == -1)) {
320 - char filename[FILENAME_MAX + 1];
321 - snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/spl/kstat/zfs");
322 - dirname = config_get("plugin:proc:" ZFS_PROC_POOLS, "directory to monitor", filename);
323 -
324 - zfs_pools = dictionary_create_advanced(DICT_OPTION_SINGLE_THREADED, &dictionary_stats_category_collectors, 0);
325 -
326 - do_zfs_pool_state = 1;
327 - }
328 -
329 - if (likely(do_zfs_pool_state)) {
330 - DIR *dir = opendir(dirname);
331 - if (unlikely(!dir)) {
332 - if (errno == ENOENT)
333 - collector_info("Cannot read directory '%s'", dirname);
334 - else
335 - collector_error("Cannot read directory '%s'", dirname);
336 - return 1;
337 - }
338 -
339 - struct dirent *de = NULL;
340 - while (likely(de = readdir(dir))) {
341 - if (likely(
342 - de->d_type == DT_DIR && ((de->d_name[0] == '.' && de->d_name[1] == '\0') ||
343 - (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0'))))
344 - continue;
345 -
346 - if (unlikely(de->d_type == DT_LNK || de->d_type == DT_DIR)) {
347 - pool_found = 1;
348 -
349 - struct zfs_pool *pool = dictionary_get(zfs_pools, de->d_name);
350 -
351 - if (unlikely(!pool)) {
352 - struct zfs_pool new_zfs_pool = {};
353 - pool = dictionary_set(zfs_pools, de->d_name, &new_zfs_pool, sizeof(struct zfs_pool));
354 - }
355 -
356 - pool->updated = 1;
357 -
358 - if (pool->disabled) {
359 - state_file_found = 1;
360 - continue;
361 - }
362 -
363 - pool->online = 0;
364 - pool->degraded = 0;
365 - pool->faulted = 0;
366 - pool->offline = 0;
367 - pool->removed = 0;
368 - pool->unavail = 0;
369 - pool->suspended = 0;
370 -
371 - char filename[FILENAME_MAX + 1];
372 - snprintfz(filename, FILENAME_MAX, "%s/%s/state", dirname, de->d_name);
373 -
374 - char state[STATE_SIZE + 1];
375 - int ret = read_txt_file(filename, state, sizeof(state));
376 -
377 - if (!ret) {
378 - state_file_found = 1;
379 -
380 - // ZFS pool states are described at https://openzfs.github.io/openzfs-docs/man/8/zpoolconcepts.8.html?#Device_Failure_and_Recovery
381 - if (!strcmp(state, "ONLINE\n")) {
382 - pool->online = 1;
383 - } else if (!strcmp(state, "DEGRADED\n")) {
384 - pool->degraded = 1;
385 - } else if (!strcmp(state, "FAULTED\n")) {
386 - pool->faulted = 1;
387 - } else if (!strcmp(state, "OFFLINE\n")) {
388 - pool->offline = 1;
389 - } else if (!strcmp(state, "REMOVED\n")) {
390 - pool->removed = 1;
391 - } else if (!strcmp(state, "UNAVAIL\n")) {
392 - pool->unavail = 1;
393 - } else if (!strcmp(state, "SUSPENDED\n")) {
394 - pool->suspended = 1;
395 - } else {
396 - disable_zfs_pool_state(pool);
397 -
398 - char *c = strchr(state, '\n');
399 - if (c)
400 - *c = '\0';
401 - collector_error("ZFS POOLS: Undefined state %s for zpool %s, disabling the chart", state, de->d_name);
402 - }
403 - }
404 - }
405 - }
406 -
407 - closedir(dir);
408 - }
409 -
410 - if (do_zfs_pool_state && pool_found && !state_file_found) {
411 - collector_info("ZFS POOLS: State files not found. Disabling the module.");
412 - do_zfs_pool_state = 0;
413 - }
414 -
415 - if (do_zfs_pool_state)
416 - dictionary_walkthrough_read(zfs_pools, update_zfs_pool_state_chart, &update_every);
417 -
418 - while (deleted_zfs_pools) {
419 - struct deleted_zfs_pool *current_pool = deleted_zfs_pools;
420 - dictionary_del(zfs_pools, current_pool->name);
421 -
422 - deleted_zfs_pools = deleted_zfs_pools->next;
423 -
424 - freez(current_pool->name);
425 - freez(current_pool);
426 - }
427 -
428 - return 0;
429 -}