MCPcopy
hub / github.com/prometheus/node_exporter / Update

Method Update

collector/systemd_linux.go:182–280  ·  view source on GitHub ↗

Update gathers metrics from systemd. Dbus collection is done in parallel to reduce wait time for responses.

(ch chan<- prometheus.Metric)

Source from the content-addressed store, hash-verified

180// Update gathers metrics from systemd. Dbus collection is done in parallel
181// to reduce wait time for responses.
182func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error {
183 begin := time.Now()
184 conn, err := newSystemdDbusConn()
185 if err != nil {
186 return fmt.Errorf("couldn't get dbus connection: %w", err)
187 }
188 defer conn.Close()
189
190 systemdVersion, systemdVersionFull := c.getSystemdVersion(conn)
191 if systemdVersion < minSystemdVersionSystemState {
192 c.logger.Debug("Detected systemd version is lower than minimum, some systemd state and timer metrics will not be available", "current", systemdVersion, "minimum", minSystemdVersionSystemState)
193 }
194 ch <- prometheus.MustNewConstMetric(
195 c.systemdVersionDesc,
196 prometheus.GaugeValue,
197 systemdVersion,
198 systemdVersionFull,
199 )
200
201 systemdVirtualization := c.getSystemdVirtualization(conn)
202 ch <- prometheus.MustNewConstMetric(
203 c.virtualizationDesc,
204 prometheus.GaugeValue,
205 1.0,
206 systemdVirtualization,
207 )
208
209 allUnits, err := c.getAllUnits(conn)
210 if err != nil {
211 return fmt.Errorf("couldn't get units: %w", err)
212 }
213 c.logger.Debug("getAllUnits took", "duration_seconds", time.Since(begin).Seconds())
214
215 begin = time.Now()
216 summary := summarizeUnits(allUnits)
217 c.collectSummaryMetrics(ch, summary)
218 c.logger.Debug("collectSummaryMetrics took", "duration_seconds", time.Since(begin).Seconds())
219
220 begin = time.Now()
221 units := filterUnits(allUnits, c.systemdUnitIncludePattern, c.systemdUnitExcludePattern, c.logger)
222 c.logger.Debug("filterUnits took", "duration_seconds", time.Since(begin).Seconds())
223
224 var wg sync.WaitGroup
225 defer wg.Wait()
226
227 wg.Add(1)
228 go func() {
229 defer wg.Done()
230 begin := time.Now()
231 c.collectUnitStatusMetrics(conn, ch, units)
232 c.logger.Debug("collectUnitStatusMetrics took", "duration_seconds", time.Since(begin).Seconds())
233 }()
234
235 if *enableStartTimeMetrics {
236 wg.Add(1)
237 go func() {
238 defer wg.Done()
239 begin := time.Now()

Callers

nothing calls this directly

Calls 14

getSystemdVersionMethod · 0.95
getAllUnitsMethod · 0.95
collectSummaryMetricsMethod · 0.95
collectTimersMethod · 0.95
collectSocketsMethod · 0.95
collectSystemStateMethod · 0.95
newSystemdDbusConnFunction · 0.85
summarizeUnitsFunction · 0.85

Tested by

no test coverage detected