github.com/netdata/go.d.plugin@v0.58.1/modules/windows/collect_collector.go (about)

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package windows
     4  
     5  import (
     6  	"github.com/netdata/go.d.plugin/pkg/prometheus"
     7  )
     8  
     9  const (
    10  	metricCollectorDuration = "windows_exporter_collector_duration_seconds"
    11  	metricCollectorSuccess  = "windows_exporter_collector_success"
    12  )
    13  
    14  func (w *Windows) collectCollector(mx map[string]int64, pms prometheus.Series) {
    15  	seen := make(map[string]bool)
    16  	px := "collector_"
    17  	for _, pm := range pms.FindByName(metricCollectorDuration) {
    18  		if name := pm.Labels.Get("collector"); name != "" {
    19  			seen[name] = true
    20  			mx[px+name+"_duration"] = int64(pm.Value * precision)
    21  		}
    22  	}
    23  	for _, pm := range pms.FindByName(metricCollectorSuccess) {
    24  		if name := pm.Labels.Get("collector"); name != "" {
    25  			seen[name] = true
    26  			if pm.Value == 1 {
    27  				mx[px+name+"_status_success"], mx[px+name+"_status_fail"] = 1, 0
    28  			} else {
    29  				mx[px+name+"_status_success"], mx[px+name+"_status_fail"] = 0, 1
    30  			}
    31  		}
    32  	}
    33  
    34  	for name := range seen {
    35  		if !w.cache.collectors[name] {
    36  			w.cache.collectors[name] = true
    37  			w.addCollectorCharts(name)
    38  		}
    39  	}
    40  	for name := range w.cache.collectors {
    41  		if !seen[name] {
    42  			delete(w.cache.collectors, name)
    43  			w.removeCollectorCharts(name)
    44  		}
    45  	}
    46  }