]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
disk.c: add config options to support diskstats 15-20 in KERNEL_LINUX 4256/head
authorzzzyhtheonly <zyhtheonly@yeah.net>
Fri, 26 Jan 2024 03:44:50 +0000 (11:44 +0800)
committerzzzyhtheonly <zyhtheonly@yeah.net>
Fri, 26 Jan 2024 03:44:50 +0000 (11:44 +0800)
Signed-off-by: tiozhang <zyhtheonly@yeah.net>
src/collectd.conf.in
src/collectd.conf.pod
src/disk.c

index c2aa004d5ddb1d3662f303b38c470a255a069615..9eb6f013020465dd7bb499aee679902d6a2a7442 100644 (file)
 #      IgnoreSelected false
 #      UseBSDName false
 #      UdevNameAttr "DEVNAME"
+#      ReportDiscard false
+#      ReportFlush false
 #</Plugin>
 
 #<Plugin dns>
index 99bd12961fe4515550dd98bb98bc6935d555a7fa..01cba6077d3027e16fd77151c130f4e208ed2a26 100644 (file)
@@ -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>
index 5b1b8486c2c7af30a0502e4a0461f549928d17d7..50582e5da6344d2829c691bf35c804734780d782 100644 (file)
@@ -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;
@@ -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;
@@ -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;
@@ -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);
       }