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