| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_DISK_OPS_H |
| 4 | #define NETDATA_DISK_OPS_H |
| 5 | |
| 6 | #include "common-contexts.h" |
| 7 | |
| 8 | typedef struct { |
| 9 | RRDSET *st_ops; |
| 10 | RRDDIM *rd_ops_reads; |
| 11 | RRDDIM *rd_ops_writes; |
| 12 | } ND_DISK_OPS; |
| 13 | |
| 14 | static inline void common_disk_ops(ND_DISK_OPS *d, const char *id, const char *name, uint64_t ops_read, uint64_t ops_write, int update_every, instance_labels_cb_t cb, void *data) { |
| 15 | if(unlikely(!d->st_ops)) { |
| 16 | d->st_ops = rrdset_create_localhost( |
| 17 | "disk_ops" |
| 18 | , id |
| 19 | , name |
| 20 | , "ops" |
| 21 | , "disk.ops" |
| 22 | , "Disk Completed I/O Operations" |
| 23 | , "operations/s" |
| 24 | , _COMMON_PLUGIN_NAME |
| 25 | , _COMMON_PLUGIN_MODULE_NAME |
| 26 | , NETDATA_CHART_PRIO_DISK_OPS |
| 27 | , update_every |
| 28 | , RRDSET_TYPE_LINE |
| 29 | ); |
| 30 | |
| 31 | d->rd_ops_reads = rrddim_add(d->st_ops, "reads", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 32 | d->rd_ops_writes = rrddim_add(d->st_ops, "writes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 33 | |
| 34 | if(cb) |
| 35 | cb(d->st_ops, 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_ops, d->rd_ops_reads, (collected_number)ops_read); |
| 40 | rrddim_set_by_pointer(d->st_ops, d->rd_ops_writes, (collected_number)ops_write); |
| 41 | rrdset_done(d->st_ops); |
| 42 | } |
| 43 | |
| 44 | #endif //NETDATA_DISK_OPS_H |