about summary refs log tree commit diff
path: root/cpu.c
diff options
context:
space:
mode:
authorHeikki Kallasjoki <fis@zem.fi>2018-12-07 02:12:32 +0000
committerHeikki Kallasjoki <fis+github@zem.fi>2018-12-07 02:17:55 +0000
commit7ec8aa9fcfba92019f537cd19dac4ce15674ddd6 (patch)
treeedfdfcb09dd20e54f9cd4742346c1bf8a45e60d2 /cpu.c
parent16d61af28bcd07348117fd457b62ff39c1a0b45d (diff)
downloadnano-exporter-7ec8aa9fcfba92019f537cd19dac4ce15674ddd6.tar.gz
nano-exporter-7ec8aa9fcfba92019f537cd19dac4ce15674ddd6.tar.xz
nano-exporter-7ec8aa9fcfba92019f537cd19dac4ce15674ddd6.zip
Use a struct type for metric labels.
Resolves #4.

The real readability benefits are for test code, which will follow up in due course.
Diffstat (limited to 'cpu.c')
-rw-r--r--cpu.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/cpu.c b/cpu.c
index c746c7b..d8f7886 100644
--- a/cpu.c
+++ b/cpu.c
@@ -63,19 +63,19 @@ void cpu_collect(scrape_req *req, void *ctx_ptr) {
   // buffers
 
   char cpu_label[MAX_CPU_DIGITS + 1] = "";
-  static const char *modes[] = {
+  static char *modes[] = {
     "user", "nice", "system", "idle", "iowait", "irq", "softirq", "steal",
     0,
   };
 
-  const char *stat_labels[][2] = {
-    { "cpu", cpu_label },
-    { "mode", 0 },  // filled by code
-    { 0, 0 },
+  struct label stat_labels[] = {
+    { .key = "cpu", .value = cpu_label },
+    { .key = "mode", .value = 0 },  // value filled by code
+    LABEL_END,
   };
-  const char *freq_labels[][2] = {
-    { "cpu", cpu_label },
-    { 0, 0 },
+  struct label freq_labels[] = {
+    { .key = "cpu", .value = cpu_label },
+    LABEL_END,
   };
 
   char buf[BUF_SIZE];
@@ -98,7 +98,7 @@ void cpu_collect(scrape_req *req, void *ctx_ptr) {
       strcpy(cpu_label, at);
 
       at = sep + 1;
-      for (const char **mode = modes; *mode; mode++) {
+      for (char **mode = modes; *mode; mode++) {
         while (*at == ' ')
           at++;
         sep = strpbrk(at, " \n");
@@ -112,7 +112,7 @@ void cpu_collect(scrape_req *req, void *ctx_ptr) {
           break;
         value /= ctx->clock_tick;
 
-        stat_labels[1][1] = *mode;
+        stat_labels[1].value = *mode;
         scrape_write(req, "node_cpu_seconds_total", stat_labels, value);
 
         at = sep + 1;