diff options
Diffstat (limited to 'scrape.c')
-rw-r--r-- | scrape.c | 19 |
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) { |