Add disk free and other dimensions to FreeBSD Plugin
Vladimir Kobal committed
Oct 17, 2017 at 20:42 UTC
31143aa7e386e4bc5b3135b18238857af44a43b9
1 file changed
+128
-31
src/freebsd_devstat.c
+128
-31
@@ -27,10 +27,15 @@ struct disk {
27
struct prev_dstat {
28
collected_number bytes_read;
29
collected_number bytes_write;
30
+ collected_number bytes_free;
31
collected_number operations_read;
32
collected_number operations_write;
33
+ collected_number operations_other;
34
+ collected_number operations_free;
35
collected_number duration_read_ms;
36
collected_number duration_write_ms;
37
+ collected_number duration_other_ms;
38
+ collected_number duration_free_ms;
39
collected_number busy_time_ms;
40
} prev_dstat;
41
@@ -39,10 +44,13 @@ struct disk {
44
RRDSET *st_io;
45
RRDDIM *rd_io_in;
46
RRDDIM *rd_io_out;
47
+ RRDDIM *rd_io_free;
48
49
RRDSET *st_ops;
50
RRDDIM *rd_ops_in;
51
RRDDIM *rd_ops_out;
52
+ RRDDIM *rd_ops_other;
53
+ RRDDIM *rd_ops_free;
54
55
RRDSET *st_qops;
56
RRDDIM *rd_qops;
@@ -53,14 +61,19 @@ struct disk {
61
RRDSET *st_iotime;
62
RRDDIM *rd_iotime_in;
63
RRDDIM *rd_iotime_out;
64
+ RRDDIM *rd_iotime_other;
65
+ RRDDIM *rd_iotime_free;
66
67
RRDSET *st_await;
68
RRDDIM *rd_await_in;
69
RRDDIM *rd_await_out;
70
+ RRDDIM *rd_await_other;
71
+ RRDDIM *rd_await_free;
72
73
RRDSET *st_avagsz;
74
RRDDIM *rd_avagsz_in;
75
RRDDIM *rd_avagsz_out;
76
+ RRDDIM *rd_avagsz_free;
77
78
RRDSET *st_svctm;
79
RRDDIM *rd_svctm;
@@ -244,7 +257,8 @@ int do_kern_devstat(int update_every, usec_t dt) {
257
258
for (i = 0; i < numdevs; i++) {
259
if (likely(do_system_io)) {
247
- if (((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) || ((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_STORARRAY)) {
260
+ if (((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) ||
261
+ ((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_STORARRAY)) {
262
total_disk_kbytes_read += dstat[i].bytes[DEVSTAT_READ] / KILO_FACTOR;
263
total_disk_kbytes_write += dstat[i].bytes[DEVSTAT_WRITE] / KILO_FACTOR;
264
}
@@ -254,11 +268,14 @@ int do_kern_devstat(int update_every, usec_t dt) {
268
if ((dstat[i].device_type & DEVSTAT_TYPE_PASS) == DEVSTAT_TYPE_PASS)
269
continue;
270
257
- if (((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) || ((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_STORARRAY)) {
271
+ if (((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) ||
272
+ ((dstat[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_STORARRAY)) {
273
char disk[DEVSTAT_NAME_LEN + MAX_INT_DIGITS + 1];
274
struct cur_dstat {
275
collected_number duration_read_ms;
276
collected_number duration_write_ms;
277
+ collected_number duration_other_ms;
278
+ collected_number duration_free_ms;
279
collected_number busy_time_ms;
280
} cur_dstat;
281
@@ -299,12 +316,19 @@ int do_kern_devstat(int update_every, usec_t dt) {
316
317
dm->prev_dstat.bytes_read = dstat[i].bytes[DEVSTAT_READ];
318
dm->prev_dstat.bytes_write = dstat[i].bytes[DEVSTAT_WRITE];
319
+ dm->prev_dstat.bytes_free = dstat[i].bytes[DEVSTAT_FREE];
320
dm->prev_dstat.operations_read = dstat[i].operations[DEVSTAT_READ];
321
dm->prev_dstat.operations_write = dstat[i].operations[DEVSTAT_WRITE];
322
+ dm->prev_dstat.operations_other = dstat[i].operations[DEVSTAT_NO_DATA];
323
+ dm->prev_dstat.operations_free = dstat[i].operations[DEVSTAT_FREE];
324
dm->prev_dstat.duration_read_ms = dstat[i].duration[DEVSTAT_READ].sec * 1000
325
+ dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE;
326
dm->prev_dstat.duration_write_ms = dstat[i].duration[DEVSTAT_WRITE].sec * 1000
307
- + dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE;
327
+ + dstat[i].duration[DEVSTAT_WRITE].frac * BINTIME_SCALE;
328
+ dm->prev_dstat.duration_other_ms = dstat[i].duration[DEVSTAT_NO_DATA].sec * 1000
329
+ + dstat[i].duration[DEVSTAT_NO_DATA].frac * BINTIME_SCALE;
330
+ dm->prev_dstat.duration_free_ms = dstat[i].duration[DEVSTAT_FREE].sec * 1000
331
+ + dstat[i].duration[DEVSTAT_FREE].frac * BINTIME_SCALE;
332
dm->prev_dstat.busy_time_ms = dstat[i].busy_time.sec * 1000
333
+ dstat[i].busy_time.frac * BINTIME_SCALE;
334
}
@@ -312,13 +336,20 @@ int do_kern_devstat(int update_every, usec_t dt) {
336
cur_dstat.duration_read_ms = dstat[i].duration[DEVSTAT_READ].sec * 1000
337
+ dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE;
338
cur_dstat.duration_write_ms = dstat[i].duration[DEVSTAT_WRITE].sec * 1000
315
- + dstat[i].duration[DEVSTAT_READ].frac * BINTIME_SCALE;
339
+ + dstat[i].duration[DEVSTAT_WRITE].frac * BINTIME_SCALE;
340
+ cur_dstat.duration_other_ms = dstat[i].duration[DEVSTAT_NO_DATA].sec * 1000
341
+ + dstat[i].duration[DEVSTAT_NO_DATA].frac * BINTIME_SCALE;
342
+ cur_dstat.duration_free_ms = dstat[i].duration[DEVSTAT_FREE].sec * 1000
343
+ + dstat[i].duration[DEVSTAT_FREE].frac * BINTIME_SCALE;
344
+
345
cur_dstat.busy_time_ms = dstat[i].busy_time.sec * 1000 + dstat[i].busy_time.frac * BINTIME_SCALE;
346
347
// --------------------------------------------------------------------
348
349
if(dm->do_io == CONFIG_BOOLEAN_YES || (dm->do_io == CONFIG_BOOLEAN_AUTO &&
321
- (dstat[i].bytes[DEVSTAT_READ] || dstat[i].bytes[DEVSTAT_WRITE]))) {
350
+ (dstat[i].bytes[DEVSTAT_READ] ||
351
+ dstat[i].bytes[DEVSTAT_WRITE] ||
352
+ dstat[i].bytes[DEVSTAT_FREE]))) {
353
if (unlikely(!dm->st_io)) {
354
dm->st_io = rrdset_create_localhost("disk",
355
disk,
@@ -338,18 +369,24 @@ int do_kern_devstat(int update_every, usec_t dt) {
369
RRD_ALGORITHM_INCREMENTAL);
370
dm->rd_io_out = rrddim_add(dm->st_io, "writes", NULL, -1, KILO_FACTOR,
371
RRD_ALGORITHM_INCREMENTAL);
372
+ dm->rd_io_free = rrddim_add(dm->st_io, "frees", NULL, -1, KILO_FACTOR,
373
+ RRD_ALGORITHM_INCREMENTAL);
374
} else
375
rrdset_next(dm->st_io);
376
344
- rrddim_set_by_pointer(dm->st_io, dm->rd_io_in, dstat[i].bytes[DEVSTAT_READ]);
345
- rrddim_set_by_pointer(dm->st_io, dm->rd_io_out, dstat[i].bytes[DEVSTAT_WRITE]);
377
+ rrddim_set_by_pointer(dm->st_io, dm->rd_io_in, dstat[i].bytes[DEVSTAT_READ]);
378
+ rrddim_set_by_pointer(dm->st_io, dm->rd_io_out, dstat[i].bytes[DEVSTAT_WRITE]);
379
+ rrddim_set_by_pointer(dm->st_io, dm->rd_io_free, dstat[i].bytes[DEVSTAT_FREE]);
380
rrdset_done(dm->st_io);
381
}
382
383
// --------------------------------------------------------------------
384
385
if(dm->do_ops == CONFIG_BOOLEAN_YES || (dm->do_ops == CONFIG_BOOLEAN_AUTO &&
352
- (dstat[i].operations[DEVSTAT_READ] || dstat[i].operations[DEVSTAT_WRITE]))) {
386
+ (dstat[i].operations[DEVSTAT_READ] ||
387
+ dstat[i].operations[DEVSTAT_WRITE] ||
388
+ dstat[i].operations[DEVSTAT_NO_DATA] ||
389
+ dstat[i].operations[DEVSTAT_FREE]))) {
390
if (unlikely(!dm->st_ops)) {
391
dm->st_ops = rrdset_create_localhost("disk_ops",
392
disk,
@@ -367,14 +404,21 @@ int do_kern_devstat(int update_every, usec_t dt) {
404
405
rrdset_flag_set(dm->st_ops, RRDSET_FLAG_DETAIL);
406
370
- dm->rd_ops_in = rrddim_add(dm->st_ops, "reads", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
371
- dm->rd_ops_out = rrddim_add(dm->st_ops, "writes", NULL, -1, 1,
372
- RRD_ALGORITHM_INCREMENTAL);
407
+ dm->rd_ops_in = rrddim_add(dm->st_ops, "reads", NULL, 1, 1,
408
+ RRD_ALGORITHM_INCREMENTAL);
409
+ dm->rd_ops_out = rrddim_add(dm->st_ops, "writes", NULL, -1, 1,
410
+ RRD_ALGORITHM_INCREMENTAL);
411
+ dm->rd_ops_other = rrddim_add(dm->st_ops, "other", NULL, 1, 1,
412
+ RRD_ALGORITHM_INCREMENTAL);
413
+ dm->rd_ops_free = rrddim_add(dm->st_ops, "frees", NULL, -1, 1,
414
+ RRD_ALGORITHM_INCREMENTAL);
415
} else
416
rrdset_next(dm->st_ops);
417
376
- rrddim_set_by_pointer(dm->st_ops, dm->rd_ops_in, dstat[i].operations[DEVSTAT_READ]);
377
- rrddim_set_by_pointer(dm->st_ops, dm->rd_ops_out, dstat[i].operations[DEVSTAT_WRITE]);
418
+ rrddim_set_by_pointer(dm->st_ops, dm->rd_ops_in, dstat[i].operations[DEVSTAT_READ]);
419
+ rrddim_set_by_pointer(dm->st_ops, dm->rd_ops_out, dstat[i].operations[DEVSTAT_WRITE]);
420
+ rrddim_set_by_pointer(dm->st_ops, dm->rd_ops_other, dstat[i].operations[DEVSTAT_NO_DATA]);
421
+ rrddim_set_by_pointer(dm->st_ops, dm->rd_ops_free, dstat[i].operations[DEVSTAT_FREE]);
422
rrdset_done(dm->st_ops);
423
}
424
@@ -440,7 +484,10 @@ int do_kern_devstat(int update_every, usec_t dt) {
484
// --------------------------------------------------------------------
485
486
if(dm->do_iotime == CONFIG_BOOLEAN_YES || (dm->do_iotime == CONFIG_BOOLEAN_AUTO &&
443
- (cur_dstat.duration_read_ms || cur_dstat.duration_write_ms))) {
487
+ (cur_dstat.duration_read_ms ||
488
+ cur_dstat.duration_write_ms ||
489
+ cur_dstat.duration_other_ms ||
490
+ cur_dstat.duration_free_ms))) {
491
if (unlikely(!dm->st_iotime)) {
492
dm->st_iotime = rrdset_create_localhost("disk_iotime",
493
disk,
@@ -458,15 +505,21 @@ int do_kern_devstat(int update_every, usec_t dt) {
505
506
rrdset_flag_set(dm->st_iotime, RRDSET_FLAG_DETAIL);
507
461
- dm->rd_iotime_in = rrddim_add(dm->st_iotime, "reads", NULL, 1, 1,
462
- RRD_ALGORITHM_INCREMENTAL);
463
- dm->rd_iotime_out = rrddim_add(dm->st_iotime, "writes", NULL, -1, 1,
464
- RRD_ALGORITHM_INCREMENTAL);
508
+ dm->rd_iotime_in = rrddim_add(dm->st_iotime, "reads", NULL, 1, 1,
509
+ RRD_ALGORITHM_INCREMENTAL);
510
+ dm->rd_iotime_out = rrddim_add(dm->st_iotime, "writes", NULL, -1, 1,
511
+ RRD_ALGORITHM_INCREMENTAL);
512
+ dm->rd_iotime_other = rrddim_add(dm->st_iotime, "other", NULL, 1, 1,
513
+ RRD_ALGORITHM_INCREMENTAL);
514
+ dm->rd_iotime_free = rrddim_add(dm->st_iotime, "frees", NULL, -1, 1,
515
+ RRD_ALGORITHM_INCREMENTAL);
516
} else
517
rrdset_next(dm->st_iotime);
518
468
- rrddim_set_by_pointer(dm->st_iotime, dm->rd_iotime_in, cur_dstat.duration_read_ms);
469
- rrddim_set_by_pointer(dm->st_iotime, dm->rd_iotime_out, cur_dstat.duration_write_ms);
519
+ rrddim_set_by_pointer(dm->st_iotime, dm->rd_iotime_in, cur_dstat.duration_read_ms);
520
+ rrddim_set_by_pointer(dm->st_iotime, dm->rd_iotime_out, cur_dstat.duration_write_ms);
521
+ rrddim_set_by_pointer(dm->st_iotime, dm->rd_iotime_other, cur_dstat.duration_other_ms);
522
+ rrddim_set_by_pointer(dm->st_iotime, dm->rd_iotime_free, cur_dstat.duration_free_ms);
523
rrdset_done(dm->st_iotime);
524
}
525
@@ -479,7 +532,10 @@ int do_kern_devstat(int update_every, usec_t dt) {
532
// --------------------------------------------------------------------
533
534
if(dm->do_await == CONFIG_BOOLEAN_YES || (dm->do_await == CONFIG_BOOLEAN_AUTO &&
482
- (dstat[i].operations[DEVSTAT_READ] || dstat[i].operations[DEVSTAT_WRITE]))) {
535
+ (dstat[i].operations[DEVSTAT_READ] ||
536
+ dstat[i].operations[DEVSTAT_WRITE] ||
537
+ dstat[i].operations[DEVSTAT_NO_DATA] ||
538
+ dstat[i].operations[DEVSTAT_FREE]))) {
539
if (unlikely(!dm->st_await)) {
540
dm->st_await = rrdset_create_localhost("disk_await",
541
disk,
@@ -497,9 +553,13 @@ int do_kern_devstat(int update_every, usec_t dt) {
553
554
rrdset_flag_set(dm->st_await, RRDSET_FLAG_DETAIL);
555
500
- dm->rd_await_in = rrddim_add(dm->st_await, "reads", NULL, 1, 1,
556
+ dm->rd_await_in = rrddim_add(dm->st_await, "reads", NULL, 1, 1,
557
+ RRD_ALGORITHM_ABSOLUTE);
558
+ dm->rd_await_out = rrddim_add(dm->st_await, "writes", NULL, -1, 1,
559
RRD_ALGORITHM_ABSOLUTE);
502
- dm->rd_await_out = rrddim_add(dm->st_await, "writes", NULL, -1, 1,
560
+ dm->rd_await_other = rrddim_add(dm->st_await, "other", NULL, 1, 1,
561
+ RRD_ALGORITHM_ABSOLUTE);
562
+ dm->rd_await_free = rrddim_add(dm->st_await, "frees", NULL, -1, 1,
563
RRD_ALGORITHM_ABSOLUTE);
564
} else
565
rrdset_next(dm->st_await);
@@ -518,13 +578,29 @@ int do_kern_devstat(int update_every, usec_t dt) {
578
(dstat[i].operations[DEVSTAT_WRITE] -
579
dm->prev_dstat.operations_write) :
580
0);
581
+ rrddim_set_by_pointer(dm->st_await, dm->rd_await_other,
582
+ (dstat[i].operations[DEVSTAT_NO_DATA] -
583
+ dm->prev_dstat.operations_other) ?
584
+ (cur_dstat.duration_other_ms - dm->prev_dstat.duration_other_ms) /
585
+ (dstat[i].operations[DEVSTAT_NO_DATA] -
586
+ dm->prev_dstat.operations_other) :
587
+ 0);
588
+ rrddim_set_by_pointer(dm->st_await, dm->rd_await_free,
589
+ (dstat[i].operations[DEVSTAT_FREE] -
590
+ dm->prev_dstat.operations_free) ?
591
+ (cur_dstat.duration_free_ms - dm->prev_dstat.duration_free_ms) /
592
+ (dstat[i].operations[DEVSTAT_FREE] -
593
+ dm->prev_dstat.operations_free) :
594
+ 0);
595
rrdset_done(dm->st_await);
596
}
597
598
// --------------------------------------------------------------------
599
600
if(dm->do_avagsz == CONFIG_BOOLEAN_YES || (dm->do_avagsz == CONFIG_BOOLEAN_AUTO &&
527
- (dstat[i].operations[DEVSTAT_READ] || dstat[i].operations[DEVSTAT_WRITE]))) {
601
+ (dstat[i].operations[DEVSTAT_READ] ||
602
+ dstat[i].operations[DEVSTAT_WRITE] ||
603
+ dstat[i].operations[DEVSTAT_FREE]))) {
604
if (unlikely(!dm->st_avagsz)) {
605
dm->st_avagsz = rrdset_create_localhost("disk_avgsz",
606
disk,
@@ -542,10 +618,12 @@ int do_kern_devstat(int update_every, usec_t dt) {
618
619
rrdset_flag_set(dm->st_avagsz, RRDSET_FLAG_DETAIL);
620
545
- dm->rd_avagsz_in = rrddim_add(dm->st_avagsz, "reads", NULL, 1, KILO_FACTOR,
546
- RRD_ALGORITHM_ABSOLUTE);
547
- dm->rd_avagsz_out = rrddim_add(dm->st_avagsz, "writes", NULL, -1, KILO_FACTOR,
548
- RRD_ALGORITHM_ABSOLUTE);
621
+ dm->rd_avagsz_in = rrddim_add(dm->st_avagsz, "reads", NULL, 1, KILO_FACTOR,
622
+ RRD_ALGORITHM_ABSOLUTE);
623
+ dm->rd_avagsz_out = rrddim_add(dm->st_avagsz, "writes", NULL, -1, KILO_FACTOR,
624
+ RRD_ALGORITHM_ABSOLUTE);
625
+ dm->rd_avagsz_free = rrddim_add(dm->st_avagsz, "frees", NULL, -1, KILO_FACTOR,
626
+ RRD_ALGORITHM_ABSOLUTE);
627
} else
628
rrdset_next(dm->st_avagsz);
629
@@ -563,13 +641,23 @@ int do_kern_devstat(int update_every, usec_t dt) {
641
(dstat[i].operations[DEVSTAT_WRITE] -
642
dm->prev_dstat.operations_write) :
643
0);
644
+ rrddim_set_by_pointer(dm->st_avagsz, dm->rd_avagsz_free,
645
+ (dstat[i].operations[DEVSTAT_FREE] -
646
+ dm->prev_dstat.operations_free) ?
647
+ (dstat[i].bytes[DEVSTAT_FREE] - dm->prev_dstat.bytes_free) /
648
+ (dstat[i].operations[DEVSTAT_FREE] -
649
+ dm->prev_dstat.operations_free) :
650
+ 0);
651
rrdset_done(dm->st_avagsz);
652
}
653
654
// --------------------------------------------------------------------
655
656
if(dm->do_svctm == CONFIG_BOOLEAN_YES || (dm->do_svctm == CONFIG_BOOLEAN_AUTO &&
572
- (dstat[i].operations[DEVSTAT_READ] || dstat[i].operations[DEVSTAT_WRITE]))) {
657
+ (dstat[i].operations[DEVSTAT_READ] ||
658
+ dstat[i].operations[DEVSTAT_WRITE] ||
659
+ dstat[i].operations[DEVSTAT_NO_DATA] ||
660
+ dstat[i].operations[DEVSTAT_FREE]))) {
661
if (unlikely(!dm->st_svctm)) {
662
dm->st_svctm = rrdset_create_localhost("disk_svctm",
663
disk,
@@ -594,10 +682,14 @@ int do_kern_devstat(int update_every, usec_t dt) {
682
683
rrddim_set_by_pointer(dm->st_svctm, dm->rd_svctm,
684
((dstat[i].operations[DEVSTAT_READ] - dm->prev_dstat.operations_read) +
597
- (dstat[i].operations[DEVSTAT_WRITE] - dm->prev_dstat.operations_write)) ?
685
+ (dstat[i].operations[DEVSTAT_WRITE] - dm->prev_dstat.operations_write) +
686
+ (dstat[i].operations[DEVSTAT_NO_DATA] - dm->prev_dstat.operations_other) +
687
+ (dstat[i].operations[DEVSTAT_FREE] - dm->prev_dstat.operations_free)) ?
688
(cur_dstat.busy_time_ms - dm->prev_dstat.busy_time_ms) /
689
((dstat[i].operations[DEVSTAT_READ] - dm->prev_dstat.operations_read) +
600
- (dstat[i].operations[DEVSTAT_WRITE] - dm->prev_dstat.operations_write)) :
690
+ (dstat[i].operations[DEVSTAT_WRITE] - dm->prev_dstat.operations_write) +
691
+ (dstat[i].operations[DEVSTAT_NO_DATA] - dm->prev_dstat.operations_other) +
692
+ (dstat[i].operations[DEVSTAT_FREE] - dm->prev_dstat.operations_free)) :
693
0);
694
rrdset_done(dm->st_svctm);
695
}
@@ -606,10 +698,15 @@ int do_kern_devstat(int update_every, usec_t dt) {
698
699
dm->prev_dstat.bytes_read = dstat[i].bytes[DEVSTAT_READ];
700
dm->prev_dstat.bytes_write = dstat[i].bytes[DEVSTAT_WRITE];
701
+ dm->prev_dstat.bytes_free = dstat[i].bytes[DEVSTAT_FREE];
702
dm->prev_dstat.operations_read = dstat[i].operations[DEVSTAT_READ];
703
dm->prev_dstat.operations_write = dstat[i].operations[DEVSTAT_WRITE];
704
+ dm->prev_dstat.operations_other = dstat[i].operations[DEVSTAT_NO_DATA];
705
+ dm->prev_dstat.operations_free = dstat[i].operations[DEVSTAT_FREE];
706
dm->prev_dstat.duration_read_ms = cur_dstat.duration_read_ms;
707
dm->prev_dstat.duration_write_ms = cur_dstat.duration_write_ms;
708
+ dm->prev_dstat.duration_other_ms = cur_dstat.duration_other_ms;
709
+ dm->prev_dstat.duration_free_ms = cur_dstat.duration_free_ms;
710
dm->prev_dstat.busy_time_ms = cur_dstat.busy_time_ms;
711
}
712
}