added bcache cache allocation chart; related to #3504
Costa Tsaousis (ktsaou) committed
May 29, 2018 at 00:08 UTC
216e6b8a105809b85e3ed4a1b51eaacac18b495c
1 file changed
+100
-1
src/proc_diskstats.c
+100
-1
@@ -49,6 +49,8 @@ static struct disk {
49
char *bcache_filename_stats_total_cache_bypass_misses;
50
char *bcache_filename_stats_total_cache_readaheads;
51
52
+ char *bcache_filename_priority_stats;
53
+
54
RRDSET *st_io;
55
RRDDIM *rd_io_reads;
56
RRDDIM *rd_io_writes;
@@ -111,6 +113,13 @@ static struct disk {
113
RRDDIM *rd_bcache_readaheads;
114
RRDDIM *rd_bcache_rate_writeback;
115
116
+ RRDSET *st_bcache_cache_allocations;
117
+ RRDDIM *rd_bcache_cache_allocations_unused;
118
+ RRDDIM *rd_bcache_cache_allocations_clean;
119
+ RRDDIM *rd_bcache_cache_allocations_dirty;
120
+ RRDDIM *rd_bcache_cache_allocations_metadata;
121
+ RRDDIM *rd_bcache_cache_allocations_unknown;
122
+
123
struct disk *next;
124
} *disk_root = NULL;
125
@@ -170,6 +179,88 @@ static unsigned long long int bcache_read_number_with_units(const char *filename
179
return 0;
180
}
181
182
+void bcache_read_priority_stats(struct disk *d, const char *family, int update_every) {
183
+ static procfile *ff = NULL;
184
+ static char *separators = " \t:%[]";
185
+
186
+ static ARL_BASE *arl_base = NULL;
187
+
188
+ static unsigned long long unused;
189
+ static unsigned long long clean;
190
+ static unsigned long long dirty;
191
+ static unsigned long long metadata;
192
+ static unsigned long long unknown;
193
+
194
+ if(unlikely(!arl_base)) {
195
+ arl_base = arl_create("bcache/priority_stats", NULL, 60);
196
+ arl_expect(arl_base, "Unused", &unused);
197
+ arl_expect(arl_base, "Clean", &clean);
198
+ arl_expect(arl_base, "Dirty", &dirty);
199
+ arl_expect(arl_base, "Metadata", &metadata);
200
+ }
201
+
202
+ ff = procfile_reopen(ff, d->bcache_filename_priority_stats, separators, PROCFILE_FLAG_DEFAULT);
203
+ if(likely(ff)) ff = procfile_readall(ff);
204
+ if(unlikely(!ff)) {
205
+ separators = " \t:%[]";
206
+ return;
207
+ }
208
+ separators = NULL;
209
+
210
+ arl_begin(arl_base);
211
+ unused = clean = dirty = metadata = unknown = 0;
212
+
213
+ size_t lines = procfile_lines(ff), l;
214
+
215
+ for(l = 0; l < lines ;l++) {
216
+ size_t words = procfile_linewords(ff, l);
217
+ if(unlikely(words < 2)) {
218
+ if(unlikely(words)) error("Cannot read '%s' line %zu. Expected 2 params, read %zu.", d->bcache_filename_priority_stats, l, words);
219
+ continue;
220
+ }
221
+
222
+ if(unlikely(arl_check(arl_base,
223
+ procfile_lineword(ff, l, 0),
224
+ procfile_lineword(ff, l, 1)))) break;
225
+ }
226
+
227
+ unknown = 100 - unused - clean - dirty - metadata;
228
+
229
+ // create / update the cache allocations chart
230
+ {
231
+ if(unlikely(!d->st_bcache_cache_allocations)) {
232
+ d->st_bcache_cache_allocations = rrdset_create_localhost(
233
+ "disk_bcache_cache_alloc"
234
+ , d->device
235
+ , d->disk
236
+ , family
237
+ , "disk.bcache_cache_alloc"
238
+ , "BCache Cache Allocations"
239
+ , "percentage"
240
+ , "proc"
241
+ , "diskstats"
242
+ , 2120
243
+ , update_every
244
+ , RRDSET_TYPE_STACKED
245
+ );
246
+
247
+ d->rd_bcache_cache_allocations_unused = rrddim_add(d->st_bcache_cache_allocations, "unused", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
248
+ d->rd_bcache_cache_allocations_dirty = rrddim_add(d->st_bcache_cache_allocations, "dirty", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
249
+ d->rd_bcache_cache_allocations_clean = rrddim_add(d->st_bcache_cache_allocations, "clean", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
250
+ d->rd_bcache_cache_allocations_metadata = rrddim_add(d->st_bcache_cache_allocations, "metadata", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
251
+ d->rd_bcache_cache_allocations_unknown = rrddim_add(d->st_bcache_cache_allocations, "undefined", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
252
+ }
253
+ else rrdset_next(d->st_bcache_cache_allocations);
254
+
255
+ rrddim_set_by_pointer(d->st_bcache_cache_allocations, d->rd_bcache_cache_allocations_unused, unused);
256
+ rrddim_set_by_pointer(d->st_bcache_cache_allocations, d->rd_bcache_cache_allocations_dirty, dirty);
257
+ rrddim_set_by_pointer(d->st_bcache_cache_allocations, d->rd_bcache_cache_allocations_clean, clean);
258
+ rrddim_set_by_pointer(d->st_bcache_cache_allocations, d->rd_bcache_cache_allocations_metadata, metadata);
259
+ rrddim_set_by_pointer(d->st_bcache_cache_allocations, d->rd_bcache_cache_allocations_unknown, unknown);
260
+ rrdset_done(d->st_bcache_cache_allocations);
261
+ }
262
+}
263
+
264
static inline int is_major_enabled(int major) {
265
static int8_t *major_configs = NULL;
266
static size_t major_size = 0;
@@ -532,6 +623,12 @@ static struct disk *get_disk(unsigned long major, unsigned long minor, char *dis
623
else
624
error("bcache file '%s' cannot be read.", buffer2);
625
626
+ snprintfz(buffer2, FILENAME_MAX, "%s/cache/cache0/priority_stats", buffer); // only one cache is supported by bcache
627
+ if(access(buffer2, R_OK) == 0)
628
+ d->bcache_filename_priority_stats = strdupz(buffer2);
629
+ else
630
+ error("bcache file '%s' cannot be read.", buffer2);
631
+
632
snprintfz(buffer2, FILENAME_MAX, "%s/dirty_data", buffer);
633
if(access(buffer2, R_OK) == 0)
634
d->bcache_filename_dirty_data = strdupz(buffer2);
@@ -1160,11 +1257,12 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1257
if(d->bcache_filename_stats_total_cache_readaheads)
1258
cache_readaheads = bcache_read_number_with_units(d->bcache_filename_stats_total_cache_readaheads);
1259
1260
+ if(d->bcache_filename_priority_stats)
1261
+ bcache_read_priority_stats(d, family, update_every);
1262
1263
// update the charts
1264
1265
{
1167
-
1266
if(unlikely(!d->st_bcache_hit_ratio)) {
1267
d->st_bcache_hit_ratio = rrdset_create_localhost(
1268
"disk_bcache_hit_ratio"
@@ -1421,6 +1519,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1519
freez(t->bcache_filename_stats_total_cache_bypass_hits);
1520
freez(t->bcache_filename_stats_total_cache_bypass_misses);
1521
freez(t->bcache_filename_stats_total_cache_readaheads);
1522
+ freez(t->bcache_filename_priority_stats);
1523
1524
freez(t->disk);
1525
freez(t->device);