Skip to content

Commit

Permalink
i think i fixed the sizes histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Seidel committed Aug 29, 2019
1 parent a0a7a5e commit 5de63b3
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions exporter/jvbCollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,25 +245,37 @@ func (c *JvbCollector) Collect(metrics chan<- prometheus.Metric) {
if metric.name == c.NamePrefix+"conference_sizes" {
var sizes = make(map[float64]uint64)
value := strings.Trim(stat.Value, "[]")
values := strings.Split(value, ",")
var sum float64
for i, v := range values {
var values []uint64
for _, v := range strings.Split(value, ",") {
vuint, _ := strconv.ParseUint(v, 10, 64)
sizes[float64(i)] = vuint
sum += float64(vuint)
values = append(values, vuint)
}

//calculate sum (makes this metric independent from conferences metric)
var sum uint64
for _, v := range values {
sum += v
}

//for the histgram buckets we need to omit the last field b/c the +inf bucket is added automatically
values = values[:len(values)-1]

for i, v := range values {
sizes[float64(i)] = v
}

m, err := prometheus.NewConstHistogram(metric.desc, uint64(len(values)), sum, sizes, set.jvbIdentifier)
m, err := prometheus.NewConstHistogram(metric.desc, sum, float64(sum), sizes, set.jvbIdentifier)

if err != nil {
fmt.Printf("Unable to publish %s: %s\n", metric.name, err.Error())
fmt.Printf("Unable to publish metric %s: %s\n", metric.name, err.Error())
continue
}

metrics <- m
continue
}

//simple metrics
value, err := strconv.ParseFloat(stat.Value, 64)
if err != nil {
fmt.Printf("unable to convert value %s to numeric: %s\n", stat.Value, err.Error())
Expand Down

0 comments on commit 5de63b3

Please sign in to comment.