Skip to content

Commit

Permalink
expose failed parsing attempts as a metric (#41)
Browse files Browse the repository at this point in the history
* expose failed parsing attempts as a metric

Signed-off-by: Sergey Bubnov <[email protected]>

* add hostname label to the expiry_failed metric

Co-authored-by: Sergey Bubnov <[email protected]>
  • Loading branch information
omgbebebe and Sergey Bubnov authored Sep 16, 2020
1 parent 437ae63 commit 45a2344
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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"}),
}
}

0 comments on commit 45a2344

Please sign in to comment.