Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for not to export go runtime and http handler metrcis #20

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

var (
Expand Down Expand Up @@ -43,6 +44,7 @@ type startParams struct {
NoExit bool
Test bool
Raw bool
Nogo bool
}

type varnishstatParams struct {
Expand Down Expand Up @@ -84,6 +86,7 @@ func init() {
flag.BoolVar(&StartParams.Verbose, "verbose", StartParams.Verbose, "Verbose logging.")
flag.BoolVar(&StartParams.Test, "test", StartParams.Test, "Test varnishstat availability, prints available metrics and exits.")
flag.BoolVar(&StartParams.Raw, "raw", StartParams.Test, "Raw stdout logging without timestamps.")
flag.BoolVar(&StartParams.Nogo, "no-go-metrics", StartParams.Nogo, "Don't export go runtime and http handler metrics")

flag.Parse()

Expand Down Expand Up @@ -158,7 +161,14 @@ func main() {
// Start serving
logInfo("Server starting on %s with metrics path %s", StartParams.ListenAddress, StartParams.Path)

prometheus.MustRegister(PrometheusExporter)
if StartParams.Nogo {
registry := prometheus.NewRegistry()
registry.Register(PrometheusExporter)
handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
http.Handle(StartParams.Path, handler)
} else {
prometheus.MustRegister(PrometheusExporter)
}

if StartParams.Path != "/" {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
Expand Down