-
Notifications
You must be signed in to change notification settings - Fork 37
/
system.go
51 lines (47 loc) · 1.75 KB
/
system.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package collector
import (
"strings"
"time"
"github.com/go-kit/kit/log/level"
"github.com/peimanja/artifactory_exporter/artifactory"
"github.com/prometheus/client_golang/prometheus"
)
func (e *Exporter) exportSystem(license artifactory.LicenseInfo, ch chan<- prometheus.Metric) error {
health, err := e.client.FetchHealth()
if err != nil {
level.Error(e.logger).Log("msg", "Couldn't scrape Artifactory when fetching system/ping", "err", err)
e.totalAPIErrors.Inc()
return err
}
buildInfo, err := e.client.FetchBuildInfo()
if err != nil {
level.Error(e.logger).Log("msg", "Couldn't scrape Artifactory when fetching system/version", "err", err)
e.totalAPIErrors.Inc()
return err
}
licenseType := strings.ToLower(license.Type)
for metricName, metric := range systemMetrics {
switch metricName {
case "healthy":
ch <- prometheus.MustNewConstMetric(metric, prometheus.GaugeValue, b2f(health.Healthy), health.NodeId)
case "version":
ch <- prometheus.MustNewConstMetric(metric, prometheus.GaugeValue, 1, buildInfo.Version, buildInfo.Revision, buildInfo.NodeId)
case "license":
var validThrough float64
timeNow := float64(time.Now().Unix())
switch licenseType {
case "oss", "jcr edition", "community edition for c/c++":
validThrough = timeNow
default:
if validThroughTime, err := time.Parse("Jan 2, 2006", license.ValidThrough); err != nil {
level.Warn(e.logger).Log("msg", "Couldn't parse Artifactory license ValidThrough", "err", err)
validThrough = timeNow
} else {
validThrough = float64(validThroughTime.Unix())
}
}
ch <- prometheus.MustNewConstMetric(metric, prometheus.GaugeValue, validThrough-timeNow, licenseType, license.LicensedTo, license.ValidThrough, license.NodeId)
}
}
return nil
}