Prometheus exporter framework
Lets you create a powerful exporter in two minutes.
This framework is extracted from node_exporter
. You can use all the features of node_exporter
with this framework:
- Enable & Disable collectors
- Include & Exclude flags
- Filtering enabled collectors
- Useful metrics
collector_duration_seconds
andcollector_success
- ...
There is an example in _example
.
Creating your exporter is very easy:
- Create some collectors implement
github.com/rea1shane/exporter/collector.Collector
and callgithub.com/rea1shane/exporter/collector.RegisterCollector
in theirinit
function. - Call the
github.com/rea1shane/exporter.Run
function to start the exporter.
Now, everything is done!
- Same as
node_exporter
, the framework useslog/slog
as the logger andgithub.com/alecthomas/kingpin/v2
as the command line argument parser. github.com/rea1shane/exporter/collector.ErrNoData
indicates the collector found no data to collect, but had no other error. If necessary, return it in thegithub.com/rea1shane/exporter/collector.Collector
'sUpdate
method.github.com/rea1shane/exporter/metric.TypedDesc
makes easier to create metrics.- If you are not using
github.com/rea1shane/exporter/metric.TypedDesc
to create metrics, you can usegithub.com/rea1shane/exporter/util.AnyToFloat64
function to convert the data tofloat64
.
Add _ "net/http/pprof"
to imports to enable PProf statistics:
package main
import (
_ "net/http/pprof"
)
See prometheus/exporter-toolkit#196 for more information.
You can using Prometheus's Makefile.common
file to building or running an exporter that uses this framework just like node_exporter
. All you need is:
- Copy prometheus/node_exporter/Makefile.common to your repository root path.
- Create
.promu.yml
like prometheus/node_exporter/.promu.yml. - Create
Makefile
like prometheus/node_exporter/Makefile. - Create
VERSION
like prometheus/node_exporter/VERSION.
Now your repository will looks like this:
your_exporter
├── .promu.yml
├── Makefile.common
├── Makefile
├── VERSION
└── ...
Then you can execute everything that has been defined in Makefile.common
. Some examples:
- Run
- Local build
- Building with Docker (Note: You need a
Dockerfile
like this)
If you want to build in a simple way, see example's Makefile. (Note: Also need a VERSION
file and may missing tags
info)