diff --git a/README.md b/README.md index cf77b3e..bbd9dfe 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,9 @@ As it is not uncommon to run multiple instances of OpenVPN on a single system (e.g., multiple servers, multiple clients or a mixture of both), this exporter can be configured to scrape and export the status of multiple status files, using the `-openvpn.status_paths` command line -flag. Paths need to be comma separated. Metrics for all status files are -exported over TCP port 9176. +flag. Paths or [globs](https://en.wikipedia.org/wiki/Glob_(programming)) +need to be comma separated. Metrics for all status files are exported +over TCP port 9176. Please refer to this utility's `main()` function for a full list of supported command line flags. diff --git a/exporters/openvpn_exporter.go b/exporters/openvpn_exporter.go index b658898..331075f 100644 --- a/exporters/openvpn_exporter.go +++ b/exporters/openvpn_exporter.go @@ -7,6 +7,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "io" "log" + "path/filepath" "os" "strconv" "strings" @@ -343,21 +344,28 @@ func (e *OpenVPNExporter) Describe(ch chan<- *prometheus.Desc) { } func (e *OpenVPNExporter) Collect(ch chan<- prometheus.Metric) { - for _, statusPath := range e.statusPaths { - err := e.collectStatusFromFile(statusPath, ch) - if err == nil { - ch <- prometheus.MustNewConstMetric( - e.openvpnUpDesc, - prometheus.GaugeValue, - 1.0, - statusPath) - } else { - log.Printf("Failed to scrape showq socket: %s", err) - ch <- prometheus.MustNewConstMetric( - e.openvpnUpDesc, - prometheus.GaugeValue, - 0.0, - statusPath) + for _, statusPathGlob := range e.statusPaths { + matches, err := filepath.Glob(statusPathGlob) + if err != nil { + log.Printf("Glob failed on %v: %v", statusPathGlob, err) + continue + } + for _, statusPath := range matches { + err := e.collectStatusFromFile(statusPath, ch) + if err == nil { + ch <- prometheus.MustNewConstMetric( + e.openvpnUpDesc, + prometheus.GaugeValue, + 1.0, + statusPath) + } else { + log.Printf("Failed to scrape showq socket: %s", err) + ch <- prometheus.MustNewConstMetric( + e.openvpnUpDesc, + prometheus.GaugeValue, + 0.0, + statusPath) + } } } }