about summary refs log tree commit diff
path: root/scrape.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2024-06-07 13:13:49 +0200
committerLeah Neukirchen <leah@vuxu.org>2024-06-07 13:13:49 +0200
commit9d5a71c7bab5e7273af938f974d97ef0098502fb (patch)
treee83a1e147486040ad4fce08a1ff2c667b97450e2 /scrape.c
parentbdfbcbc2a9b44040fa1cccabe7ea275a5a15ebfb (diff)
downloadnano-exporter-9d5a71c7bab5e7273af938f974d97ef0098502fb.tar.gz
nano-exporter-9d5a71c7bab5e7273af938f974d97ef0098502fb.tar.xz
nano-exporter-9d5a71c7bab5e7273af938f974d97ef0098502fb.zip
add --stdout
Diffstat (limited to 'scrape.c')
-rw-r--r--scrape.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/scrape.c b/scrape.c
index 68f8c80..f68f9b9 100644
--- a/scrape.c
+++ b/scrape.c
@@ -218,6 +218,25 @@ void scrape_close(scrape_server *srv) {
   free(srv);
 }
 
+void scrape_print(unsigned ncoll, const struct collector *coll[], void *coll_ctx[]) {
+  bbuf *buf = bbuf_alloc(BUF_INITIAL, BUF_MAX);
+  for (unsigned i = 0; i < ncoll; i++) {
+    bbuf_reset(buf);
+
+    struct scrape_req req = {
+      .state = req_state_write_metrics,
+      .buf = buf,
+    };
+    coll[i]->collect(&req, coll_ctx[i]);
+
+    size_t len;
+    char *data = bbuf_get(buf, &len);
+    write_all(1, data, len);
+  }
+
+  bbuf_free(buf);
+}
+
 // scrape write API implementation
 
 void scrape_write(scrape_req *req, const char *metric, const struct label *labels, double value) {