aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Eckert <fe@dev.tdt.de>2021-03-11 16:49:50 +0100
committerFlorian Eckert <fe@dev.tdt.de>2021-03-23 10:20:27 +0100
commitb4e24c12a6c187565e63b9365df6f88d954bf8c6 (patch)
tree5507a4b9dd4a1e753fe14ab494ed60e16ca1cef4
parent4927b53333652825a73bf0ecd53914636af6b6d3 (diff)
collectd: add percent calculation of bad block to ubi plugin
This patche adds the percent evaluation for the bad blocks. Signed-off-by: Florian Eckert <fe@dev.tdt.de>
-rw-r--r--utils/collectd/patches/935-ubi-add-percent.patch56
1 files changed, 56 insertions, 0 deletions
diff --git a/utils/collectd/patches/935-ubi-add-percent.patch b/utils/collectd/patches/935-ubi-add-percent.patch
new file mode 100644
index 000000000..4736b85fc
--- /dev/null
+++ b/utils/collectd/patches/935-ubi-add-percent.patch
@@ -0,0 +1,56 @@
+--- a/src/ubi.c
++++ b/src/ubi.c
+@@ -35,6 +35,9 @@
+ #define DEV_BAD_COUNT \
+ "bad_peb_count" // Count of bad physical eraseblocks on the underlying MTD
+ // device.
++// Value reserved for bad block
++#define DEV_RESERVED_BAD_BLOCK "reserved_for_bad"
++
+ #define MAXIMUM_ERASE "max_ec" // Current maximum erase counter value
+
+ /*
+@@ -140,6 +143,35 @@ static inline int ubi_read_max_ec(const
+ return 0;
+ } /* int ubi_read_max_ec */
+
++static inline int ubi_read_percent(const char *dev_name) {
++ int ret;
++ int bcount;
++ int bblock;
++
++ ret = ubi_read_dev_attr(dev_name, DEV_BAD_COUNT, &bcount);
++
++ if (ret != 0) {
++ ERROR(PLUGIN_NAME " : Unable to read bad_peb_count");
++ return -1;
++ }
++
++ ret = ubi_read_dev_attr(dev_name, DEV_RESERVED_BAD_BLOCK, &bblock);
++
++ if (ret != 0) {
++ ERROR(PLUGIN_NAME " : Unable to read reserved_for_bad");
++ return -1;
++ }
++
++ if (bblock == 0) {
++ ERROR(PLUGIN_NAME " : Percentage value cannot be determined (reserved_for_bad = 0)");
++ return -2;
++ }
++
++ ubi_submit(dev_name, "percent", (gauge_t)((float_t)bcount / (float_t)bblock * 100.0));
++
++ return 0;
++} /* int ubi_read_percent */
++
+ static int ubi_read(void) {
+ DIR *dir;
+ struct dirent *dirent;
+@@ -155,6 +187,7 @@ static int ubi_read(void) {
+
+ ubi_read_dev_bad_count(dirent->d_name);
+ ubi_read_max_ec(dirent->d_name);
++ ubi_read_percent(dirent->d_name);
+ }
+
+ closedir(dir);