Skip to content

Commit

Permalink
Merge pull request #13 from vinted/fix/fix_possible_race_condintion
Browse files Browse the repository at this point in the history
Fix for possible race condition
  • Loading branch information
Seitanas authored Feb 11, 2020
2 parents 529e8d4 + 80d56b8 commit 827b546
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var schema = make(map[string]string)
var cephMetrics = make(map[string]interface{})
var cephDevice = make(map[string]interface{})
var osdSchema = make(map[string]interface{})
var mutex = sync.RWMutex{}

type cephCollector struct {
}
Expand Down Expand Up @@ -90,10 +91,7 @@ func CollectTimer(queryInterval int) {
}

func Collector() {

var cephDeviceTmp map[string]string
var mutex = &sync.Mutex{}

log.Debug("Collector started")
sockets := ListCephSockets()
for _, socket := range sockets {
Expand All @@ -112,11 +110,9 @@ func Collector() {
}

func (collector *cephCollector) Collect(ch chan<- prometheus.Metric) {

scrapeTime := time.Now()

log.Debug("Processing HTTP request")

mutex.RLock()
for socket, cephMetric := range cephMetrics {
for metricName, metricData := range cephMetric.(map[string]interface{}) {
for metricType, metricsValue := range metricData.(map[string]interface{}) {
Expand Down Expand Up @@ -147,6 +143,7 @@ func (collector *cephCollector) Collect(ch chan<- prometheus.Metric) {
}
}
}
mutex.RUnlock()
description := prometheus.NewDesc("ceph_exporter_scrape_time", "Duration of a collector scrape", nil, nil)
ch <- prometheus.MustNewConstMetric(description, prometheus.GaugeValue, time.Since(scrapeTime).Seconds())
log.Debug("HTTP request finished")
Expand Down

0 comments on commit 827b546

Please sign in to comment.