From patchwork Thu Jul 8 11:20:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 4497 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4GLDNY6Z0Zz3xGX for ; Thu, 8 Jul 2021 11:20:13 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4GLDNV6s3Yzwl; Thu, 8 Jul 2021 11:20:10 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4GLDNV4QR7z2yyB; Thu, 8 Jul 2021 11:20:10 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4GLDNT68PMz2yN1 for ; Thu, 8 Jul 2021 11:20:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4GLDNT1JkKz25; Thu, 8 Jul 2021 11:20:09 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1625743209; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vr7TUnMquiS/1BdtvRhaDOanUbCU1BYN2RYYcFM4Ct4=; b=BW4ONB7l87jihF1NHx13rVvVIS+WBsjD22YCTYaP73uVUkB1PvFeKg0Q9izT555716qIx3 haWJeCdJLrin2CBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1625743209; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vr7TUnMquiS/1BdtvRhaDOanUbCU1BYN2RYYcFM4Ct4=; b=ckuD9sawgKaiYU0Y5JNm14YPpJjL7tg0eksSF0IfjjeX7wMAD3SX/yC6mkvhS/kJlRUKDD 8Q9pAOM81jlQxRe7OgrHmqzrV61/J0tE3V+cHdev/IUxIJs9UZ3kSYsiXXMCX56uaJJE6L b9+DcjH/ehVv0iTk8bGScX7ipjfFAYiCVx57bmoUY6+HEcpLV8tIexxVpam7ypxSra9mWe cGgJkFuLPTht4GPQYsUFbkKzVLgqbrrksqwaHdI5meTBNfswECvx7FeLAldxLQsfuO2n5K c4ktQaRDDu+CTRuES/Y5LplcwIDKtBaAQJ0wcMWCqhSS5sawEGNU0rbnu9CJ9w== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH 3/3] collectd: Use libstatgrab to read disk stats Date: Thu, 8 Jul 2021 11:20:05 +0000 Message-Id: <20210708112005.22389-3-michael.tremer@ipfire.org> In-Reply-To: <20210708112005.22389-1-michael.tremer@ipfire.org> References: <20210708112005.22389-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Michael Tremer --- lfs/collectd | 1 + ...collectd-4.10-drop-linux-disk-module.patch | 299 ++++++++++++++++++ 2 files changed, 300 insertions(+) create mode 100644 src/patches/collectd-4.10-drop-linux-disk-module.patch diff --git a/lfs/collectd b/lfs/collectd index 36b507868..09d8c6fcf 100644 --- a/lfs/collectd +++ b/lfs/collectd @@ -107,6 +107,7 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) cd $(DIR_APP) && patch -p1 -i $(DIR_SRC)/src/patches/collectd-4.10.9-xfs-compile-fix.patch cd $(DIR_APP) && patch -p1 -i $(DIR_SRC)/src/patches/collectd-4.10-libiptc-build-fixes.patch cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/collectd-4.10.9-remove-checks-for-SENSORS_API_VERSION-upper-limit.patch + cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/collectd-4.10-drop-linux-disk-module.patch cd $(DIR_APP) && autoupdate -v configure.in cd $(DIR_APP) && autoreconf -vfi cd $(DIR_APP)/libltdl && autoreconf -vfi diff --git a/src/patches/collectd-4.10-drop-linux-disk-module.patch b/src/patches/collectd-4.10-drop-linux-disk-module.patch new file mode 100644 index 000000000..02e9543f1 --- /dev/null +++ b/src/patches/collectd-4.10-drop-linux-disk-module.patch @@ -0,0 +1,299 @@ +diff --git a/src/collectd.c b/src/collectd.c +index 6b77d599..f17c19eb 100644 +--- a/src/collectd.c ++++ b/src/collectd.c +@@ -294,7 +294,7 @@ static int do_init (void) + #endif + + #if HAVE_LIBSTATGRAB +- if (sg_init ()) ++ if (sg_init (0)) + { + ERROR ("sg_init: %s", sg_str_error (sg_get_error ())); + return (-1); +diff --git a/src/disk.c b/src/disk.c +index 4a78f1bd..5f972aa5 100644 +--- a/src/disk.c ++++ b/src/disk.c +@@ -77,34 +77,6 @@ + static mach_port_t io_master_port = MACH_PORT_NULL; + /* #endif HAVE_IOKIT_IOKITLIB_H */ + +-#elif KERNEL_LINUX +-typedef struct diskstats +-{ +- char *name; +- +- /* This overflows in roughly 1361 years */ +- unsigned int poll_count; +- +- counter_t read_sectors; +- counter_t write_sectors; +- +- counter_t read_bytes; +- counter_t write_bytes; +- +- counter_t read_ops; +- counter_t write_ops; +- counter_t read_time; +- counter_t write_time; +- +- counter_t avg_read_time; +- counter_t avg_write_time; +- +- struct diskstats *next; +-} diskstats_t; +- +-static diskstats_t *disklist; +-/* #endif KERNEL_LINUX */ +- + #elif HAVE_LIBKSTAT + #define MAX_NUMDISK 256 + extern kstat_ctl_t *kc; +@@ -182,10 +154,6 @@ static int disk_init (void) + } + /* #endif HAVE_IOKIT_IOKITLIB_H */ + +-#elif KERNEL_LINUX +- /* do nothing */ +-/* #endif KERNEL_LINUX */ +- + #elif HAVE_LIBKSTAT + kstat_t *ksp_chain; + +@@ -235,16 +203,6 @@ static void disk_submit (const char *plugin_instance, + plugin_dispatch_values (&vl); + } /* void disk_submit */ + +-#if KERNEL_LINUX +-static counter_t disk_calc_time_incr (counter_t delta_time, counter_t delta_ops) +-{ +- double avg_time = ((double) delta_time) / ((double) delta_ops); +- double avg_time_incr = ((double) interval_g) * avg_time; +- +- return ((counter_t) (avg_time_incr + .5)); +-} +-#endif +- + #if HAVE_IOKIT_IOKITLIB_H + static signed long long dict_get_value (CFDictionaryRef dict, const char *key) + { +@@ -428,218 +386,6 @@ static int disk_read (void) + IOObjectRelease (disk_list); + /* #endif HAVE_IOKIT_IOKITLIB_H */ + +-#elif KERNEL_LINUX +- FILE *fh; +- char buffer[1024]; +- +- char *fields[32]; +- int numfields; +- int fieldshift = 0; +- +- int minor = 0; +- +- counter_t read_sectors = 0; +- counter_t write_sectors = 0; +- +- counter_t read_ops = 0; +- counter_t read_merged = 0; +- counter_t read_time = 0; +- counter_t write_ops = 0; +- counter_t write_merged = 0; +- counter_t write_time = 0; +- int is_disk = 0; +- +- diskstats_t *ds, *pre_ds; +- +- if ((fh = fopen ("/proc/diskstats", "r")) == NULL) +- { +- fh = fopen ("/proc/partitions", "r"); +- if (fh == NULL) +- { +- ERROR ("disk plugin: fopen (/proc/{diskstats,partitions}) failed."); +- return (-1); +- } +- +- /* Kernel is 2.4.* */ +- fieldshift = 1; +- } +- +- while (fgets (buffer, sizeof (buffer), fh) != NULL) +- { +- char *disk_name; +- +- numfields = strsplit (buffer, fields, 32); +- +- if ((numfields != (14 + fieldshift)) && (numfields != 7)) +- continue; +- +- minor = atoll (fields[1]); +- +- disk_name = fields[2 + fieldshift]; +- +- for (ds = disklist, pre_ds = disklist; ds != NULL; pre_ds = ds, ds = ds->next) +- if (strcmp (disk_name, ds->name) == 0) +- break; +- +- if (ds == NULL) +- { +- if ((ds = (diskstats_t *) calloc (1, sizeof (diskstats_t))) == NULL) +- continue; +- +- if ((ds->name = strdup (disk_name)) == NULL) +- { +- free (ds); +- continue; +- } +- +- if (pre_ds == NULL) +- disklist = ds; +- else +- pre_ds->next = ds; +- } +- +- is_disk = 0; +- if (numfields == 7) +- { +- /* Kernel 2.6, Partition */ +- read_ops = atoll (fields[3]); +- read_sectors = atoll (fields[4]); +- write_ops = atoll (fields[5]); +- write_sectors = atoll (fields[6]); +- } +- else if (numfields == (14 + fieldshift)) +- { +- read_ops = atoll (fields[3 + fieldshift]); +- write_ops = atoll (fields[7 + fieldshift]); +- +- read_sectors = atoll (fields[5 + fieldshift]); +- write_sectors = atoll (fields[9 + fieldshift]); +- +- if ((fieldshift == 0) || (minor == 0)) +- { +- is_disk = 1; +- read_merged = atoll (fields[4 + fieldshift]); +- read_time = atoll (fields[6 + fieldshift]); +- write_merged = atoll (fields[8 + fieldshift]); +- write_time = atoll (fields[10+ fieldshift]); +- } +- } +- else +- { +- DEBUG ("numfields = %i; => unknown file format.", numfields); +- continue; +- } +- +- { +- counter_t diff_read_sectors; +- counter_t diff_write_sectors; +- +- /* If the counter wraps around, it's only 32 bits.. */ +- if (read_sectors < ds->read_sectors) +- diff_read_sectors = 1 + read_sectors +- + (UINT_MAX - ds->read_sectors); +- else +- diff_read_sectors = read_sectors - ds->read_sectors; +- if (write_sectors < ds->write_sectors) +- diff_write_sectors = 1 + write_sectors +- + (UINT_MAX - ds->write_sectors); +- else +- diff_write_sectors = write_sectors - ds->write_sectors; +- +- ds->read_bytes += 512 * diff_read_sectors; +- ds->write_bytes += 512 * diff_write_sectors; +- ds->read_sectors = read_sectors; +- ds->write_sectors = write_sectors; +- } +- +- /* Calculate the average time an io-op needs to complete */ +- if (is_disk) +- { +- counter_t diff_read_ops; +- counter_t diff_write_ops; +- counter_t diff_read_time; +- counter_t diff_write_time; +- +- if (read_ops < ds->read_ops) +- diff_read_ops = 1 + read_ops +- + (UINT_MAX - ds->read_ops); +- else +- diff_read_ops = read_ops - ds->read_ops; +- DEBUG ("disk plugin: disk_name = %s; read_ops = %llu; " +- "ds->read_ops = %llu; diff_read_ops = %llu;", +- disk_name, +- read_ops, ds->read_ops, diff_read_ops); +- +- if (write_ops < ds->write_ops) +- diff_write_ops = 1 + write_ops +- + (UINT_MAX - ds->write_ops); +- else +- diff_write_ops = write_ops - ds->write_ops; +- +- if (read_time < ds->read_time) +- diff_read_time = 1 + read_time +- + (UINT_MAX - ds->read_time); +- else +- diff_read_time = read_time - ds->read_time; +- +- if (write_time < ds->write_time) +- diff_write_time = 1 + write_time +- + (UINT_MAX - ds->write_time); +- else +- diff_write_time = write_time - ds->write_time; +- +- if (diff_read_ops != 0) +- ds->avg_read_time += disk_calc_time_incr ( +- diff_read_time, diff_read_ops); +- if (diff_write_ops != 0) +- ds->avg_write_time += disk_calc_time_incr ( +- diff_write_time, diff_write_ops); +- +- ds->read_ops = read_ops; +- ds->read_time = read_time; +- ds->write_ops = write_ops; +- ds->write_time = write_time; +- } /* if (is_disk) */ +- +- /* Don't write to the RRDs if we've just started.. */ +- ds->poll_count++; +- if (ds->poll_count <= 2) +- { +- DEBUG ("disk plugin: (ds->poll_count = %i) <= " +- "(min_poll_count = 2); => Not writing.", +- ds->poll_count); +- continue; +- } +- +- if ((read_ops == 0) && (write_ops == 0)) +- { +- DEBUG ("disk plugin: ((read_ops == 0) && " +- "(write_ops == 0)); => Not writing."); +- continue; +- } +- +- if ((ds->read_bytes != 0) || (ds->write_bytes != 0)) +- disk_submit (disk_name, "disk_octets", +- ds->read_bytes, ds->write_bytes); +- +- if ((ds->read_ops != 0) || (ds->write_ops != 0)) +- disk_submit (disk_name, "disk_ops", +- read_ops, write_ops); +- +- if ((ds->avg_read_time != 0) || (ds->avg_write_time != 0)) +- disk_submit (disk_name, "disk_time", +- ds->avg_read_time, ds->avg_write_time); +- +- if (is_disk) +- { +- disk_submit (disk_name, "disk_merged", +- read_merged, write_merged); +- } /* if (is_disk) */ +- } /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */ +- +- fclose (fh); +-/* #endif defined(KERNEL_LINUX) */ +- + #elif HAVE_LIBKSTAT + # if HAVE_KSTAT_IO_T_WRITES && HAVE_KSTAT_IO_T_NWRITES && HAVE_KSTAT_IO_T_WTIME + # define KIO_ROCTETS reads