Use LVM UUIDs in chart ids for logical volumes (#13525)
Vladimir Kobal committed
Aug 16, 2022 at 18:06 UTC
6e2c07e1128555268e896bebd982d2e971dab2ea
1 file changed
+57
-25
collectors/proc.plugin/proc_diskstats.c
+57
-25
@@ -25,6 +25,8 @@ static struct disk {
25
26
char *mount_point;
27
28
+ char *chart_id;
29
+
30
// disk options caching
31
int do_io;
32
int do_ops;
@@ -283,7 +285,7 @@ void bcache_read_priority_stats(struct disk *d, const char *family, int update_e
285
if(unlikely(!d->st_bcache_cache_allocations)) {
286
d->st_bcache_cache_allocations = rrdset_create_localhost(
287
"disk_bcache_cache_alloc"
286
- , d->device
288
+ , d->chart_id
289
, d->disk
290
, family
291
, "disk.bcache_cache_alloc"
@@ -609,6 +611,26 @@ static struct disk *get_disk(unsigned long major, unsigned long minor, char *dis
611
last->next = d;
612
}
613
614
+ d->chart_id = strdupz(d->device);
615
+
616
+ // read device uuid if it is an LVM volume
617
+ if (!strncmp(d->device, "dm-", 3)) {
618
+ char uuid_filename[FILENAME_MAX + 1];
619
+ snprintfz(uuid_filename, FILENAME_MAX, path_to_sys_devices_virtual_block_device, disk);
620
+ strncat(uuid_filename, "/dm/uuid", FILENAME_MAX);
621
+
622
+ char device_uuid[RRD_ID_LENGTH_MAX + 1];
623
+ if (!read_file(uuid_filename, device_uuid, RRD_ID_LENGTH_MAX) && !strncmp(device_uuid, "LVM-", 4)) {
624
+ trim(device_uuid);
625
+
626
+ char chart_id[RRD_ID_LENGTH_MAX + 1];
627
+ snprintf(chart_id, RRD_ID_LENGTH_MAX, "%s-%s", d->device, device_uuid + 4);
628
+
629
+ freez(d->chart_id);
630
+ d->chart_id = strdupz(chart_id);
631
+ }
632
+ }
633
+
634
char buffer[FILENAME_MAX + 1];
635
636
// find if it is a physical disk
@@ -1078,7 +1100,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1100
if(unlikely(!d->st_io)) {
1101
d->st_io = rrdset_create_localhost(
1102
RRD_TYPE_DISK
1081
- , d->device
1103
+ , d->chart_id
1104
, d->disk
1105
, family
1106
, "disk.io"
@@ -1109,7 +1131,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1131
if (unlikely(!d->st_ext_io)) {
1132
d->st_ext_io = rrdset_create_localhost(
1133
"disk_ext"
1112
- , d->device
1134
+ , d->chart_id
1135
, d->disk
1136
, family
1137
, "disk_ext.io"
@@ -1142,7 +1164,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1164
if(unlikely(!d->st_ops)) {
1165
d->st_ops = rrdset_create_localhost(
1166
"disk_ops"
1145
- , d->device
1167
+ , d->chart_id
1168
, d->disk
1169
, family
1170
, "disk.ops"
@@ -1175,7 +1197,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1197
if (unlikely(!d->st_ext_ops)) {
1198
d->st_ext_ops = rrdset_create_localhost(
1199
"disk_ext_ops"
1178
- , d->device
1200
+ , d->chart_id
1201
, d->disk
1202
, family
1203
, "disk_ext.ops"
@@ -1214,7 +1236,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1236
if(unlikely(!d->st_qops)) {
1237
d->st_qops = rrdset_create_localhost(
1238
"disk_qops"
1217
- , d->device
1239
+ , d->chart_id
1240
, d->disk
1241
, family
1242
, "disk.qops"
@@ -1248,7 +1270,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1270
if(unlikely(!d->st_backlog)) {
1271
d->st_backlog = rrdset_create_localhost(
1272
"disk_backlog"
1251
- , d->device
1273
+ , d->chart_id
1274
, d->disk
1275
, family
1276
, "disk.backlog"
@@ -1282,7 +1304,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1304
if(unlikely(!d->st_busy)) {
1305
d->st_busy = rrdset_create_localhost(
1306
"disk_busy"
1285
- , d->device
1307
+ , d->chart_id
1308
, d->disk
1309
, family
1310
, "disk.busy"
@@ -1311,7 +1333,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1333
if(unlikely(!d->st_util)) {
1334
d->st_util = rrdset_create_localhost(
1335
"disk_util"
1314
- , d->device
1336
+ , d->chart_id
1337
, d->disk
1338
, family
1339
, "disk.util"
@@ -1350,7 +1372,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1372
if(unlikely(!d->st_mops)) {
1373
d->st_mops = rrdset_create_localhost(
1374
"disk_mops"
1353
- , d->device
1375
+ , d->chart_id
1376
, d->disk
1377
, family
1378
, "disk.mops"
@@ -1385,7 +1407,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1407
if(unlikely(!d->st_ext_mops)) {
1408
d->st_ext_mops = rrdset_create_localhost(
1409
"disk_ext_mops"
1388
- , d->device
1410
+ , d->chart_id
1411
, d->disk
1412
, family
1413
, "disk_ext.mops"
@@ -1420,7 +1442,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1442
if(unlikely(!d->st_iotime)) {
1443
d->st_iotime = rrdset_create_localhost(
1444
"disk_iotime"
1423
- , d->device
1445
+ , d->chart_id
1446
, d->disk
1447
, family
1448
, "disk.iotime"
@@ -1453,7 +1475,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1475
if(unlikely(!d->st_ext_iotime)) {
1476
d->st_ext_iotime = rrdset_create_localhost(
1477
"disk_ext_iotime"
1456
- , d->device
1478
+ , d->chart_id
1479
, d->disk
1480
, family
1481
, "disk_ext.iotime"
@@ -1498,7 +1520,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1520
if(unlikely(!d->st_await)) {
1521
d->st_await = rrdset_create_localhost(
1522
"disk_await"
1501
- , d->device
1523
+ , d->chart_id
1524
, d->disk
1525
, family
1526
, "disk.await"
@@ -1529,7 +1551,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1551
if(unlikely(!d->st_ext_await)) {
1552
d->st_ext_await = rrdset_create_localhost(
1553
"disk_ext_await"
1532
- , d->device
1554
+ , d->chart_id
1555
, d->disk
1556
, family
1557
, "disk_ext.await"
@@ -1573,7 +1595,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1595
if(unlikely(!d->st_avgsz)) {
1596
d->st_avgsz = rrdset_create_localhost(
1597
"disk_avgsz"
1576
- , d->device
1598
+ , d->chart_id
1599
, d->disk
1600
, family
1601
, "disk.avgsz"
@@ -1604,7 +1626,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1626
if(unlikely(!d->st_ext_avgsz)) {
1627
d->st_ext_avgsz = rrdset_create_localhost(
1628
"disk_ext_avgsz"
1607
- , d->device
1629
+ , d->chart_id
1630
, d->disk
1631
, family
1632
, "disk_ext.avgsz"
@@ -1643,7 +1665,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1665
if(unlikely(!d->st_svctm)) {
1666
d->st_svctm = rrdset_create_localhost(
1667
"disk_svctm"
1646
- , d->device
1668
+ , d->chart_id
1669
, d->disk
1670
, family
1671
, "disk.svctm"
@@ -1751,7 +1773,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1773
if(unlikely(!d->st_bcache_hit_ratio)) {
1774
d->st_bcache_hit_ratio = rrdset_create_localhost(
1775
"disk_bcache_hit_ratio"
1754
- , d->device
1776
+ , d->chart_id
1777
, d->disk
1778
, family
1779
, "disk.bcache_hit_ratio"
@@ -1786,7 +1808,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1808
if(unlikely(!d->st_bcache_rates)) {
1809
d->st_bcache_rates = rrdset_create_localhost(
1810
"disk_bcache_rates"
1789
- , d->device
1811
+ , d->chart_id
1812
, d->disk
1813
, family
1814
, "disk.bcache_rates"
@@ -1816,7 +1838,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1838
if(unlikely(!d->st_bcache_size)) {
1839
d->st_bcache_size = rrdset_create_localhost(
1840
"disk_bcache_size"
1819
- , d->device
1841
+ , d->chart_id
1842
, d->disk
1843
, family
1844
, "disk.bcache_size"
@@ -1844,7 +1866,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1866
if(unlikely(!d->st_bcache_usage)) {
1867
d->st_bcache_usage = rrdset_create_localhost(
1868
"disk_bcache_usage"
1847
- , d->device
1869
+ , d->chart_id
1870
, d->disk
1871
, family
1872
, "disk.bcache_usage"
@@ -1873,7 +1895,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1895
if(unlikely(!d->st_bcache_cache_read_races)) {
1896
d->st_bcache_cache_read_races = rrdset_create_localhost(
1897
"disk_bcache_cache_read_races"
1876
- , d->device
1898
+ , d->chart_id
1899
, d->disk
1900
, family
1901
, "disk.bcache_cache_read_races"
@@ -1908,7 +1930,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1930
if(unlikely(!d->st_bcache)) {
1931
d->st_bcache = rrdset_create_localhost(
1932
"disk_bcache"
1911
- , d->device
1933
+ , d->chart_id
1934
, d->disk
1935
, family
1936
, "disk.bcache"
@@ -1948,7 +1970,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
1970
if(unlikely(!d->st_bcache_bypass)) {
1971
d->st_bcache_bypass = rrdset_create_localhost(
1972
"disk_bcache_bypass"
1951
- , d->device
1973
+ , d->chart_id
1974
, d->disk
1975
, family
1976
, "disk.bcache_bypass"
@@ -2023,12 +2045,19 @@ int do_proc_diskstats(int update_every, usec_t dt) {
2045
struct disk *t = d;
2046
2047
rrdset_obsolete_and_pointer_null(d->st_avgsz);
2048
+ rrdset_obsolete_and_pointer_null(d->st_ext_avgsz);
2049
rrdset_obsolete_and_pointer_null(d->st_await);
2050
+ rrdset_obsolete_and_pointer_null(d->st_ext_await);
2051
rrdset_obsolete_and_pointer_null(d->st_backlog);
2052
+ rrdset_obsolete_and_pointer_null(d->st_busy);
2053
rrdset_obsolete_and_pointer_null(d->st_io);
2054
+ rrdset_obsolete_and_pointer_null(d->st_ext_io);
2055
rrdset_obsolete_and_pointer_null(d->st_iotime);
2056
+ rrdset_obsolete_and_pointer_null(d->st_ext_iotime);
2057
rrdset_obsolete_and_pointer_null(d->st_mops);
2058
+ rrdset_obsolete_and_pointer_null(d->st_ext_mops);
2059
rrdset_obsolete_and_pointer_null(d->st_ops);
2060
+ rrdset_obsolete_and_pointer_null(d->st_ext_ops);
2061
rrdset_obsolete_and_pointer_null(d->st_qops);
2062
rrdset_obsolete_and_pointer_null(d->st_svctm);
2063
rrdset_obsolete_and_pointer_null(d->st_util);
@@ -2038,6 +2067,8 @@ int do_proc_diskstats(int update_every, usec_t dt) {
2067
rrdset_obsolete_and_pointer_null(d->st_bcache_size);
2068
rrdset_obsolete_and_pointer_null(d->st_bcache_usage);
2069
rrdset_obsolete_and_pointer_null(d->st_bcache_hit_ratio);
2070
+ rrdset_obsolete_and_pointer_null(d->st_bcache_cache_allocations);
2071
+ rrdset_obsolete_and_pointer_null(d->st_bcache_cache_read_races);
2072
2073
if(d == disk_root) {
2074
disk_root = d = d->next;
@@ -2068,6 +2099,7 @@ int do_proc_diskstats(int update_every, usec_t dt) {
2099
freez(t->disk);
2100
freez(t->device);
2101
freez(t->mount_point);
2102
+ freez(t->chart_id);
2103
freez(t);
2104
}
2105
else {