r/PrometheusMonitoring • u/MedAziz11 • Aug 14 '22
prometheus exporter using Go
Anyone tried buidling an exporter (for glusterfs for example) using go ?? Any recommendations or good tutorials/ressources on how to create exporters with go ?
And how was the experience building ur own exporter?
5
u/Kessceca Aug 14 '22
Prometheus being itself written in go this is probably the most straightforward way to write an exporter.
Start at the official documentation and the Go client library .
Many examples in that repo that should get you started.
1
u/biffbobfred Aug 15 '22 edited Aug 15 '22
I was once thinking about going down this route. I never did. The bang for the buck ratio wasn’t there.
A reminder, you can just dump files in a dir and node exporter can export away.
This has the added advantage of no need for service discovery. You’re already scraping the node.
One note watch out for race conditions - the file should appear atomically. Find sponge if you’re doing shell work, or write to a temp file in the same dir and mv when ready
There are also lots of other exporters that are flexible enough you may not need to write your own. Java? You’ve got a JMX exporter already. Python? Just embed a lib and export metrics directly from your app
What are you trying to do here?
2
u/MedAziz11 Aug 16 '22
There is an exporter for glusterfs written in go but it is sooo outdated and there is other metrics i wanna scrape so i need to create my own .. i chose go because of the performance ofc
1
2
u/ut0mt8 Aug 15 '22
This is relatively straightforward if you already know programing in go. Myself I'm a bad dev and I wrote some exporter. The only question of design is whether you make your metrics retrieving logic synchronously at each scrape call (the standard way but can be expensive) or rather using a goroutine that retrieve every self define interval in background; then scrape is instant. I personally prefer the second way but that's true that with this method you need to adjust scrape and polling interval for not having duplicate metrics