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>
(cherry picked from commit 4927b53333
)
This commit is contained in:
parent
b90c67c8f1
commit
646f8dd14e
1 changed files with 66 additions and 0 deletions
|
@ -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…
Reference in a new issue