Skip to content

Commit

Permalink
Make log level configurable via command-line flag
Browse files Browse the repository at this point in the history
As per other exporters in the Prometheus ecosystem, make log level
configurable by leveraging the promlogflag package.

Also a small tweak to Client.Get() to identify specific stats endpoint
that returns non-200 HTTP status.

Signed-off-by: Daniel Swarbrick <[email protected]>
  • Loading branch information
dswarbrick committed Aug 22, 2023
1 parent b9e01ef commit 31db02b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *XMLClient) Get(p string, v interface{}) error {
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("unexpected status %s", resp.Status)
return fmt.Errorf("unexpected status for %q: %s", u, resp.Status)
}

if err := xml.NewDecoder(resp.Body).Decode(v); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion bind_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus-community/bind_exporter/bind"
"github.com/prometheus-community/bind_exporter/bind/auto"
Expand All @@ -35,6 +36,7 @@ import (
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/prometheus/common/version"
"github.com/prometheus/exporter-toolkit/web"
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
Expand All @@ -47,7 +49,7 @@ const (
)

var (
logger = promlog.New(&promlog.Config{})
logger log.Logger

up = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "up"),
Expand Down Expand Up @@ -551,9 +553,12 @@ func main() {
bind.ServerStats, bind.ViewStats, bind.TaskStats,
}).String()).SetValue(&groups)

promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.Version(version.Print(exporter))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
logger = promlog.New(promlogConfig)

level.Info(logger).Log("msg", "Starting bind_exporter", "version", version.Info())
level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext())
Expand Down

0 comments on commit 31db02b

Please sign in to comment.