btrfs physical disk size; #3095
Costa Tsaousis (ktsaou) committed
Dec 18, 2017 at 21:48 UTC
9b2288e2a7bae2b15eec9be1d9e1d2480b700502
1 file changed
+291
-128
src/sys_fs_btrfs.c
+291
-128
@@ -1,15 +1,26 @@
1
#include "common.h"
2
3
-#define BTRFS_MAX_ID_LENGTH 50
4
-#define BTRFS_MAX_LABEL_LENGTH 200
3
+typedef struct btrfs_disk {
4
+ char *name;
5
+ uint32_t hash;
6
+ int exists;
7
+
8
+ char *size_filename;
9
+ char *hw_sector_size_filename;
10
+ unsigned long long size;
11
+ unsigned long long hw_sector_size;
12
+
13
+ struct btrfs_disk *next;
14
+} BTRFS_DISK;
15
16
typedef struct btrfs_node {
17
int exists;
18
+ int logged_error;
19
9
- char id[BTRFS_MAX_ID_LENGTH + 1];
20
+ char *id;
21
uint32_t hash;
22
12
- char label[BTRFS_MAX_LABEL_LENGTH + 1];
23
+ char *label;
24
25
// unsigned long long int sectorsize;
26
// unsigned long long int nodesize;
@@ -17,46 +28,64 @@ typedef struct btrfs_node {
28
29
#define declare_btrfs_allocation_section_field(SECTION, FIELD) \
30
char *allocation_ ## SECTION ## _ ## FIELD ## _filename; \
20
- unsigned long long int allocation_ ## SECTION ## _ ## FIELD; \
21
- RRDDIM *rd_allocation_ ## SECTION ## _ ## FIELD;
31
+ unsigned long long int allocation_ ## SECTION ## _ ## FIELD;
32
33
#define declare_btrfs_allocation_field(FIELD) \
34
char *allocation_ ## FIELD ## _filename; \
25
- unsigned long long int allocation_ ## FIELD; \
26
- RRDDIM *rd_allocation_ ## FIELD;
35
+ unsigned long long int allocation_ ## FIELD;
36
28
- RRDSET *st_allocation_system;
29
- declare_btrfs_allocation_section_field(system, total_bytes)
30
- declare_btrfs_allocation_section_field(system, bytes_used)
31
- declare_btrfs_allocation_section_field(system, disk_total)
32
- declare_btrfs_allocation_section_field(system, disk_used)
37
+ RRDSET *st_allocation_disks;
38
+ RRDDIM *rd_allocation_disks_used;
39
+ RRDDIM *rd_allocation_disks_unallocated;
40
+ RRDDIM *rd_allocation_disks_free;
41
+ unsigned long long all_disks_total;
42
43
RRDSET *st_allocation_data;
44
+ RRDDIM *rd_allocation_data_free;
45
+ RRDDIM *rd_allocation_data_used;
46
declare_btrfs_allocation_section_field(data, total_bytes)
47
declare_btrfs_allocation_section_field(data, bytes_used)
48
declare_btrfs_allocation_section_field(data, disk_total)
49
declare_btrfs_allocation_section_field(data, disk_used)
50
51
RRDSET *st_allocation_metadata;
52
+ RRDDIM *rd_allocation_metadata_free;
53
+ RRDDIM *rd_allocation_metadata_used;
54
+ RRDDIM *rd_allocation_metadata_reserved;
55
declare_btrfs_allocation_section_field(metadata, total_bytes)
56
declare_btrfs_allocation_section_field(metadata, bytes_used)
57
declare_btrfs_allocation_section_field(metadata, disk_total)
58
declare_btrfs_allocation_section_field(metadata, disk_used)
45
-
46
- RRDSET *st_allocation_global_rsv;
47
- declare_btrfs_allocation_field(global_rsv_reserved)
59
+ //declare_btrfs_allocation_field(global_rsv_reserved)
60
declare_btrfs_allocation_field(global_rsv_size)
61
62
+ RRDSET *st_allocation_system;
63
+ RRDDIM *rd_allocation_system_free;
64
+ RRDDIM *rd_allocation_system_used;
65
+ declare_btrfs_allocation_section_field(system, total_bytes)
66
+ declare_btrfs_allocation_section_field(system, bytes_used)
67
+ declare_btrfs_allocation_section_field(system, disk_total)
68
+ declare_btrfs_allocation_section_field(system, disk_used)
69
+
70
+ BTRFS_DISK *disks;
71
+
72
struct btrfs_node *next;
73
} BTRFS_NODE;
74
75
static BTRFS_NODE *nodes = NULL;
76
77
+static inline void btrfs_free_disk(BTRFS_DISK *d) {
78
+ freez(d->name);
79
+ freez(d->size_filename);
80
+ freez(d->hw_sector_size_filename);
81
+ freez(d);
82
+}
83
+
84
static inline void btrfs_free_node(BTRFS_NODE *node) {
85
// info("BTRFS: destroying '%s'", node->id);
86
58
- if(node->st_allocation_system)
59
- rrdset_is_obsolete(node->st_allocation_system);
87
+ if(node->st_allocation_disks)
88
+ rrdset_is_obsolete(node->st_allocation_disks);
89
90
if(node->st_allocation_data)
91
rrdset_is_obsolete(node->st_allocation_data);
@@ -64,11 +93,8 @@ static inline void btrfs_free_node(BTRFS_NODE *node) {
93
if(node->st_allocation_metadata)
94
rrdset_is_obsolete(node->st_allocation_metadata);
95
67
- if(node->st_allocation_global_rsv)
68
- rrdset_is_obsolete(node->st_allocation_global_rsv);
69
-
70
- freez(node->allocation_system_bytes_used_filename);
71
- freez(node->allocation_system_total_bytes_filename);
96
+ if(node->st_allocation_system)
97
+ rrdset_is_obsolete(node->st_allocation_system);
98
99
freez(node->allocation_data_bytes_used_filename);
100
freez(node->allocation_data_total_bytes_filename);
@@ -76,9 +102,131 @@ static inline void btrfs_free_node(BTRFS_NODE *node) {
102
freez(node->allocation_metadata_bytes_used_filename);
103
freez(node->allocation_metadata_total_bytes_filename);
104
105
+ freez(node->allocation_system_bytes_used_filename);
106
+ freez(node->allocation_system_total_bytes_filename);
107
+
108
+ while(node->disks) {
109
+ BTRFS_DISK *d = node->disks;
110
+ node->disks = node->disks->next;
111
+ btrfs_free_disk(d);
112
+ }
113
+
114
+ freez(node->label);
115
+ freez(node->id);
116
freez(node);
117
}
118
119
+static inline int find_btrfs_disks(BTRFS_NODE *node, const char *path) {
120
+ char filename[FILENAME_MAX + 1];
121
+
122
+ node->all_disks_total = 0;
123
+
124
+ BTRFS_DISK *d;
125
+ for(d = node->disks ; d ; d = d->next)
126
+ d->exists = 0;
127
+
128
+ DIR *dir = opendir(path);
129
+ if (!dir) {
130
+ if(!node->logged_error) {
131
+ error("BTRFS: Cannot open directory '%s'.", path);
132
+ node->logged_error = 1;
133
+ }
134
+ return 1;
135
+ }
136
+ node->logged_error = 0;
137
+
138
+ struct dirent *de = NULL;
139
+ while ((de = readdir(dir))) {
140
+ if (de->d_type != DT_LNK
141
+ || !strcmp(de->d_name, ".")
142
+ || !strcmp(de->d_name, "..")
143
+ ) {
144
+ // info("BTRFS: ignoring '%s'", de->d_name);
145
+ continue;
146
+ }
147
+
148
+ uint32_t hash = simple_hash(de->d_name);
149
+
150
+ // --------------------------------------------------------------------
151
+ // search for it
152
+
153
+ for(d = node->disks ; d ; d = d->next) {
154
+ if(hash == d->hash && !strcmp(de->d_name, d->name))
155
+ break;
156
+ }
157
+
158
+ // --------------------------------------------------------------------
159
+ // did we find it?
160
+
161
+ if(!d) {
162
+ d = callocz(sizeof(BTRFS_DISK), 1);
163
+
164
+ d->name = strdupz(de->d_name);
165
+ d->hash = simple_hash(d->name);
166
+
167
+ snprintfz(filename, FILENAME_MAX, "%s/%s/size", path, de->d_name);
168
+ d->size_filename = strdupz(filename);
169
+
170
+ snprintfz(filename, FILENAME_MAX, "%s/%s/queue/hw_sector_size", path, de->d_name);
171
+ d->hw_sector_size_filename = strdupz(filename);
172
+
173
+ // link it
174
+ d->next = node->disks;
175
+ node->disks = d;
176
+ }
177
+
178
+ d->exists = 1;
179
+
180
+
181
+ // --------------------------------------------------------------------
182
+ // update the values
183
+
184
+ if(read_single_number_file(d->size_filename, &d->size) != 0) {
185
+ error("BTRFS: failed to read '%s'", d->size_filename);
186
+ d->exists = 0;
187
+ continue;
188
+ }
189
+
190
+ if(read_single_number_file(d->hw_sector_size_filename, &d->hw_sector_size) != 0) {
191
+ error("BTRFS: failed to read '%s'", d->hw_sector_size_filename);
192
+ d->exists = 0;
193
+ continue;
194
+ }
195
+
196
+ node->all_disks_total += d->size * d->hw_sector_size;
197
+ }
198
+
199
+ // ------------------------------------------------------------------------
200
+ // cleanup
201
+
202
+ BTRFS_DISK *last = NULL;
203
+ d = node->disks;
204
+
205
+ while(d) {
206
+ if(unlikely(!d->exists)) {
207
+ if(unlikely(node->disks == d)) {
208
+ node->disks = d->next;
209
+ btrfs_free_disk(d);
210
+ d = node->disks;
211
+ last = NULL;
212
+ }
213
+ else {
214
+ last->next = d->next;
215
+ btrfs_free_disk(d);
216
+ d = last->next;
217
+ }
218
+
219
+ continue;
220
+ }
221
+
222
+ last = d;
223
+ d = d->next;
224
+ }
225
+
226
+ return 0;
227
+}
228
+
229
+
230
static inline int find_all_btrfs_pools(const char *path) {
231
static int logged_error = 0;
232
char filename[FILENAME_MAX + 1];
@@ -120,7 +268,12 @@ static inline int find_all_btrfs_pools(const char *path) {
268
if(node) {
269
// info("BTRFS: already exists '%s'", de->d_name);
270
node->exists = 1;
123
- break;
271
+
272
+ // update the disk sizes
273
+ snprintfz(filename, FILENAME_MAX, "%s/%s/devices", path, de->d_name);
274
+ find_btrfs_disks(node, filename);
275
+
276
+ continue;
277
}
278
279
// info("BTRFS: adding '%s'", de->d_name);
@@ -128,18 +281,20 @@ static inline int find_all_btrfs_pools(const char *path) {
281
// not found, create it
282
node = callocz(sizeof(BTRFS_NODE), 1);
283
131
- strncpyz(node->id, de->d_name, BTRFS_MAX_ID_LENGTH);
284
+ node->id = strdupz(de->d_name);
285
node->hash = simple_hash(node->id);
286
node->exists = 1;
287
135
- snprintfz(filename, FILENAME_MAX, "%s/%s/label", path, de->d_name);
136
- if(read_file(filename, node->label, sizeof(node->label)) != 0) {
137
- error("BTRFS: failed to read '%s'", filename);
138
- btrfs_free_node(node);
139
- continue;
288
+ {
289
+ char label[FILENAME_MAX + 1] = "";
290
+
291
+ snprintfz(filename, FILENAME_MAX, "%s/%s/label", path, de->d_name);
292
+ read_file(filename, label, FILENAME_MAX);
293
+ if (label[0])
294
+ node->label = strdupz(label);
295
+ else
296
+ node->label = strdupz(node->id);
297
}
141
- if(!node->label[0])
142
- strncpyz(node->label, node->id, BTRFS_MAX_LABEL_LENGTH);
298
299
//snprintfz(filename, FILENAME_MAX, "%s/%s/sectorsize", path, de->d_name);
300
//if(read_single_number_file(filename, &node->sectorsize) != 0) {
@@ -195,6 +350,7 @@ static inline int find_all_btrfs_pools(const char *path) {
350
init_btrfs_allocation_section_field(data, disk_total);
351
init_btrfs_allocation_section_field(data, disk_used);
352
353
+
354
// --------------------------------------------------------------------
355
// allocation/metadata
356
@@ -203,6 +359,9 @@ static inline int find_all_btrfs_pools(const char *path) {
359
init_btrfs_allocation_section_field(metadata, disk_total);
360
init_btrfs_allocation_section_field(metadata, disk_used);
361
362
+ init_btrfs_allocation_field(global_rsv_size);
363
+ // init_btrfs_allocation_field(global_rsv_reserved);
364
+
365
366
// --------------------------------------------------------------------
367
// allocation/system
@@ -214,10 +373,11 @@ static inline int find_all_btrfs_pools(const char *path) {
373
374
375
// --------------------------------------------------------------------
217
- // allocation/global_rsv
376
+ // find all disks related to this node
377
+ // and collect their sizes
378
219
- init_btrfs_allocation_field(global_rsv_size);
220
- init_btrfs_allocation_field(global_rsv_reserved);
379
+ snprintfz(filename, FILENAME_MAX, "%s/%s/devices", path, de->d_name);
380
+ find_btrfs_disks(node, filename);
381
382
383
// --------------------------------------------------------------------
@@ -261,7 +421,12 @@ static inline int find_all_btrfs_pools(const char *path) {
421
}
422
423
int do_sys_fs_btrfs(int update_every, usec_t dt) {
264
- static int initialized = 0, do_allocation_system = 1, do_allocation_data = 1, do_allocation_metadata = 1, do_allocation_global_rsv = 1;
424
+ static int initialized = 0
425
+ , do_allocation_disks = CONFIG_BOOLEAN_AUTO
426
+ , do_allocation_system = CONFIG_BOOLEAN_AUTO
427
+ , do_allocation_data = CONFIG_BOOLEAN_AUTO
428
+ , do_allocation_metadata = CONFIG_BOOLEAN_AUTO;
429
+
430
static usec_t refresh_delta = 0, refresh_every = 60 * USEC_PER_SEC;
431
static char *btrfs_path = NULL;
432
@@ -277,10 +442,10 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
442
refresh_every = config_get_number("plugin:proc:/sys/fs/btrfs", "check for btrfs changes every", refresh_every / USEC_PER_SEC) * USEC_PER_SEC;
443
refresh_delta = refresh_every;
444
280
- do_allocation_data = config_get_boolean_ondemand("plugin:proc:/sys/fs/btrfs", "data allocation", CONFIG_BOOLEAN_AUTO);
281
- do_allocation_metadata = config_get_boolean_ondemand("plugin:proc:/sys/fs/btrfs", "metadata allocation", CONFIG_BOOLEAN_AUTO);
282
- do_allocation_system = config_get_boolean_ondemand("plugin:proc:/sys/fs/btrfs", "system allocation", CONFIG_BOOLEAN_AUTO);
283
- do_allocation_global_rsv = config_get_boolean_ondemand("plugin:proc:/sys/fs/btrfs", "global reserve", CONFIG_BOOLEAN_AUTO);
445
+ do_allocation_disks = config_get_boolean_ondemand("plugin:proc:/sys/fs/btrfs", "physical disks allocation", do_allocation_disks);
446
+ do_allocation_data = config_get_boolean_ondemand("plugin:proc:/sys/fs/btrfs", "data allocation", do_allocation_data);
447
+ do_allocation_metadata = config_get_boolean_ondemand("plugin:proc:/sys/fs/btrfs", "metadata allocation", do_allocation_metadata);
448
+ do_allocation_system = config_get_boolean_ondemand("plugin:proc:/sys/fs/btrfs", "system allocation", do_allocation_system);
449
}
450
451
refresh_delta += dt;
@@ -300,11 +465,23 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
465
#define collect_btrfs_allocation_section_field(SECTION, FIELD) \
466
read_single_number_file(node->allocation_ ## SECTION ## _ ## FIELD ## _filename, &node->allocation_ ## SECTION ## _ ## FIELD)
467
468
+ if(do_allocation_disks != CONFIG_BOOLEAN_NO) {
469
+ if( collect_btrfs_allocation_section_field(data, disk_total) != 0
470
+ || collect_btrfs_allocation_section_field(data, disk_used) != 0
471
+ || collect_btrfs_allocation_section_field(metadata, disk_total) != 0
472
+ || collect_btrfs_allocation_section_field(metadata, disk_used) != 0
473
+ || collect_btrfs_allocation_section_field(system, disk_total) != 0
474
+ || collect_btrfs_allocation_section_field(system, disk_used) != 0) {
475
+ error("BTRFS: failed to collect physical disks allocation for '%s'", node->id);
476
+ // make it refresh btrfs at the next iteration
477
+ refresh_delta = refresh_every;
478
+ continue;
479
+ }
480
+ }
481
+
482
if(do_allocation_data != CONFIG_BOOLEAN_NO) {
483
if (collect_btrfs_allocation_section_field(data, total_bytes) != 0
305
- || collect_btrfs_allocation_section_field(data, bytes_used) != 0
306
- || collect_btrfs_allocation_section_field(data, disk_total) != 0
307
- || collect_btrfs_allocation_section_field(data, disk_used) != 0) {
484
+ || collect_btrfs_allocation_section_field(data, bytes_used) != 0) {
485
error("BTRFS: failed to collect allocation/data for '%s'", node->id);
486
// make it refresh btrfs at the next iteration
487
refresh_delta = refresh_every;
@@ -315,8 +492,8 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
492
if(do_allocation_metadata != CONFIG_BOOLEAN_NO) {
493
if (collect_btrfs_allocation_section_field(metadata, total_bytes) != 0
494
|| collect_btrfs_allocation_section_field(metadata, bytes_used) != 0
318
- || collect_btrfs_allocation_section_field(metadata, disk_total) != 0
319
- || collect_btrfs_allocation_section_field(metadata, disk_used) != 0) {
495
+ || collect_btrfs_allocation_field(global_rsv_size) != 0
496
+ ) {
497
error("BTRFS: failed to collect allocation/metadata for '%s'", node->id);
498
// make it refresh btrfs at the next iteration
499
refresh_delta = refresh_every;
@@ -326,9 +503,7 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
503
504
if(do_allocation_system != CONFIG_BOOLEAN_NO) {
505
if (collect_btrfs_allocation_section_field(system, total_bytes) != 0
329
- || collect_btrfs_allocation_section_field(system, bytes_used) != 0
330
- || collect_btrfs_allocation_section_field(system, disk_total) != 0
331
- || collect_btrfs_allocation_section_field(system, disk_used) != 0) {
506
+ || collect_btrfs_allocation_section_field(system, bytes_used) != 0) {
507
error("BTRFS: failed to collect allocation/system for '%s'", node->id);
508
// make it refresh btrfs at the next iteration
509
refresh_delta = refresh_every;
@@ -336,117 +511,107 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
511
}
512
}
513
339
- if(do_allocation_global_rsv != CONFIG_BOOLEAN_NO) {
340
- if(collect_btrfs_allocation_field(global_rsv_reserved) != 0
341
- || collect_btrfs_allocation_field(global_rsv_size) != 0) {
342
- error("BTRFS: failed to collect global reserve for '%s'", node->id);
343
- // make it refresh btrfs at the next iteration
344
- refresh_delta = refresh_every;
345
- continue;
346
- }
347
- }
348
-
514
// --------------------------------------------------------------------
350
- // allocation/data
515
+ // allocation/disks
516
352
- if(do_allocation_data == CONFIG_BOOLEAN_YES || (do_allocation_data == CONFIG_BOOLEAN_AUTO && (node->allocation_data_total_bytes || node->allocation_data_bytes_used))) {
353
- do_allocation_data = CONFIG_BOOLEAN_YES;
517
+ if(do_allocation_disks == CONFIG_BOOLEAN_YES || (do_allocation_disks == CONFIG_BOOLEAN_AUTO && node->all_disks_total && node->allocation_data_disk_total)) {
518
+ do_allocation_disks = CONFIG_BOOLEAN_YES;
519
355
- if(unlikely(!node->st_allocation_data)) {
520
+ if(unlikely(!node->st_allocation_disks)) {
521
char id[RRD_ID_LENGTH_MAX + 1], name[RRD_ID_LENGTH_MAX + 1], title[200 + 1];
522
358
- snprintf(id, RRD_ID_LENGTH_MAX, "data_bytes_%s", node->id);
359
- snprintf(name, RRD_ID_LENGTH_MAX, "data_bytes_%s", node->label);
360
- snprintf(title, 200, "BTRFS Data Allocation for %s", node->label);
523
+ snprintf(id, RRD_ID_LENGTH_MAX, "disk_%s", node->id);
524
+ snprintf(name, RRD_ID_LENGTH_MAX, "disk_%s", node->label);
525
+ snprintf(title, 200, "BTRFS Disk Allocation for %s", node->label);
526
527
netdata_fix_chart_id(id);
528
netdata_fix_chart_name(name);
529
365
- node->st_allocation_data = rrdset_create_localhost(
530
+ node->st_allocation_disks = rrdset_create_localhost(
531
"btrfs"
532
, id
533
, name
534
, node->label
370
- , "btrfs.system_bytes"
535
+ , "btrfs.disk"
536
, title
537
, "MB"
538
, "proc"
539
, "sys/fs/btrfs"
540
, 2300
541
, update_every
377
- , RRDSET_TYPE_LINE
542
+ , RRDSET_TYPE_STACKED
543
);
544
380
- node->rd_allocation_data_total_bytes = rrddim_add(node->st_allocation_data, "total", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
381
- node->rd_allocation_data_bytes_used = rrddim_add(node->st_allocation_data, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
382
- node->rd_allocation_data_disk_total = rrddim_add(node->st_allocation_data, "disk_total", "disk total", 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
383
- node->rd_allocation_data_disk_used = rrddim_add(node->st_allocation_data, "disk_used", "disk used", 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
545
+ node->rd_allocation_disks_unallocated = rrddim_add(node->st_allocation_disks, "unallocated", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
546
+ node->rd_allocation_disks_used = rrddim_add(node->st_allocation_disks, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
547
+ node->rd_allocation_disks_free = rrddim_add(node->st_allocation_disks, "free", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
548
}
385
- else rrdset_next(node->st_allocation_data);
549
+ else rrdset_next(node->st_allocation_disks);
550
387
- rrddim_set_by_pointer(node->st_allocation_data, node->rd_allocation_data_total_bytes, node->allocation_data_total_bytes);
388
- rrddim_set_by_pointer(node->st_allocation_data, node->rd_allocation_data_bytes_used, node->allocation_data_bytes_used);
389
- rrddim_set_by_pointer(node->st_allocation_data, node->rd_allocation_data_disk_total, node->allocation_data_disk_total);
390
- rrddim_set_by_pointer(node->st_allocation_data, node->rd_allocation_data_disk_used, node->allocation_data_disk_used);
391
- rrdset_done(node->st_allocation_data);
551
+
552
+ unsigned long long disk_used = node->allocation_data_disk_used + node->allocation_metadata_disk_used + node->allocation_system_disk_used;
553
+ unsigned long long disk_total = node->allocation_data_disk_total + node->allocation_metadata_disk_total + node->allocation_system_disk_total;
554
+ unsigned long long disk_unallocated = node->all_disks_total - disk_total;
555
+
556
+ rrddim_set_by_pointer(node->st_allocation_disks, node->rd_allocation_disks_unallocated, disk_unallocated);
557
+ rrddim_set_by_pointer(node->st_allocation_disks, node->rd_allocation_disks_used, disk_used);
558
+ rrddim_set_by_pointer(node->st_allocation_disks, node->rd_allocation_disks_free, disk_total - disk_used);
559
+ rrdset_done(node->st_allocation_disks);
560
}
561
562
+
563
// --------------------------------------------------------------------
395
- // allocation/system
564
+ // allocation/data
565
397
- if(do_allocation_system == CONFIG_BOOLEAN_YES || (do_allocation_system == CONFIG_BOOLEAN_AUTO && (node->allocation_system_total_bytes || node->allocation_system_bytes_used))) {
398
- do_allocation_system = CONFIG_BOOLEAN_YES;
566
+ if(do_allocation_data == CONFIG_BOOLEAN_YES || (do_allocation_data == CONFIG_BOOLEAN_AUTO && node->allocation_data_total_bytes)) {
567
+ do_allocation_data = CONFIG_BOOLEAN_YES;
568
400
- if(unlikely(!node->st_allocation_system)) {
569
+ if(unlikely(!node->st_allocation_data)) {
570
char id[RRD_ID_LENGTH_MAX + 1], name[RRD_ID_LENGTH_MAX + 1], title[200 + 1];
571
403
- snprintf(id, RRD_ID_LENGTH_MAX, "system_bytes_%s", node->id);
404
- snprintf(name, RRD_ID_LENGTH_MAX, "system_bytes_%s", node->label);
405
- snprintf(title, 200, "BTRFS System Allocation for %s", node->label);
572
+ snprintf(id, RRD_ID_LENGTH_MAX, "data_%s", node->id);
573
+ snprintf(name, RRD_ID_LENGTH_MAX, "data_%s", node->label);
574
+ snprintf(title, 200, "BTRFS Data Allocation for %s", node->label);
575
576
netdata_fix_chart_id(id);
577
netdata_fix_chart_name(name);
578
410
- node->st_allocation_system = rrdset_create_localhost(
579
+ node->st_allocation_data = rrdset_create_localhost(
580
"btrfs"
581
, id
582
, name
583
, node->label
415
- , "btrfs.system_bytes"
584
+ , "btrfs.data"
585
, title
586
, "MB"
587
, "proc"
588
, "sys/fs/btrfs"
589
, 2301
590
, update_every
422
- , RRDSET_TYPE_LINE
591
+ , RRDSET_TYPE_STACKED
592
);
593
425
- node->rd_allocation_system_total_bytes = rrddim_add(node->st_allocation_system, "total", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
426
- node->rd_allocation_system_bytes_used = rrddim_add(node->st_allocation_system, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
427
- node->rd_allocation_system_disk_total = rrddim_add(node->st_allocation_system, "disk_total", "disk total", 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
428
- node->rd_allocation_system_disk_used = rrddim_add(node->st_allocation_system, "disk_used", "disk used", 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
594
+ node->rd_allocation_data_free = rrddim_add(node->st_allocation_data, "free", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
595
+ node->rd_allocation_data_used = rrddim_add(node->st_allocation_data, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
596
}
430
- else rrdset_next(node->st_allocation_system);
597
+ else rrdset_next(node->st_allocation_data);
598
432
- rrddim_set_by_pointer(node->st_allocation_system, node->rd_allocation_system_total_bytes, node->allocation_system_total_bytes);
433
- rrddim_set_by_pointer(node->st_allocation_system, node->rd_allocation_system_bytes_used, node->allocation_system_bytes_used);
434
- rrddim_set_by_pointer(node->st_allocation_system, node->rd_allocation_system_disk_total, node->allocation_system_disk_total);
435
- rrddim_set_by_pointer(node->st_allocation_system, node->rd_allocation_system_disk_used, node->allocation_system_disk_used);
436
- rrdset_done(node->st_allocation_system);
599
+ rrddim_set_by_pointer(node->st_allocation_data, node->rd_allocation_data_free, node->allocation_data_total_bytes - node->allocation_data_bytes_used);
600
+ rrddim_set_by_pointer(node->st_allocation_data, node->rd_allocation_data_used, node->allocation_data_bytes_used);
601
+ rrdset_done(node->st_allocation_data);
602
}
603
604
// --------------------------------------------------------------------
605
// allocation/metadata
606
442
- if(do_allocation_metadata == CONFIG_BOOLEAN_YES || (do_allocation_metadata == CONFIG_BOOLEAN_AUTO && (node->allocation_metadata_total_bytes || node->allocation_metadata_bytes_used))) {
607
+ if(do_allocation_metadata == CONFIG_BOOLEAN_YES || (do_allocation_metadata == CONFIG_BOOLEAN_AUTO && node->allocation_metadata_total_bytes)) {
608
do_allocation_metadata = CONFIG_BOOLEAN_YES;
609
610
if(unlikely(!node->st_allocation_metadata)) {
611
char id[RRD_ID_LENGTH_MAX + 1], name[RRD_ID_LENGTH_MAX + 1], title[200 + 1];
612
448
- snprintf(id, RRD_ID_LENGTH_MAX, "metadata_bytes_%s", node->id);
449
- snprintf(name, RRD_ID_LENGTH_MAX, "metadata_bytes_%s", node->label);
613
+ snprintf(id, RRD_ID_LENGTH_MAX, "metadata_%s", node->id);
614
+ snprintf(name, RRD_ID_LENGTH_MAX, "metadata_%s", node->label);
615
snprintf(title, 200, "BTRFS Metadata Allocation for %s", node->label);
616
617
netdata_fix_chart_id(id);
@@ -457,69 +622,67 @@ int do_sys_fs_btrfs(int update_every, usec_t dt) {
622
, id
623
, name
624
, node->label
460
- , "btrfs.system_bytes"
625
+ , "btrfs.metdata"
626
, title
627
, "MB"
628
, "proc"
629
, "sys/fs/btrfs"
630
, 2302
631
, update_every
467
- , RRDSET_TYPE_LINE
632
+ , RRDSET_TYPE_STACKED
633
);
634
470
- node->rd_allocation_metadata_total_bytes = rrddim_add(node->st_allocation_metadata, "total", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
471
- node->rd_allocation_metadata_bytes_used = rrddim_add(node->st_allocation_metadata, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
472
- node->rd_allocation_metadata_disk_total = rrddim_add(node->st_allocation_metadata, "disk_total", "disk total", 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
473
- node->rd_allocation_metadata_disk_used = rrddim_add(node->st_allocation_metadata, "disk_used", "disk used", 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
635
+ node->rd_allocation_metadata_free = rrddim_add(node->st_allocation_metadata, "free", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
636
+ node->rd_allocation_metadata_used = rrddim_add(node->st_allocation_metadata, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
637
+ node->rd_allocation_metadata_reserved = rrddim_add(node->st_allocation_metadata, "reserved", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
638
}
639
else rrdset_next(node->st_allocation_metadata);
640
477
- rrddim_set_by_pointer(node->st_allocation_metadata, node->rd_allocation_metadata_total_bytes, node->allocation_metadata_total_bytes);
478
- rrddim_set_by_pointer(node->st_allocation_metadata, node->rd_allocation_metadata_bytes_used, node->allocation_metadata_bytes_used);
479
- rrddim_set_by_pointer(node->st_allocation_metadata, node->rd_allocation_metadata_disk_total, node->allocation_metadata_disk_total);
480
- rrddim_set_by_pointer(node->st_allocation_metadata, node->rd_allocation_metadata_disk_used, node->allocation_metadata_disk_used);
641
+ rrddim_set_by_pointer(node->st_allocation_metadata, node->rd_allocation_metadata_free, node->allocation_metadata_total_bytes - node->allocation_metadata_bytes_used - node->allocation_global_rsv_size);
642
+ rrddim_set_by_pointer(node->st_allocation_metadata, node->rd_allocation_metadata_used, node->allocation_metadata_bytes_used);
643
+ rrddim_set_by_pointer(node->st_allocation_metadata, node->rd_allocation_metadata_reserved, node->allocation_global_rsv_size);
644
rrdset_done(node->st_allocation_metadata);
645
}
646
484
-
647
// --------------------------------------------------------------------
486
- // allocation/global_rsv
648
+ // allocation/system
649
488
- if(do_allocation_global_rsv == CONFIG_BOOLEAN_YES || (do_allocation_global_rsv == CONFIG_BOOLEAN_AUTO && (node->allocation_global_rsv_size || node->allocation_global_rsv_reserved))) {
489
- do_allocation_global_rsv = CONFIG_BOOLEAN_YES;
650
+ if(do_allocation_system == CONFIG_BOOLEAN_YES || (do_allocation_system == CONFIG_BOOLEAN_AUTO && node->allocation_system_total_bytes)) {
651
+ do_allocation_system = CONFIG_BOOLEAN_YES;
652
491
- if(unlikely(!node->st_allocation_global_rsv)) {
653
+ if(unlikely(!node->st_allocation_system)) {
654
char id[RRD_ID_LENGTH_MAX + 1], name[RRD_ID_LENGTH_MAX + 1], title[200 + 1];
655
494
- snprintf(id, RRD_ID_LENGTH_MAX, "global_reserve_%s", node->id);
495
- snprintf(name, RRD_ID_LENGTH_MAX, "global_reserve_%s", node->label);
496
- snprintf(title, 200, "BTRFS Global Reserve for %s", node->label);
656
+ snprintf(id, RRD_ID_LENGTH_MAX, "system_%s", node->id);
657
+ snprintf(name, RRD_ID_LENGTH_MAX, "system_%s", node->label);
658
+ snprintf(title, 200, "BTRFS System Allocation for %s", node->label);
659
660
netdata_fix_chart_id(id);
661
netdata_fix_chart_name(name);
662
501
- node->st_allocation_global_rsv = rrdset_create_localhost(
663
+ node->st_allocation_system = rrdset_create_localhost(
664
"btrfs"
665
, id
666
, name
667
, node->label
506
- , "btrfs.system_bytes"
668
+ , "btrfs.system"
669
, title
670
, "MB"
671
, "proc"
672
, "sys/fs/btrfs"
673
, 2303
674
, update_every
513
- , RRDSET_TYPE_LINE
675
+ , RRDSET_TYPE_STACKED
676
);
515
- node->rd_allocation_global_rsv_size = rrddim_add(node->st_allocation_global_rsv, "size", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
516
- node->rd_allocation_global_rsv_reserved = rrddim_add(node->st_allocation_global_rsv, "reserved", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
677
+
678
+ node->rd_allocation_system_free = rrddim_add(node->st_allocation_system, "free", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
679
+ node->rd_allocation_system_used = rrddim_add(node->st_allocation_system, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
680
}
518
- else rrdset_next(node->st_allocation_global_rsv);
681
+ else rrdset_next(node->st_allocation_system);
682
520
- rrddim_set_by_pointer(node->st_allocation_global_rsv, node->rd_allocation_global_rsv_size, node->allocation_global_rsv_size);
521
- rrddim_set_by_pointer(node->st_allocation_global_rsv, node->rd_allocation_global_rsv_reserved, node->allocation_global_rsv_reserved);
522
- rrdset_done(node->st_allocation_global_rsv);
683
+ rrddim_set_by_pointer(node->st_allocation_system, node->rd_allocation_system_free, node->allocation_system_total_bytes - node->allocation_system_bytes_used);
684
+ rrddim_set_by_pointer(node->st_allocation_system, node->rd_allocation_system_used, node->allocation_system_bytes_used);
685
+ rrdset_done(node->st_allocation_system);
686
}
687
}
688