cleanup removed disks
Costa Tsaousis (ktsaou) committed
Mar 5, 2017 at 22:36 UTC
d61aa7dabfdb6829c040c53f2c6e7284281b22d3
1 file changed
+46
-6
src/plugin_proc_diskspace.c
+46
-6
@@ -22,12 +22,13 @@ static inline void mountinfo_reload(int force) {
22
}
23
}
24
25
-// Data to be stored in DICTIONARY mount_points used by do_disk_space_stats().
25
+// Data to be stored in DICTIONARY dict_mountpoints used by do_disk_space_stats().
26
// This DICTIONARY is used to lookup the settings of the mount point on each iteration.
27
struct mount_point_metadata {
28
int do_space;
29
int do_inodes;
30
int shown_error;
31
+ int updated;
32
33
size_t collected; // the number of times this has been collected
34
@@ -42,16 +43,50 @@ struct mount_point_metadata {
43
RRDDIM *rd_inodes_reserved;
44
};
45
46
+static DICTIONARY *dict_mountpoints = NULL;
47
+
48
+#define rrdset_obsolete_and_pointer_null(st) do { if(st) { rrdset_flag_set(st, RRDSET_FLAG_OBSOLETE); st = NULL; } } while(st)
49
+
50
+int mount_point_cleanup(void *entry, void *data) {
51
+ (void)data;
52
+
53
+ struct mount_point_metadata *mp = (struct mount_point_metadata *)entry;
54
+ if(!mp) return 0;
55
+
56
+ if(likely(mp->updated)) {
57
+ mp->updated = 0;
58
+ return 0;
59
+ }
60
+
61
+ if(likely(mp->collected)) {
62
+ mp->collected = 0;
63
+ mp->updated = 0;
64
+ mp->shown_error = 0;
65
+
66
+ mp->rd_space_avail = NULL;
67
+ mp->rd_space_used = NULL;
68
+ mp->rd_space_reserved = NULL;
69
+
70
+ mp->rd_inodes_avail = NULL;
71
+ mp->rd_inodes_used = NULL;
72
+ mp->rd_inodes_reserved = NULL;
73
+
74
+ rrdset_obsolete_and_pointer_null(mp->st_space);
75
+ rrdset_obsolete_and_pointer_null(mp->st_inodes);
76
+ }
77
+
78
+ return 0;
79
+}
80
+
81
static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
82
const char *family = mi->mount_point;
83
const char *disk = mi->persistent_id;
84
49
- static DICTIONARY *mount_points = NULL;
85
static SIMPLE_PATTERN *excluded_mountpoints = NULL;
86
static SIMPLE_PATTERN *excluded_filesystems = NULL;
87
int do_space, do_inodes;
88
54
- if(unlikely(!mount_points)) {
89
+ if(unlikely(!dict_mountpoints)) {
90
SIMPLE_PREFIX_MODE mode = SIMPLE_PATTERN_EXACT;
91
92
if(config_move("plugin:proc:/proc/diskstats", "exclude space metrics on paths", CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths") != -1) {
@@ -69,10 +104,10 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
104
SIMPLE_PATTERN_EXACT
105
);
106
72
- mount_points = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
107
+ dict_mountpoints = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
108
}
109
75
- struct mount_point_metadata *m = dictionary_get(mount_points, mi->mount_point);
110
+ struct mount_point_metadata *m = dictionary_get(dict_mountpoints, mi->mount_point);
111
if(unlikely(!m)) {
112
char var_name[4096 + 1];
113
snprintfz(var_name, 4096, "plugin:proc:diskspace:%s", mi->mount_point);
@@ -97,6 +132,7 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
132
.do_space = do_space,
133
.do_inodes = do_inodes,
134
.shown_error = 0,
135
+ .updated = 0,
136
137
.collected = 0,
138
@@ -111,9 +147,11 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
147
.rd_inodes_reserved = NULL
148
};
149
114
- m = dictionary_set(mount_points, mi->mount_point, &mp, sizeof(struct mount_point_metadata));
150
+ m = dictionary_set(dict_mountpoints, mi->mount_point, &mp, sizeof(struct mount_point_metadata));
151
}
152
153
+ m->updated = 1;
154
+
155
if(unlikely(m->do_space == CONFIG_BOOLEAN_NO && m->do_inodes == CONFIG_BOOLEAN_NO))
156
return;
157
@@ -305,6 +343,8 @@ void *proc_diskspace_main(void *ptr) {
343
344
if(unlikely(netdata_exit)) break;
345
346
+ dictionary_get_all(dict_mountpoints, mount_point_cleanup, NULL);
347
+
348
if(vdo_cpu_netdata) {
349
static RRDSET *stcpu_thread = NULL, *st_duration = NULL;
350
static RRDDIM *rd_user = NULL, *rd_system = NULL, *rd_duration = NULL;