@@ -69,6 +69,7 @@ type Collector struct {
69
69
unitActiveExitTimeDesc * prometheus.Desc
70
70
unitInactiveEnterTimeDesc * prometheus.Desc
71
71
unitInactiveExitTimeDesc * prometheus.Desc
72
+ unitMemoryCurrentDesc * prometheus.Desc
72
73
nRestartsDesc * prometheus.Desc
73
74
timerLastTriggerDesc * prometheus.Desc
74
75
socketAcceptedConnectionsDesc * prometheus.Desc
@@ -142,6 +143,11 @@ func NewCollector(logger log.Logger) (*Collector, error) {
142
143
"Last time the unit transitioned out of the inactive state" ,
143
144
[]string {"name" , "type" }, nil ,
144
145
)
146
+ unitMemoryCurrentDesc := prometheus .NewDesc (
147
+ prometheus .BuildFQName (namespace , "" , "unit_memory_current" ),
148
+ "Current memory per Systemd unit" ,
149
+ []string {"name" }, nil ,
150
+ )
145
151
nRestartsDesc := prometheus .NewDesc (
146
152
prometheus .BuildFQName (namespace , "" , "service_restart_total" ),
147
153
"Service unit count of Restart triggers" , []string {"name" }, nil )
@@ -205,6 +211,7 @@ func NewCollector(logger log.Logger) (*Collector, error) {
205
211
unitActiveExitTimeDesc : unitActiveExitTimeDesc ,
206
212
unitInactiveEnterTimeDesc : unitInactiveEnterTimeDesc ,
207
213
unitInactiveExitTimeDesc : unitInactiveExitTimeDesc ,
214
+ unitMemoryCurrentDesc : unitMemoryCurrentDesc ,
208
215
nRestartsDesc : nRestartsDesc ,
209
216
timerLastTriggerDesc : timerLastTriggerDesc ,
210
217
socketAcceptedConnectionsDesc : socketAcceptedConnectionsDesc ,
@@ -235,6 +242,7 @@ func (c *Collector) Describe(desc chan<- *prometheus.Desc) {
235
242
desc <- c .unitStartTimeDesc
236
243
desc <- c .unitTasksCurrentDesc
237
244
desc <- c .unitTasksMaxDesc
245
+ desc <- c .unitMemoryCurrentDesc
238
246
desc <- c .nRestartsDesc
239
247
desc <- c .timerLastTriggerDesc
240
248
desc <- c .socketAcceptedConnectionsDesc
@@ -325,6 +333,11 @@ func (c *Collector) collectUnit(conn *dbus.Conn, ch chan<- prometheus.Metric, un
325
333
level .Warn (logger ).Log ("msg" , errUnitMetricsMsg , "err" , err )
326
334
}
327
335
336
+ err = c .collectServiceMemoryMetrics (conn , ch , unit )
337
+ if err != nil {
338
+ level .Warn (logger ).Log ("msg" , errUnitMetricsMsg , "err" , err )
339
+ }
340
+
328
341
err = c .collectUnitCPUUsageMetrics ("Service" , conn , ch , unit )
329
342
if err != nil {
330
343
level .Warn (logger ).Log ("msg" , errUnitMetricsMsg , "err" , err )
@@ -686,6 +699,27 @@ func (c *Collector) collectServiceTasksMetrics(conn *dbus.Conn, ch chan<- promet
686
699
return nil
687
700
}
688
701
702
+ func (c * Collector ) collectServiceMemoryMetrics (conn * dbus.Conn , ch chan <- prometheus.Metric , unit dbus.UnitStatus ) error {
703
+ memoryCurrentCount , err := conn .GetUnitTypePropertyContext (c .ctx , unit .Name , "Service" , "MemoryCurrent" )
704
+ if err != nil {
705
+ return errors .Wrapf (err , errGetPropertyMsg , "MemoryCurrent" )
706
+ }
707
+
708
+ currentCount , ok := memoryCurrentCount .Value .Value ().(uint64 )
709
+ if ! ok {
710
+ return errors .Errorf (errConvertUint64PropertyMsg , "MemoryCurrent" , memoryCurrentCount .Value .Value ())
711
+ }
712
+
713
+ // Don't set if memoryCurrent if dbus reports MaxUint64.
714
+ if currentCount != math .MaxUint64 {
715
+ ch <- prometheus .MustNewConstMetric (
716
+ c .unitMemoryCurrentDesc , prometheus .GaugeValue ,
717
+ float64 (currentCount ), unit .Name )
718
+ }
719
+
720
+ return nil
721
+ }
722
+
689
723
func (c * Collector ) collectTimerTriggerTime (conn * dbus.Conn , ch chan <- prometheus.Metric , unit dbus.UnitStatus ) error {
690
724
lastTriggerValue , err := conn .GetUnitTypePropertyContext (c .ctx , unit .Name , "Timer" , "LastTriggerUSec" )
691
725
if err != nil {
0 commit comments