Unverified Commit a0a7bdde authored by Nick Groenen's avatar Nick Groenen
Browse files

Switch to kingpin for flag parsing

Prometheus is standardizing on kingping for flag parsing, as discussed
in https://github.com/prometheus/prometheus/issues/2455. Many exporters
are following this decision so most of the Prometheus ecosystem uses
kingpin.

As a consequence of this change, flags now require double dashes.
`-web.listen-address` becomes `--web.listen-address` for example.

Usage before:

```
Usage of ./dovecot_exporter:
  -dovecot.socket-path string
    	Path under which to expose metrics. (default "/var/run/dovecot/stats")
  -web.listen-address string
    	Address to listen on for web interface and telemetry. (default ":9166")
  -web.telemetry-path string
    	Path under which to expose metrics. (default "/metrics")
```

And after:

```
usage: dovecot_exporter [<flags>]

Prometheus metrics exporter for Dovecot

Flags:
  --help                        Show context-sensitive help (also try --help-long and --help-man).
  --web.listen-address=":9166"  Address to listen on for web interface and telemetry.
  --web.telemetry-path="/metrics"
                                Path under which to expose metrics.
  --dovecot.socket-path="/var/run/dovecot/stats"
                                Path under which to expose metrics.
```
parent f21fd885
......@@ -15,7 +15,6 @@ package main
import (
"bufio"
"flag"
"fmt"
"io"
"log"
......@@ -26,6 +25,7 @@ import (
"strings"
"github.com/prometheus/client_golang/prometheus"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
......@@ -62,7 +62,7 @@ func CollectFromReader(file io.Reader, ch chan<- prometheus.Metric) error {
// Read successive lines, containing the values.
for scanner.Scan() {
values := strings.Fields(scanner.Text())
if len(values) != len(columns) + 1 {
if len(values) != len(columns)+1 {
break
}
for i, value := range values[1:] {
......@@ -136,11 +136,12 @@ func (e *DovecotExporter) Collect(ch chan<- prometheus.Metric) {
func main() {
var (
listenAddress = flag.String("web.listen-address", ":9166", "Address to listen on for web interface and telemetry.")
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
socketPath = flag.String("dovecot.socket-path", "/var/run/dovecot/stats", "Path under which to expose metrics.")
app = kingpin.New("dovecot_exporter", "Prometheus metrics exporter for Dovecot")
listenAddress = app.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9166").String()
metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
socketPath = app.Flag("dovecot.socket-path", "Path under which to expose metrics.").Default("/var/run/dovecot/stats").String()
)
flag.Parse()
kingpin.MustParse(app.Parse(os.Args[1:]))
exporter := NewDovecotExporter(*socketPath)
prometheus.MustRegister(exporter)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment