forked from SUSE/saptune_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta_collector.go
48 lines (39 loc) · 1.32 KB
/
meta_collector.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
package main
import (
"strconv"
"github.com/SUSE/saptune/txtparser"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
const subsystem_meta = "meta"
// MetaCollector is the saptune collector for general infos
type MetaCollector struct {
DefaultCollector
saptuneSysConf string
}
// NewMetaCollector creates a new solution saptune collector
func NewMetaCollector(saptuneSysConf string) (*MetaCollector, error) {
c := &MetaCollector{
NewDefaultCollector(subsystem_meta),
saptuneSysConf,
}
// this metric are set by setSolutionEnabledMetric
c.SetDescriptor("version", "Show version of saptune", nil)
return c, nil
}
// Collect various metrics for saptune solution
func (c *MetaCollector) Collect(ch chan<- prometheus.Metric) {
log.Debugln("Collecting saptune solution metrics...")
c.setSaptuneVersionMetric(ch)
}
func (c *MetaCollector) setSaptuneVersionMetric(ch chan<- prometheus.Metric) {
// get major saptune version
sconf, err := txtparser.ParseSysconfigFile(c.saptuneSysConf, true)
if err != nil {
log.Warnf("Error: Unable to read configuration %s: %v\n", c.saptuneSysConf, err)
}
SaptuneVersion := sconf.GetString("SAPTUNE_VERSION", "")
if SaptuneVersionF, err := strconv.ParseFloat(SaptuneVersion, 32); err == nil {
ch <- c.MakeGaugeMetric("version", float64(SaptuneVersionF))
}
}