5858type Collector struct {
5959 ctx context.Context
6060 logger log.Logger
61+ healthy * prometheus.Desc
6162 unitCPUTotal * prometheus.Desc
6263 unitState * prometheus.Desc
6364 unitInfo * prometheus.Desc
@@ -84,6 +85,10 @@ type Collector struct {
8485
8586// NewCollector returns a new Collector exposing systemd statistics.
8687func NewCollector (logger log.Logger ) (* Collector , error ) {
88+ healthy := prometheus .NewDesc (
89+ prometheus .BuildFQName (namespace , "" , "healthy" ),
90+ "Systemd exporter DBus connection health" , nil , nil ,
91+ )
8792 // Type is labeled twice e.g. name="foo.service" and type="service" to maintain compatibility
8893 // with users before we started exporting type label
8994 unitState := prometheus .NewDesc (
@@ -194,6 +199,7 @@ func NewCollector(logger log.Logger) (*Collector, error) {
194199 return & Collector {
195200 ctx : ctx ,
196201 logger : logger ,
202+ healthy : healthy ,
197203 unitCPUTotal : unitCPUTotal ,
198204 unitState : unitState ,
199205 unitInfo : unitInfo ,
@@ -223,11 +229,14 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
223229 err := c .collect (ch )
224230 if err != nil {
225231 level .Error (c .logger ).Log ("msg" , "error collecting metrics" , "err" , err )
232+ ch <- prometheus .MustNewConstMetric (
233+ c .healthy , prometheus .GaugeValue , 0 )
226234 }
227235}
228236
229237// Describe gathers descriptions of Metrics
230238func (c * Collector ) Describe (desc chan <- * prometheus.Desc ) {
239+ desc <- c .healthy
231240 desc <- c .unitCPUTotal
232241 desc <- c .unitState
233242 desc <- c .unitInfo
@@ -282,6 +291,10 @@ func (c *Collector) collect(ch chan<- prometheus.Metric) error {
282291 }
283292
284293 wg .Wait ()
294+
295+ ch <- prometheus .MustNewConstMetric (
296+ c .healthy , prometheus .GaugeValue , 1 )
297+
285298 return nil
286299}
287300
0 commit comments