Skip to content

Commit

Permalink
feat: add new custom metric ipa_replication
Browse files Browse the repository at this point in the history
  • Loading branch information
lconsuegra committed Dec 5, 2023
1 parent d2cc7ce commit fa92633
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions ipahealthcheck_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ var (
[]string{"ipahealthcheck", "result"}, nil,
)

ipahealthcheckReplicationDesc = prometheus.NewDesc(
"ipa_replication",
"Replication heatlh (1: success, 0: error)",
[]string{"ipahealthcheck", "result", "message"}, nil,
)

ipahealthcheckCertExpirationDesc = prometheus.NewDesc(
"ipa_cert_expiration",
"Expiration date of the certificates in warning or error state (unix timestamp)",
Expand All @@ -59,10 +65,6 @@ var (
scrape: true,
metricsDesc: ipahealthcheckReplicationCheckDesc,
},
"ReplicationCheck": {
scrape: true,
metricsDesc: ipahealthcheckReplicationCheckDesc,
},
"DogtagCertsConnectivityCheck": {
scrape: true,
metricsDesc: ipahealthcheckDogtagCheckDesc,
Expand Down Expand Up @@ -101,6 +103,7 @@ func (ic ipahealthcheckCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- ipahealthcheckServiceStateDesc
ch <- ipahealthcheckDogtagCheckDesc
ch <- ipahealthcheckReplicationCheckDesc
ch <- ipahealthcheckReplicationDesc
ch <- ipahealthcheckCertExpirationDesc
}

Expand Down Expand Up @@ -167,7 +170,7 @@ func (ic ipahealthcheckCollector) Collect(ch chan<- prometheus.Metric) {
if scrapedChecks[check.Check].scrape {

if verbose {
log.Infof("scrape=true -> add metric : %v", check)
log.Infof("scraped check -> add metric : %v", check.Check)
}

if check.Result == "SUCCESS" {
Expand All @@ -177,8 +180,28 @@ func (ic ipahealthcheckCollector) Collect(ch chan<- prometheus.Metric) {
}
}

if check.Check == "ReplicationCheck" {
message := "nil"

if verbose {
log.Infof("custom check -> add metric : %v", check.Check)
}

if check.Kw["msg"] != nil {
if verbose {
log.Infof("msg detected in check -> add to the metric as label : %v", check.Kw["msg"])
}
message = check.Kw["msg"].(string)
}
ch <- prometheus.MustNewConstMetric(ipahealthcheckReplicationDesc, prometheus.GaugeValue, 0.0, check.Check, strings.ToLower(check.Result), message)
}

if check.Source == "ipahealthcheck.ipa.certs" && check.Check == "IPACertmongerExpirationCheck" {

if verbose {
log.Infof("custom check -> add metric : %v", check.Check)
}

if check.Result == "WARNING" || check.Result == "ERROR" {

timestamp, err := time.Parse("20060102150405Z", check.Kw["expiration_date"].(string))
Expand Down

0 comments on commit fa92633

Please sign in to comment.