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"`)
|
||||
- `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
|
||||
[FreeIPMI](https://www.gnu.org/software/freeipmi/) suite installed:
|
||||
|
|
24
main.go
24
main.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -11,21 +10,22 @@ import (
|
|||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/prometheus/common/log"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
configFile = flag.String(
|
||||
"config.file", "ipmi.yml",
|
||||
configFile = kingpin.Flag(
|
||||
"config.file",
|
||||
"Path to configuration file.",
|
||||
)
|
||||
executablesPath = flag.String(
|
||||
"path", "",
|
||||
).Default("ipmi.yml").String()
|
||||
executablesPath = kingpin.Flag(
|
||||
"freeipmi.path",
|
||||
"Path to FreeIPMI executables (default: rely on $PATH).",
|
||||
)
|
||||
listenAddress = flag.String(
|
||||
"web.listen-address", ":9290",
|
||||
).String()
|
||||
listenAddress = kingpin.Flag(
|
||||
"web.listen-address",
|
||||
"Address to listen on for web interface and telemetry.",
|
||||
)
|
||||
).Default(":9290").String()
|
||||
|
||||
sc = &SafeConfig{
|
||||
C: &Config{},
|
||||
|
@ -64,7 +64,9 @@ func updateConfiguration(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
log.AddFlags(kingpin.CommandLine)
|
||||
kingpin.HelpFlag.Short('h')
|
||||
kingpin.Parse()
|
||||
log.Infoln("Starting ipmi_exporter")
|
||||
|
||||
// Bail early if the config is bad.
|
||||
|
|
Loading…
Reference in New Issue