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
|
// SPDX-License-Identifier: GPL-3.0-or-later
//go:build linux
// +build linux
package systemdunits
import (
"fmt"
"github.com/netdata/netdata/go/go.d.plugin/agent/module"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
const (
prioServiceUnitState = module.Priority + iota
prioSocketUnitState
prioTargetUnitState
prioPathUnitState
prioDeviceUnitState
prioMountUnitState
prioAutomountUnitState
prioSwapUnitState
prioTimerUnitState
prioScopeUnitState
prioSliceUnitState
)
var prioMap = map[string]int{
unitTypeService: prioServiceUnitState,
unitTypeSocket: prioSocketUnitState,
unitTypeTarget: prioTargetUnitState,
unitTypePath: prioPathUnitState,
unitTypeDevice: prioDeviceUnitState,
unitTypeMount: prioMountUnitState,
unitTypeAutomount: prioAutomountUnitState,
unitTypeSwap: prioSwapUnitState,
unitTypeTimer: prioTimerUnitState,
unitTypeScope: prioScopeUnitState,
unitTypeSlice: prioSliceUnitState,
}
func newTypedUnitStateChartTmpl(name, typ string) *module.Chart {
chart := module.Chart{
ID: fmt.Sprintf("unit_%s_%s_state", name, typ),
Title: fmt.Sprintf("%s Unit State", cases.Title(language.English, cases.Compact).String(typ)),
Units: "state",
Fam: fmt.Sprintf("%s units", typ),
Ctx: fmt.Sprintf("systemd.%s_unit_state", typ),
Priority: prioMap[typ],
Labels: []module.Label{
{Key: "unit_name", Value: name},
},
Dims: module.Dims{
{Name: unitStateActive},
{Name: unitStateInactive},
{Name: unitStateActivating},
{Name: unitStateDeactivating},
{Name: unitStateFailed},
},
}
for _, d := range chart.Dims {
d.ID = fmt.Sprintf("unit_%s_%s_state_%s", name, typ, d.Name)
}
return &chart
}
func (s *SystemdUnits) addUnitToCharts(name, typ string) {
chart := newTypedUnitStateChartTmpl(name, typ)
if err := s.Charts().Add(chart); err != nil {
s.Warning(err)
}
}
|