Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func run(app *kingpin.Application, args []string, srv *http.Server) (exitCode in
maxProcs = app.Flag("runtime.gomaxprocs", "The target number of CPUs Go will run on (GOMAXPROCS)").Envar("GOMAXPROCS").Default("4").Int()
maxRequests = app.Flag("web.max-requests", "Maximum number of parallel scrape requests. Use 0 to disable.").Default("40").Int()
disableExporterMetrics = app.Flag("web.disable-exporter-metrics", "Exclude metrics about the exporter itself (promhttp_*, process_*, go_*).").Bool()
exposeConfig = app.Flag("web.expose-config", "Expose /config endpoint.").Bool()
toolkitFlags = kingpinflag.AddFlags(app, ":8085")
)
app.Version(version.Print("emqx-exporter"))
Expand Down Expand Up @@ -83,18 +84,20 @@ func run(app *kingpin.Application, args []string, srv *http.Server) (exitCode in
prober.Handler(w, r, probes, logger, nil)
})

mux.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) {
sc.RLock()
c, err := yaml.Marshal(sc.C)
sc.RUnlock()
if err != nil {
level.Warn(logger).Log("msg", "Error marshalling configuration", "err", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/plain")
w.Write(c)
})
if *exposeConfig {
mux.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) {
sc.RLock()
c, err := yaml.Marshal(sc.C)
sc.RUnlock()
if err != nil {
level.Warn(logger).Log("msg", "Error marshalling configuration", "err", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/plain")
w.Write(c)
})
}

landingConfig := web.LandingConfig{
Name: "EMQX Exporter",
Expand All @@ -109,12 +112,15 @@ func run(app *kingpin.Application, args []string, srv *http.Server) (exitCode in
Address: "/probe",
Text: "Probe",
},
{
Address: "/config",
Text: "Config",
},
},
}

if *exposeConfig {
landingConfig.Links = append(landingConfig.Links, web.LandingLinks{
Address: "/config",
Text: "Config",
})
}
landingPage, err := web.NewLandingPage(landingConfig)
if err != nil {
level.Error(logger).Log("err", err)
Expand Down
Loading