diff --git a/exporter_queue.go b/exporter_queue.go index e46973a..c62b319 100644 --- a/exporter_queue.go +++ b/exporter_queue.go @@ -3,7 +3,6 @@ package main import ( "context" "errors" - "time" "github.com/prometheus/client_golang/prometheus" log "github.com/sirupsen/logrus" @@ -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 diff --git a/jsonmap.go b/jsonmap.go index 4cec6d8..81a0c81 100644 --- a/jsonmap.go +++ b/jsonmap.go @@ -3,7 +3,9 @@ package main import ( "bytes" "encoding/json" + "fmt" "strconv" + "time" log "github.com/sirupsen/logrus" ) @@ -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") + +}