Skip to content

Commit

Permalink
Add TLS metrics support (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaganto authored Nov 17, 2021
1 parent b7310f0 commit 44d59f9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
13 changes: 11 additions & 2 deletions cmd/process-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -263,7 +270,9 @@ func main() {
</body>
</html>`))
})
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)
}
}

0 comments on commit 44d59f9

Please sign in to comment.