Switch to kingpin command line parser
Unfortunately this is a breaking change, as this means going from `-config.file` to `--config.file` syntax, but it needs to happen eventually. It better aligns the IPMI exporter with the rest of the Prometheus eco-system. As a first benefit, expose the command line parameters that control the logging library.
This commit is contained in:
parent
b478aaf12e
commit
25e67b2f9c
|
@ -30,7 +30,11 @@ Supported parameters include:
|
||||||
|
|
||||||
- `web.listen-address`: the address/port to listen on (default: `":9290"`)
|
- `web.listen-address`: the address/port to listen on (default: `":9290"`)
|
||||||
- `config.file`: path to the configuration file (default: `ipmi.yml`)
|
- `config.file`: path to the configuration file (default: `ipmi.yml`)
|
||||||
- `path`: path to the FreeIPMI executables (default: rely on `$PATH`)
|
- `freeipmi.path`: path to the FreeIPMI executables (default: rely on `$PATH`)
|
||||||
|
|
||||||
|
For a complete list of available parameters, run:
|
||||||
|
|
||||||
|
./ipmi_exporter -h
|
||||||
|
|
||||||
Make sure you have the following tools from the
|
Make sure you have the following tools from the
|
||||||
[FreeIPMI](https://www.gnu.org/software/freeipmi/) suite installed:
|
[FreeIPMI](https://www.gnu.org/software/freeipmi/) suite installed:
|
||||||
|
|
24
main.go
24
main.go
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -11,21 +10,22 @@ import (
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"github.com/prometheus/common/log"
|
"github.com/prometheus/common/log"
|
||||||
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
configFile = flag.String(
|
configFile = kingpin.Flag(
|
||||||
"config.file", "ipmi.yml",
|
"config.file",
|
||||||
"Path to configuration file.",
|
"Path to configuration file.",
|
||||||
)
|
).Default("ipmi.yml").String()
|
||||||
executablesPath = flag.String(
|
executablesPath = kingpin.Flag(
|
||||||
"path", "",
|
"freeipmi.path",
|
||||||
"Path to FreeIPMI executables (default: rely on $PATH).",
|
"Path to FreeIPMI executables (default: rely on $PATH).",
|
||||||
)
|
).String()
|
||||||
listenAddress = flag.String(
|
listenAddress = kingpin.Flag(
|
||||||
"web.listen-address", ":9290",
|
"web.listen-address",
|
||||||
"Address to listen on for web interface and telemetry.",
|
"Address to listen on for web interface and telemetry.",
|
||||||
)
|
).Default(":9290").String()
|
||||||
|
|
||||||
sc = &SafeConfig{
|
sc = &SafeConfig{
|
||||||
C: &Config{},
|
C: &Config{},
|
||||||
|
@ -64,7 +64,9 @@ func updateConfiguration(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
log.AddFlags(kingpin.CommandLine)
|
||||||
|
kingpin.HelpFlag.Short('h')
|
||||||
|
kingpin.Parse()
|
||||||
log.Infoln("Starting ipmi_exporter")
|
log.Infoln("Starting ipmi_exporter")
|
||||||
|
|
||||||
// Bail early if the config is bad.
|
// Bail early if the config is bad.
|
||||||
|
|
Loading…
Reference in New Issue