Skip to content

Commit

Permalink
Changes for exporting redis only metrics if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
nipuntalukdar committed Oct 23, 2017
1 parent de202b0 commit d8b6fa9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cloudfoundry-community/go-cfenv"
"github.com/oliver006/redis_exporter/exporter"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)

Expand All @@ -28,6 +29,7 @@ var (
logFormat = flag.String("log-format", "txt", "Log format, valid options are txt and json")
showVersion = flag.Bool("version", false, "Show version information and exit")
useCfBindings = flag.Bool("use-cf-bindings", false, "Use Cloud Foundry service bindings")
redisOnly = flag.Bool("redis-only-metrics", false, "Whether to export go runtime metrics also")
addrs []string
passwords []string
aliases []string
Expand Down Expand Up @@ -86,16 +88,25 @@ func main() {
if err != nil {
log.Fatal(err)
}
prometheus.MustRegister(exp)

buildInfo := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "redis_exporter_build_info",
Help: "redis exporter build_info",
}, []string{"version", "commit_sha", "build_date", "golang_version"})
prometheus.MustRegister(buildInfo)
buildInfo.WithLabelValues(VERSION, COMMIT_SHA1, BUILD_DATE, runtime.Version()).Set(1)

http.Handle(*metricPath, prometheus.Handler())
if !*redisOnly {
prometheus.MustRegister(exp)
prometheus.MustRegister(buildInfo)
http.Handle(*metricPath, prometheus.Handler())
} else {
registry := prometheus.NewRegistry()
registry.Register(exp)
registry.Register(buildInfo)
handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
http.Handle(*metricPath, handler)
}

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
<html>
Expand Down

0 comments on commit d8b6fa9

Please sign in to comment.