From 45a23445d365cb7f1db9e3e6d55666f759e1fc99 Mon Sep 17 00:00:00 2001 From: omgbebebe Date: Wed, 16 Sep 2020 22:34:36 +0400 Subject: [PATCH] expose failed parsing attempts as a metric (#41) * expose failed parsing attempts as a metric Signed-off-by: Sergey Bubnov * add hostname label to the expiry_failed metric Co-authored-by: Sergey Bubnov --- pkg/exporter/exporter.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/exporter/exporter.go b/pkg/exporter/exporter.go index 27733ae..bb43436 100644 --- a/pkg/exporter/exporter.go +++ b/pkg/exporter/exporter.go @@ -71,6 +71,7 @@ type Exporter struct { roots []string exRoots []string certExpiry *prometheus.GaugeVec + certFailed *prometheus.GaugeVec } // SetRoots sets the list of file paths that the exporter should search for certificates in @@ -111,16 +112,19 @@ func (e *Exporter) Scrape(ch chan<- prometheus.Metric) { data, err := ioutil.ReadFile(path) if err != nil { glog.Warningf("Couldn't read %s: %s", path, err.Error()) + ch <- e.certFailed.With(prometheus.Labels{"path": path, "hostname": hostname, "nodename": nodename}) continue } block := getFirstCertBlock(data) if len(block) == 0 { glog.Warningf("Couldn't find a CERTIFICATE block in %s", path) + ch <- e.certFailed.With(prometheus.Labels{"path": path, "hostname": hostname, "nodename": nodename}) continue } cert, err := x509.ParseCertificate(block) if err != nil { glog.Warningf("Couldn't parse %s: %s", path, err.Error()) + ch <- e.certFailed.With(prometheus.Labels{"path": path, "hostname": hostname, "nodename": nodename}) continue } @@ -154,5 +158,12 @@ func New() *Exporter { Help: "Number of seconds until certificate expires", }, []string{"path", "issuer", "alg", "version", "subject", "dns_names", "email_addresses", "hostname", "nodename"}), + certFailed: prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: "ssl_certificate", + Subsystem: "expiry", + Name: "failed", + Help: "files that were failed to process", + }, + []string{"path", "hostname", "nodename"}), } }