Skip to content

Commit

Permalink
Merge pull request collectd#4256 from zzzyhtheonly/main
Browse files Browse the repository at this point in the history
disk.c: add config options to support diskstats 15-20 in KERNEL_LINUX
  • Loading branch information
octo committed Jan 26, 2024
2 parents 3a48ff2 + b8447f7 commit cfbf444
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/collectd.conf.in
Expand Up @@ -683,6 +683,8 @@
# IgnoreSelected false
# UseBSDName false
# UdevNameAttr "DEVNAME"
# ReportDiscard false
# ReportFlush false
#</Plugin>

#<Plugin dns>
Expand Down
10 changes: 10 additions & 0 deletions src/collectd.conf.pod
Expand Up @@ -3027,6 +3027,16 @@ data about the whole disk and each partition being mixed together incorrectly.
In this case, you can use B<ID_COLLECTD> attribute that is provided by
I<contrib/99-storage-collectd.rules> udev rule file instead.

=item B<ReportDiscard> B<true>|B<false>

Whether to submit discard metrics (/proc/diskstats 15-18), on Linux only.
Requires Linux Kernel version > 4.18+.

=item B<ReportFlush> B<true>|B<false>

Whether to submit flush metrics (/proc/diskstats 19-20), on Linux only.
Requires Linux Kernel version > 5.5+.

=back

=head2 Plugin C<dns>
Expand Down
26 changes: 22 additions & 4 deletions src/disk.c
Expand Up @@ -119,6 +119,9 @@ typedef struct diskstats {
} diskstats_t;

static diskstats_t *disklist;

static bool report_discard;
static bool report_flush;
/* #endif KERNEL_LINUX */
#elif KERNEL_FREEBSD
static struct gmesh geom_tree;
Expand Down Expand Up @@ -164,8 +167,9 @@ static char *conf_udev_name_attr;
static struct udev *handle_udev;
#endif

static const char *config_keys[] = {"Disk", "UseBSDName", "IgnoreSelected",
"UdevNameAttr"};
static const char *config_keys[] = {"Disk", "UseBSDName",
"IgnoreSelected", "UdevNameAttr",
"ReportDiscard", "ReportFlush"};
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);

static ignorelist_t *ignorelist;
Expand Down Expand Up @@ -201,6 +205,20 @@ static int disk_config(const char *key, const char *value) {
#else
WARNING("disk plugin: The \"UdevNameAttr\" option is only supported "
"if collectd is built with libudev support");
#endif
} else if (strcasecmp("ReportDiscard", key) == 0) {
#if KERNEL_LINUX
report_discard = IS_TRUE(value);
#else
WARNING("disk plugin: The \"ReportDiscard\" option is only supported "
"on Linux and will be ignored.");
#endif
} else if (strcasecmp("ReportFlush", key) == 0) {
#if KERNEL_LINUX
report_flush = IS_TRUE(value);
#else
WARNING("disk plugin: The \"ReportFlush\" option is only supported "
"on Linux and will be ignored.");
#endif
} else {
return -1;
Expand Down Expand Up @@ -981,14 +999,14 @@ static int disk_read(void) {
submit_in_progress(output_name, in_progress);
if (ds->has_io_time)
submit_io_time(output_name, io_time, weighted_time);
if (ds->has_discard) {
if (report_discard && ds->has_discard) {
disk_submit_single(output_name, "disk_discard_ops", discard_ops);
disk_submit_single(output_name, "disk_discard_merged", discard_merged);
disk_submit_single(output_name, "disk_discard_sectors",
discard_sectors);
disk_submit_single(output_name, "disk_discard_time", discard_time);
}
if (ds->has_flush) {
if (report_flush && ds->has_flush) {
disk_submit_single(output_name, "disk_flush_ops", flush_ops);
disk_submit_single(output_name, "disk_flush_time", flush_time);
}
Expand Down

0 comments on commit cfbf444

Please sign in to comment.