github.com/netdata/go.d.plugin@v0.58.1/modules/systemdunits/charts.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 //go:build linux 4 // +build linux 5 6 package systemdunits 7 8 import ( 9 "fmt" 10 11 "github.com/netdata/go.d.plugin/agent/module" 12 13 "golang.org/x/text/cases" 14 "golang.org/x/text/language" 15 ) 16 17 const ( 18 prioServiceUnitState = module.Priority + iota 19 prioSocketUnitState 20 prioTargetUnitState 21 prioPathUnitState 22 prioDeviceUnitState 23 prioMountUnitState 24 prioAutomountUnitState 25 prioSwapUnitState 26 prioTimerUnitState 27 prioScopeUnitState 28 prioSliceUnitState 29 ) 30 31 var prioMap = map[string]int{ 32 unitTypeService: prioServiceUnitState, 33 unitTypeSocket: prioSocketUnitState, 34 unitTypeTarget: prioTargetUnitState, 35 unitTypePath: prioPathUnitState, 36 unitTypeDevice: prioDeviceUnitState, 37 unitTypeMount: prioMountUnitState, 38 unitTypeAutomount: prioAutomountUnitState, 39 unitTypeSwap: prioSwapUnitState, 40 unitTypeTimer: prioTimerUnitState, 41 unitTypeScope: prioScopeUnitState, 42 unitTypeSlice: prioSliceUnitState, 43 } 44 45 func newTypedUnitStateChartTmpl(name, typ string) *module.Chart { 46 chart := module.Chart{ 47 ID: fmt.Sprintf("unit_%s_%s_state", name, typ), 48 Title: fmt.Sprintf("%s Unit State", cases.Title(language.English, cases.Compact).String(typ)), 49 Units: "state", 50 Fam: fmt.Sprintf("%s units", typ), 51 Ctx: fmt.Sprintf("systemd.%s_unit_state", typ), 52 Priority: prioMap[typ], 53 Labels: []module.Label{ 54 {Key: "unit_name", Value: name}, 55 }, 56 Dims: module.Dims{ 57 {Name: unitStateActive}, 58 {Name: unitStateInactive}, 59 {Name: unitStateActivating}, 60 {Name: unitStateDeactivating}, 61 {Name: unitStateFailed}, 62 }, 63 } 64 for _, d := range chart.Dims { 65 d.ID = fmt.Sprintf("unit_%s_%s_state_%s", name, typ, d.Name) 66 } 67 return &chart 68 } 69 70 func (s *SystemdUnits) addUnitToCharts(name, typ string) { 71 chart := newTypedUnitStateChartTmpl(name, typ) 72 73 if err := s.Charts().Add(chart); err != nil { 74 s.Warning(err) 75 } 76 }