Browse Source

collectd: prepare ubi plugin for percent calculation

This patche change prepares the ubi plugin to add the bad block evaluation in
percent.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
lilik-openwrt-22.03
Florian Eckert 4 years ago
parent
commit
4927b53333
1 changed files with 66 additions and 0 deletions
  1. +66
    -0
      utils/collectd/patches/934-ubi-prepare-read-for-percent.patch

+ 66
- 0
utils/collectd/patches/934-ubi-prepare-read-for-percent.patch View File

@ -0,0 +1,66 @@
--- a/src/ubi.c
+++ b/src/ubi.c
@@ -84,9 +84,8 @@ static void ubi_submit(const char *dev_n
plugin_dispatch_values(&vl);
} /* void ubi_submit */
-static int ubi_read_dev_attr(const char *dev_name, const char *attr) {
+static int ubi_read_dev_attr(const char *dev_name, const char *attr, int *value) {
FILE *f;
- int val;
char
str[sizeof(SYS_PATH) + strlen(dev_name) + sizeof("/") + strlen(attr) + 1];
int n;
@@ -98,7 +97,7 @@ static int ubi_read_dev_attr(const char
return -1;
}
- n = fscanf(f, "%d", &val);
+ n = fscanf(f, "%d", value);
fclose(f);
if (n != 1) {
@@ -106,17 +105,39 @@ static int ubi_read_dev_attr(const char
return -1;
}
- ubi_submit(dev_name, attr, (gauge_t)val);
-
return 0;
} /* int ubi_read_dev_attr */
static inline int ubi_read_dev_bad_count(const char *dev_name) {
- return ubi_read_dev_attr(dev_name, DEV_BAD_COUNT);
+ int ret;
+ int value;
+
+ ret = ubi_read_dev_attr(dev_name, DEV_BAD_COUNT, &value);
+
+ if (ret != 0) {
+ ERROR(PLUGIN_NAME " : Unable to read bat_peb_count");
+ return -1;
+ }
+
+ ubi_submit(dev_name, DEV_BAD_COUNT, (gauge_t)value);
+
+ return 0;
} /* int ubi_read_dev_bad_count */
static inline int ubi_read_max_ec(const char *dev_name) {
- return ubi_read_dev_attr(dev_name, MAXIMUM_ERASE);
+ int ret;
+ int value;
+
+ ret = ubi_read_dev_attr(dev_name, MAXIMUM_ERASE, &value);
+
+ if (ret != 0) {
+ ERROR(PLUGIN_NAME " : Unable to read max_ec");
+ return -1;
+ }
+
+ ubi_submit(dev_name, MAXIMUM_ERASE, (gauge_t)value);
+
+ return 0;
} /* int ubi_read_max_ec */
static int ubi_read(void) {

Loading…
Cancel
Save