diff --git a/cmd/server.go b/cmd/server.go index 9a945d7..59b80ed 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -14,6 +14,7 @@ package cmd import ( + "context" "fmt" "github.com/hipages/php-fpm_exporter/phpfpm" "github.com/prometheus/client_golang/prometheus" @@ -21,15 +22,15 @@ import ( "github.com/spf13/cobra" "net/http" "os" + "os/signal" + "time" ) // Configuration variables var ( - listeningAddress string - metricsEndpoint string - scrapeURIs []string - customLabelNames []string - customLabelValues []string + listeningAddress string + metricsEndpoint string + scrapeURIs []string ) // serverCmd represents the server command @@ -54,17 +55,52 @@ to quickly create a Cobra application.`, exporter := phpfpm.NewExporter(pm) prometheus.MustRegister(exporter) + srv := &http.Server{ + Addr: listeningAddress, + // Good practice to set timeouts to avoid Slowloris attacks. + WriteTimeout: time.Second * 15, + ReadTimeout: time.Second * 15, + IdleTimeout: time.Second * 60, + } + http.Handle(metricsEndpoint, promhttp.Handler()) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(` -