| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_DISK_IO_H |
| 4 | #define NETDATA_DISK_IO_H |
| 5 | |
| 6 | #include "common-contexts.h" |
| 7 | |
| 8 | typedef struct { |
| 9 | RRDSET *st_io; |
| 10 | RRDDIM *rd_io_reads; |
| 11 | RRDDIM *rd_io_writes; |
| 12 | } ND_DISK_IO; |
| 13 | |
| 14 | static inline void common_disk_io(ND_DISK_IO *d, const char *id, const char *name, uint64_t bytes_read, uint64_t bytes_write, int update_every, instance_labels_cb_t cb, void *data) { |
| 15 | if(unlikely(!d->st_io)) { |
| 16 | d->st_io = rrdset_create_localhost( |
| 17 | "disk" |
| 18 | , id |
| 19 | , name |
| 20 | , "io" |
| 21 | , "disk.io" |
| 22 | , "Disk I/O Bandwidth" |
| 23 | , "KiB/s" |
| 24 | , _COMMON_PLUGIN_NAME |
| 25 | , _COMMON_PLUGIN_MODULE_NAME |
| 26 | , NETDATA_CHART_PRIO_DISK_IO |
| 27 | , update_every |
| 28 | , RRDSET_TYPE_AREA |
| 29 | ); |
| 30 | |
| 31 | d->rd_io_reads = rrddim_add(d->st_io, "reads", NULL, 1, 1024, RRD_ALGORITHM_INCREMENTAL); |
| 32 | d->rd_io_writes = rrddim_add(d->st_io, "writes", NULL, -1, 1024, RRD_ALGORITHM_INCREMENTAL); |
| 33 | |
| 34 | if(cb) |
| 35 | cb(d->st_io, data); |
| 36 | } |
| 37 | |
| 38 | // this always have to be in base units, so that exporting sends base units to other time-series db |
| 39 | rrddim_set_by_pointer(d->st_io, d->rd_io_reads, (collected_number)bytes_read); |
| 40 | rrddim_set_by_pointer(d->st_io, d->rd_io_writes, (collected_number)bytes_write); |
| 41 | rrdset_done(d->st_io); |
| 42 | } |
| 43 | |
| 44 | #endif //NETDATA_DISK_IO_H |