diff options
author | Heikki Kallasjoki <fis@zem.fi> | 2018-08-05 23:50:20 +0100 |
---|---|---|
committer | Heikki Kallasjoki <fis@zem.fi> | 2018-08-05 23:50:20 +0100 |
commit | c73aca3d51a9ce915b089d92ea9a43ec49ef63f0 (patch) | |
tree | 4a75083b7470679ad7aed217749a457bbf259996 /uname.c | |
download | nano-exporter-c73aca3d51a9ce915b089d92ea9a43ec49ef63f0.tar.gz nano-exporter-c73aca3d51a9ce915b089d92ea9a43ec49ef63f0.tar.xz nano-exporter-c73aca3d51a9ce915b089d92ea9a43ec49ef63f0.zip |
Initial prototype.
Diffstat (limited to 'uname.c')
-rw-r--r-- | uname.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/uname.c b/uname.c new file mode 100644 index 0000000..6d71764 --- /dev/null +++ b/uname.c @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <stdlib.h> +#include <sys/utsname.h> + +#include "uname.h" +#include "util.h" + +static void *uname_init(int argc, char *argv[]); +static void uname_collect(scrape_req *req, void *ctx); + +const struct collector uname_collector = { + .name = "uname", + .collect = uname_collect, + .init = uname_init, +}; + +enum { + label_machine, + label_nodename, + label_release, + label_sysname, + label_version, + max_label, +}; + +struct uname_context { + const char *labels[max_label + 1][2]; +}; + +static void *uname_init(int argc, char *argv[]) { + struct utsname name; + if (uname(&name) == -1) { + perror("uname"); + return 0; + } + + struct uname_context *ctx = must_malloc(sizeof *ctx); + ctx->labels[label_machine][0] = "machine"; + ctx->labels[label_machine][1] = must_strdup(name.machine); + ctx->labels[label_nodename][0] = "nodename"; + ctx->labels[label_nodename][1] = must_strdup(name.nodename); + ctx->labels[label_release][0] = "release"; + ctx->labels[label_release][1] = must_strdup(name.release); + ctx->labels[label_sysname][0] = "sysname"; + ctx->labels[label_sysname][1] = must_strdup(name.sysname); + ctx->labels[label_version][0] = "version"; + ctx->labels[label_version][1] = must_strdup(name.version); + ctx->labels[max_label][0] = ctx->labels[max_label][1] = 0; + return ctx; +} + +static void uname_collect(scrape_req *req, void *ctx_ptr) { + struct uname_context *ctx = ctx_ptr; + scrape_write(req, "node_uname_info", ctx->labels, 1.0); +} |