forked from SUSE/saptune_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes_collector.go
78 lines (66 loc) · 2.23 KB
/
notes_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"os/exec"
"strings"
"github.com/SUSE/saptune/sap/note"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
const subsystemNote = "note"
const noteTuningSheets = "/usr/share/saptune/notes/"
const extraTuningSheets = "/etc/saptune/extra/"
// NoteCollector is the saptune solution collector
type NoteCollector struct {
DefaultCollector
saptunePath string
}
// Lookup for a given Solution ID enabled the corrisponding Name/Descriptions
func getNoteDesc(enabledNoteID string) string {
tuningOptions := note.GetTuningOptions(noteTuningSheets, extraTuningSheets)
for _, noteID := range tuningOptions.GetSortedIDs() {
noteObj := tuningOptions[noteID]
if noteID == enabledNoteID {
// this is how looks like noteObj.Name, remove the version.
// "Linux: User and system resource limits \n Version 5 from 18.06.2018 ",
solDescRaw := strings.Split(noteObj.Name(), "\n")
// return only description
return solDescRaw[0]
}
}
// in case there is no match return empty string
return ""
}
// NewNoteCollector creates a new solution saptune collector
func NewNoteCollector(saptunePath string) (*NoteCollector, error) {
c := &NoteCollector{
NewDefaultCollector(subsystemNote),
saptunePath,
}
c.SetDescriptor("enabled", "This metrics show with 1 all the enabled notes on the system", []string{"note_id", "note_desc"})
return c, nil
}
// Collect various metrics for saptune solution
func (c *NoteCollector) Collect(ch chan<- prometheus.Metric) {
log.Debugln("Collecting saptune note metrics...")
c.noteEnabled(ch)
}
func (c *NoteCollector) noteEnabled(ch chan<- prometheus.Metric) {
err := checkExecutables(c.saptunePath)
if err != nil {
log.Warnf("%v failed to retrieve saptune executable", err)
return
}
noteList, err := exec.Command(c.saptunePath, "note", "enabled").CombinedOutput()
if err != nil {
log.Warnf("%v - Failed to run saptune note enabled command n %s ", err, string(noteList))
return
}
notes := strings.Fields(string(noteList))
for _, note := range notes {
noteDesc := getNoteDesc(note)
if noteDesc == "" {
log.Warnf("Could not find the note description for given note ID %s", note)
}
ch <- c.MakeGaugeMetric("enabled", float64(1), note, noteDesc)
}
}