Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to kingpin flags #639

Merged
merged 4 commits into from
Aug 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ docker run -d -p 9100:9100 \
-v "/:/rootfs:ro" \
--net="host" \
quay.io/prometheus/node-exporter \
-collector.procfs /host/proc \
-collector.sysfs /host/sys \
-collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
--collector.procfs /host/proc \
--collector.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
```

Be aware though that the mountpoint label in various metrics will now have
Expand Down
4 changes: 2 additions & 2 deletions collector/diskstats_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package collector

import (
"bufio"
"flag"
"fmt"
"io"
"os"
Expand All @@ -27,6 +26,7 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"gopkg.in/alecthomas/kingpin.v2"
)

const (
Expand All @@ -35,7 +35,7 @@ const (
)

var (
ignoredDevices = flag.String("collector.diskstats.ignored-devices", "^(ram|loop|fd|(h|s|v|xv)d[a-z]|nvme\\d+n\\d+p)\\d+$", "Regexp of devices to ignore for diskstats.")
ignoredDevices = kingpin.Flag("collector.diskstats.ignored-devices", "Regexp of devices to ignore for diskstats.").Default("^(ram|loop|fd|(h|s|v|xv)d[a-z]|nvme\\d+n\\d+p)\\d+$").String()
)

type diskstatsCollector struct {
Expand Down
15 changes: 7 additions & 8 deletions collector/filesystem_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package collector

import (
"flag"
"regexp"

"github.com/prometheus/client_golang/prometheus"
"gopkg.in/alecthomas/kingpin.v2"
)

// Arch-dependent implementation must define:
Expand All @@ -30,15 +30,14 @@ import (
// * filesystemCollector.GetStats

var (
ignoredMountPoints = flag.String(
ignoredMountPoints = kingpin.Flag(
"collector.filesystem.ignored-mount-points",
defIgnoredMountPoints,
"Regexp of mount points to ignore for filesystem collector.")

ignoredFSTypes = flag.String(
"Regexp of mount points to ignore for filesystem collector.",
).Default(defIgnoredMountPoints).String()
ignoredFSTypes = kingpin.Flag(
"collector.filesystem.ignored-fs-types",
defIgnoredFSTypes,
"Regexp of filesystem types to ignore for filesystem collector.")
"Regexp of filesystem types to ignore for filesystem collector.",
).Default(defIgnoredFSTypes).String()

filesystemLabelNames = []string{"device", "mountpoint", "fstype"}
)
Expand Down
6 changes: 3 additions & 3 deletions collector/ipvs_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package collector

import (
"flag"
"fmt"
"io/ioutil"
"net/http"
Expand All @@ -24,10 +23,11 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"gopkg.in/alecthomas/kingpin.v2"
)

func TestIPVSCollector(t *testing.T) {
if err := flag.Set("collector.procfs", "fixtures/proc"); err != nil {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.procfs", "fixtures/proc"}); err != nil {
t.Fatal(err)
}
collector, err := newIPVSCollector()
Expand Down Expand Up @@ -76,7 +76,7 @@ func (c miniCollector) Describe(ch chan<- *prometheus.Desc) {
}

func TestIPVSCollectorResponse(t *testing.T) {
if err := flag.Set("collector.procfs", "fixtures/proc"); err != nil {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.procfs", "fixtures/proc"}); err != nil {
t.Fatal(err)
}
collector, err := NewIPVSCollector()
Expand Down
4 changes: 2 additions & 2 deletions collector/megacli.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package collector

import (
"bufio"
"flag"
"io"
"os/exec"
"strconv"
"strings"

"github.com/prometheus/client_golang/prometheus"
"gopkg.in/alecthomas/kingpin.v2"
)

const (
Expand All @@ -32,7 +32,7 @@ const (
)

var (
megacliCommand = flag.String("collector.megacli.command", defaultMegaCli, "Command to run megacli.")
megacliCommand = kingpin.Flag("collector.megacli.command", "Command to run megacli.").Default(defaultMegaCli).String()
)

type megaCliCollector struct {
Expand Down
4 changes: 2 additions & 2 deletions collector/megacli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
package collector

import (
"flag"
"os"
"testing"

"github.com/prometheus/client_golang/prometheus"
"gopkg.in/alecthomas/kingpin.v2"
)

const (
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestMegaCliDisks(t *testing.T) {
}

func TestMegaCliCollectorDoesntCrash(t *testing.T) {
if err := flag.Set("collector.megacli.command", "./fixtures/megacli"); err != nil {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.megacli.command", "./fixtures/megacli"}); err != nil {
t.Fatal(err)
}
collector, err := NewMegaCliCollector()
Expand Down
6 changes: 2 additions & 4 deletions collector/netdev_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@
package collector

import (
"flag"
"fmt"
"regexp"
"strconv"

"github.com/prometheus/client_golang/prometheus"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
netdevIgnoredDevices = flag.String(
"collector.netdev.ignored-devices", "^$",
"Regexp of net devices to ignore for netdev collector.")
netdevIgnoredDevices = kingpin.Flag("collector.netdev.ignored-devices", "Regexp of net devices to ignore for netdev collector.").Default("^$").String()
)

type netDevCollector struct {
Expand Down
6 changes: 3 additions & 3 deletions collector/ntp.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
package collector

import (
"flag"
"fmt"

"github.com/beevik/ntp"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
ntpServer = flag.String("collector.ntp.server", "", "NTP server to use for ntp collector.")
ntpProtocolVersion = flag.Int("collector.ntp.protocol-version", 4, "NTP protocol version")
ntpServer = kingpin.Flag("collector.ntp.server", "NTP server to use for ntp collector.").Default("").String()
ntpProtocolVersion = kingpin.Flag("collector.ntp.protocol-version", "NTP protocol version").Default("4").Int()
)

type ntpCollector struct {
Expand Down
6 changes: 3 additions & 3 deletions collector/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
package collector

import (
"flag"
"path"

"github.com/prometheus/procfs"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
// The path of the proc filesystem.
procPath = flag.String("collector.procfs", procfs.DefaultMountPoint, "procfs mountpoint.")
sysPath = flag.String("collector.sysfs", "/sys", "sysfs mountpoint.")
procPath = kingpin.Flag("collector.procfs", "procfs mountpoint.").Default(procfs.DefaultMountPoint).String()
sysPath = kingpin.Flag("collector.sysfs", "sysfs mountpoint.").Default("/sys").String()
)

func procFilePath(name string) string {
Expand Down
10 changes: 5 additions & 5 deletions collector/paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
package collector

import (
"flag"
"testing"

"github.com/prometheus/procfs"
"gopkg.in/alecthomas/kingpin.v2"
)

func TestDefaultProcPath(t *testing.T) {
if err := flag.Set("collector.procfs", procfs.DefaultMountPoint); err != nil {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.procfs", procfs.DefaultMountPoint}); err != nil {
t.Fatal(err)
}

Expand All @@ -35,7 +35,7 @@ func TestDefaultProcPath(t *testing.T) {
}

func TestCustomProcPath(t *testing.T) {
if err := flag.Set("collector.procfs", "./../some/./place/"); err != nil {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.procfs", "./../some/./place/"}); err != nil {
t.Fatal(err)
}

Expand All @@ -49,7 +49,7 @@ func TestCustomProcPath(t *testing.T) {
}

func TestDefaultSysPath(t *testing.T) {
if err := flag.Set("collector.sysfs", "/sys"); err != nil {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.sysfs", "/sys"}); err != nil {
t.Fatal(err)
}

Expand All @@ -63,7 +63,7 @@ func TestDefaultSysPath(t *testing.T) {
}

func TestCustomSysPath(t *testing.T) {
if err := flag.Set("collector.sysfs", "./../some/./place/"); err != nil {
if _, err := kingpin.CommandLine.Parse([]string{"--collector.sysfs", "./../some/./place/"}); err != nil {
t.Fatal(err)
}

Expand Down
4 changes: 2 additions & 2 deletions collector/qdisc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package collector

import (
"encoding/json"
"flag"
"io/ioutil"
"path/filepath"

"github.com/ema/qdisc"
"github.com/prometheus/client_golang/prometheus"
"gopkg.in/alecthomas/kingpin.v2"
)

type qdiscStatCollector struct {
Expand All @@ -34,7 +34,7 @@ type qdiscStatCollector struct {
}

var (
collectorQdisc = flag.String("collector.qdisc", "", "test fixtures to use for qdisc collector end-to-end testing")
collectorQdisc = kingpin.Flag("collector.qdisc", "test fixtures to use for qdisc collector end-to-end testing").Default("").String()
)

func init() {
Expand Down
8 changes: 2 additions & 6 deletions collector/runit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@
package collector

import (
"flag"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"github.com/soundcloud/go-runit/runit"
"gopkg.in/alecthomas/kingpin.v2"
)

var runitServiceDir = flag.String(
"collector.runit.servicedir",
"/etc/service",
"Path to runit service directory.")
var runitServiceDir = kingpin.Flag("collector.runit.servicedir", "Path to runit service directory.").Default("/etc/service").String()

type runitCollector struct {
state, stateDesired, stateNormal, stateTimestamp typedDesc
Expand Down
5 changes: 2 additions & 3 deletions collector/supervisord.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
package collector

import (
"flag"

"github.com/kolo/xmlrpc"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
supervisordURL = flag.String("collector.supervisord.url", "http://localhost:9001/RPC2", "XML RPC endpoint")
supervisordURL = kingpin.Flag("collector.supervisord.url", "XML RPC endpoint.").Default("http://localhost:9001/RPC2").String()
)

type supervisordCollector struct {
Expand Down
15 changes: 4 additions & 11 deletions collector/systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
package collector

import (
"flag"
"fmt"
"regexp"

"github.com/coreos/go-systemd/dbus"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
unitWhitelist = flag.String("collector.systemd.unit-whitelist", ".+", "Regexp of systemd units to whitelist. Units must both match whitelist and not match blacklist to be included.")
unitBlacklist = flag.String("collector.systemd.unit-blacklist", ".+\\.scope", "Regexp of systemd units to blacklist. Units must both match whitelist and not match blacklist to be included.")
unitWhitelist = kingpin.Flag("collector.systemd.unit-whitelist", "Regexp of systemd units to whitelist. Units must both match whitelist and not match blacklist to be included.").Default(".+").String()
unitBlacklist = kingpin.Flag("collector.systemd.unit-blacklist", "Regexp of systemd units to blacklist. Units must both match whitelist and not match blacklist to be included.").Default(".+\\.scope").String()
systemdPrivate = kingpin.Flag("collector.systemd.private", "Establish a private, direct connection to systemd without dbus.").Bool()
)

type systemdCollector struct {
Expand All @@ -39,14 +40,6 @@ type systemdCollector struct {

var unitStatesName = []string{"active", "activating", "deactivating", "inactive", "failed"}

var (
systemdPrivate = flag.Bool(
"collector.systemd.private",
false,
"Establish a private, direct connection to systemd without dbus.",
)
)

func init() {
Factories["systemd"] = NewSystemdCollector
}
Expand Down
4 changes: 2 additions & 2 deletions collector/textfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package collector

import (
"flag"
"fmt"
"io/ioutil"
"os"
Expand All @@ -30,10 +29,11 @@ import (
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
"github.com/prometheus/common/log"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
textFileDirectory = flag.String("collector.textfile.directory", "", "Directory to read text files with metrics from.")
textFileDirectory = kingpin.Flag("collector.textfile.directory", "Directory to read text files with metrics from.").Default("").String()
)

type textFileCollector struct {
Expand Down
6 changes: 4 additions & 2 deletions collector/textfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
package collector

import (
"flag"
"io/ioutil"
"sort"
"strings"
"testing"

"github.com/golang/protobuf/proto"
"github.com/prometheus/common/log"
"gopkg.in/alecthomas/kingpin.v2"
)

func TestParseTextFiles(t *testing.T) {
Expand Down Expand Up @@ -49,7 +50,8 @@ func TestParseTextFiles(t *testing.T) {

// Suppress a log message about `nonexistent_path` not existing, this is
// expected and clutters the test output.
err := flag.Set("log.level", "fatal")
log.AddFlags(kingpin.CommandLine)
_, err := kingpin.CommandLine.Parse([]string{"--log.level", "fatal"})
if err != nil {
t.Fatal(err)
}
Expand Down
Loading