diff options
Diffstat (limited to 'src/go/collectors/go.d.plugin/modules/systemdunits/charts.go')
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/systemdunits/charts.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/systemdunits/charts.go b/src/go/collectors/go.d.plugin/modules/systemdunits/charts.go new file mode 100644 index 0000000000..23a1bf75e7 --- /dev/null +++ b/src/go/collectors/go.d.plugin/modules/systemdunits/charts.go @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +//go:build linux +// +build linux + +package systemdunits + +import ( + "fmt" + + "github.com/netdata/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) + } +} |