From 9d5a71c7bab5e7273af938f974d97ef0098502fb Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Fri, 7 Jun 2024 13:13:49 +0200 Subject: add --stdout --- scrape.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'scrape.c') 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) { -- cgit 1.4.1