Prometheus Exporter Collector for TCollector

91 views
Skip to first unread message

Jonathan Creasy

unread,
Oct 15, 2020, 3:38:30 PM10/15/20
to OpenTSDB
If anyone has any service running which exposes Prometheus exporter pages please consider pointing this new collector at them and gathering some metrics. I would be particularly interested in seeing some of the metrics generated and also identifying any invalid lines sent. 


~Jonathan

Elias Abacioglu

unread,
Nov 20, 2020, 9:48:56 AM11/20/20
to OpenTSDB
Hi,

I have also written a collector for Prometheus endpoints which I tried not to over-engineer.
Mine is quite simple and lightweight, the only requirements are bash, curl and gawk.
Sure starting curl and gawk every 10 seconds might be more costly than a long-running Python process. So the collector and requirements are lightweight, not the execution :-)
However with that said, I don't feel that starting curl and gawk every 10 seconds does any negative performance impact.

Sorry for not publishing it before. But a year ago it seemed like that the TCollector project was stale and having open PR's that were stale since years ago..

```
#!/bin/bash
# metric collector that scrapes prometheus /metric endpoints
set -e
set -o pipefail

SLEEP=10
URL=http://localhost:8000/metrics
METRIC=haproxy

get_metrics () {
  # sleep an additional 60 seconds to give the curl a second chance before exit 13
  curl -s ${URL} || sleep 60 && curl -s ${URL} || exit 13
}

print_metrics () {
  get_metrics | gawk "/^${METRIC}/ {gsub(/,/, \" \"); gsub(/\"/, \"\"); gsub(/\{/, \" \"); gsub(/\}/, \"\"); a = \$1; b = \$NF; \$1=\$NF=\"\"; print a, systime(), b \$0}"
}

while :;do print_metrics; sleep ${SLEEP}; done
```

Simply change the METRIC and URL variables to whatever application you want to collect metrics for. Been running it for a year without any issues.
I have not written a etc/ config for this, I simply copy the script and adjust the METRIC and URL variables for each application I want to scrape Prometheus metrics from.

Do you want me to make a PR? This collector could replace the old HAProxy collector (which it already has in my environment) or it could be as an example as a generic Prometheus collector.

/Elias

Jonathan Creasy

unread,
Nov 20, 2020, 4:44:28 PM11/20/20
to Elias Abacioglu, OpenTSDB
Yeah, I would be happy to include your collector as well. Different tools fit better into different environments.

--
You received this message because you are subscribed to the Google Groups "OpenTSDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opentsdb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/opentsdb/3985dd08-77af-4287-97f6-85f8e10bf81en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages