This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
forked from monitoring-tools/prom-puppet-agent-exporter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
summary_report.go
58 lines (48 loc) · 1.48 KB
/
summary_report.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
52
53
54
55
56
57
58
package main
import (
"github.com/prometheus/client_golang/prometheus"
)
// NewSummaryReportScraper creates new scraper for puppet agent summary report file
func NewSummaryReportScraper(namespace, reportFilename, disableLockFilename string) PuppetYamlReportScraper {
return &summaryReportScraper{
newPuppetReportScraper(namespace, reportFilename, disableLockFilename),
}
}
type summaryReportScraper struct {
*reportScraper
}
func (r *summaryReportScraper) CollectMetrics(ch chan<- prometheus.Metric) error {
return r.collectMetrics(ch, r)
}
func (r *summaryReportScraper) UnmarshalYAML(unmarshal func(interface{}) error) error {
var v struct {
Version struct {
Puppet string
Config string
}
Application struct {
RunMode string `yaml:"run_mode"`
InitialEnvironment string `yaml:"initial_environment"`
ConvergedEnvironment string `yaml:"converged_environment"`
}
Time struct {
LastRun float64 `yaml:"last_run"`
}
}
if err := unmarshal(&v); err != nil {
return err
}
r.reportScraper.setPuppetVersion(v.Version.Puppet)
r.reportScraper.setConfigTimestamp(v.Time.LastRun)
r.setCatalogVersion(v.Version.Config)
r.setInfo("environment", v.Application.ConvergedEnvironment)
var objmap map[string]gaugeValueMap
unmarshal(&objmap)
delete(objmap, "version")
for sectionName, reportSection := range objmap {
for metricName, metricValue := range reportSection {
r.reportScraper.setMetricValue(sectionName, metricName, metricValue)
}
}
return nil
}