Skip to content

Commit

Permalink
fix idle_since metric for rabbitmq 3.10
Browse files Browse the repository at this point in the history
spotted in #285
  • Loading branch information
kbudde committed Jun 22, 2022
1 parent 3e446f0 commit 1105bfa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions exporter_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"errors"
"time"

"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -202,7 +201,8 @@ func (e exporterQueue) Collect(ctx context.Context, ch chan<- prometheus.Metric)
state := queue.labels["state"]
idleSince, exists := queue.labels["idle_since"]
if exists && idleSince != "" {
if t, err := time.Parse("2006-01-02 15:04:05", idleSince); err == nil {

if t, err := parseTime(idleSince); err == nil {
unixSeconds := float64(t.UnixNano()) / 1e9

if state == "running" { //replace running state with idle if idle_since time is provided. Other states (flow, etc.) are not replaced
Expand Down
15 changes: 15 additions & 0 deletions jsonmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
"time"

log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -129,3 +131,16 @@ func (rep *rabbitJSONReply) GetString(key string) (string, bool) {
value, ok := val.(string)
return value, ok
}

func parseTime(s string) (time.Time, error) {
t, err := time.Parse("2006-01-02 15:04:05", s)
if err == nil {
return t, nil
}
t, err = time.Parse("2006-01-02T15:04:05.999-07:00", s)
if err == nil {
return t, nil
}
return t, fmt.Errorf("time format does not match expectations")

}

0 comments on commit 1105bfa

Please sign in to comment.