diff --git a/README.md b/README.md index 91efd89..82aa96c 100644 --- a/README.md +++ b/README.md @@ -375,3 +375,43 @@ Requires Go 1.13 installed. ``` make ``` + +## Exposing metrics through HTTPS + +web-config.yml +``` +# Minimal TLS configuration example. Additionally, a certificate and a key file +# are needed. +tls_server_config: + cert_file: server.crt + key_file: server.key +``` +Running +``` +$ ./process-exporter -web.config.file web-config.yml & +$ curl -sk https://localhost:9256/metrics | grep process + +# HELP namedprocess_scrape_errors general scrape errors: no proc metrics collected during a cycle +# TYPE namedprocess_scrape_errors counter +namedprocess_scrape_errors 0 +# HELP namedprocess_scrape_partial_errors incremented each time a tracked proc's metrics collection fails partially, e.g. unreadable I/O stats +# TYPE namedprocess_scrape_partial_errors counter +namedprocess_scrape_partial_errors 0 +# HELP namedprocess_scrape_procread_errors incremented each time a proc's metrics collection fails +# TYPE namedprocess_scrape_procread_errors counter +namedprocess_scrape_procread_errors 0 +# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds. +# TYPE process_cpu_seconds_total counter +process_cpu_seconds_total 0.21 +# HELP process_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which process_exporter was built. +# TYPE process_exporter_build_info gauge +process_exporter_build_info{branch="",goversion="go1.17.3",revision="",version=""} 1 +# HELP process_max_fds Maximum number of open file descriptors. +# TYPE process_max_fds gauge +process_max_fds 1.048576e+06 +# HELP process_open_fds Number of open file descriptors. +# TYPE process_open_fds gauge +process_open_fds 10 +``` + +For further information about TLS configuration, please visit: [exporter-toolkit](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md) \ No newline at end of file diff --git a/cmd/process-exporter/main.go b/cmd/process-exporter/main.go index 3b80cb3..29c3c25 100644 --- a/cmd/process-exporter/main.go +++ b/cmd/process-exporter/main.go @@ -17,7 +17,9 @@ import ( "github.com/ncabatoff/process-exporter/config" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/prometheus/common/promlog" promVersion "github.com/prometheus/common/version" + "github.com/prometheus/exporter-toolkit/web" ) // Version is set at build time use ldflags. @@ -166,6 +168,8 @@ func main() { "print manual") configPath = flag.String("config.path", "", "path to YAML config file") + tlsConfigFile = flag.String("web.config.file", "", + "path to YAML web config file") recheck = flag.Bool("recheck", false, "recheck process names on each scrape") debug = flag.Bool("debug", false, @@ -175,6 +179,9 @@ func main() { ) flag.Parse() + promlogConfig := &promlog.Config{} + logger := promlog.New(promlogConfig) + if *showVersion { fmt.Printf("%s\n", promVersion.Print("process-exporter")) os.Exit(0) @@ -263,7 +270,9 @@ func main() { `)) }) - if err := http.ListenAndServe(*listenAddress, nil); err != nil { - log.Fatalf("Unable to setup HTTP server: %v", err) + server := &http.Server{Addr: *listenAddress} + if err := web.ListenAndServe(server, *tlsConfigFile, logger); err != nil { + log.Fatalf("Failed to start the server: %v", err) + os.Exit(1) } }