Skip to content

Commit

Permalink
Merge pull request #82 from ashleyprimo/master
Browse files Browse the repository at this point in the history
Add -address listen, log -level flag
  • Loading branch information
stefanotorresi authored Oct 30, 2019
2 parents a3f6392 + fb700be commit b2f09e1
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions ha_cluster_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,34 @@ func landingpage(w http.ResponseWriter, r *http.Request) {
</html>`))
}

func loglevel(opt string) {
switch opt {
case "error":
log.SetLevel(log.ErrorLevel)
case "warn":
log.SetLevel(log.WarnLevel)
case "info":
log.SetLevel(log.InfoLevel)
case "debug":
log.SetLevel(log.DebugLevel)
default:
log.Warnln("Unrecognized log level, default to `info` level")
}
}

var (
clock Clock = &SystemClock{}
portNumber = flag.String("port", "9002", "The port number to listen on for HTTP requests.")
address = flag.String("address", "0.0.0.0", "The address to listen on for HTTP requests.")
logLevel = flag.String("level", "info", "The level of logs to log")
)

func main() {
// read cli option and setup initial stat
flag.Parse()

loglevel(*logLevel)

pacemakerCollector, err := NewPacemakerCollector()
if err != nil {
log.Warnf("Could not initialize Pacemaker collector: %v\n", err)
Expand Down Expand Up @@ -112,6 +131,6 @@ func main() {

http.HandleFunc("/", landingpage)
http.Handle("/metrics", promhttp.Handler())
log.Infoln("Serving metrics on port", *portNumber)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", *portNumber), nil))
log.Infof("Serving metrics on %s:%s", *address, *portNumber)
log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%s", *address, *portNumber), nil))
}

0 comments on commit b2f09e1

Please sign in to comment.