diff --git a/lib/metrics/gat.go b/lib/metrics/gat.go index cf9360b87f1cd073f0394f885ce20159be773a50..7d245c55d48065fa17b324dd1e057c909e0c1634 100644 --- a/lib/metrics/gat.go +++ b/lib/metrics/gat.go @@ -1,6 +1,8 @@ package metrics import ( + "os" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" ) @@ -21,14 +23,24 @@ func GatMetrics() *gatMetrics { } func newGatmetrics() *gatMetrics { + hostname := os.Getenv("HOSTNAME") + if hostname == "" { + hostname = "default" + } o := &gatMetrics{ ConnectionCounter: promauto.NewCounter(prometheus.CounterOpts{ Name: "pggat_connection_count_total", Help: "total number of connections initiated with pggat", + ConstLabels: prometheus.Labels{ + "pod": hostname, + }, }), ActiveConnections: promauto.NewGauge(prometheus.GaugeOpts{ Name: "pggat_current_connection_count", Help: "number of connections to pggat currently", + ConstLabels: prometheus.Labels{ + "pod": hostname, + }, }), } return o diff --git a/lib/metrics/pool.go b/lib/metrics/pool.go index 32c118e8d7519187d0d21f73872ea318dc263b28..df2a9ca66689d190eec08ebc1c19d72d1aba8b3f 100644 --- a/lib/metrics/pool.go +++ b/lib/metrics/pool.go @@ -1,6 +1,7 @@ package metrics import ( + "os" "time" "github.com/prometheus/client_golang/prometheus" @@ -30,6 +31,10 @@ func PoolMetrics(db string, user string) poolMetrics { } func newPoolMetrics(db string, user string) poolMetrics { + hostname := os.Getenv("HOSTNAME") + if hostname == "" { + hostname = "default" + } o := poolMetrics{ name: db + user, TxLatency: promauto.NewHistogramVec(prometheus.HistogramOpts{ @@ -39,6 +44,7 @@ func newPoolMetrics(db string, user string) poolMetrics { ConstLabels: prometheus.Labels{ "db": db, "user": user, + "pod": hostname, }, }, []string{}), QueryLatency: promauto.NewHistogramVec(prometheus.HistogramOpts{ @@ -48,6 +54,7 @@ func newPoolMetrics(db string, user string) poolMetrics { ConstLabels: prometheus.Labels{ "db": db, "user": user, + "pod": hostname, }, }, []string{}), TxErrorCounts: promauto.NewCounterVec(prometheus.CounterOpts{ @@ -56,6 +63,7 @@ func newPoolMetrics(db string, user string) poolMetrics { ConstLabels: prometheus.Labels{ "db": db, "user": user, + "pod": hostname, }, }, []string{"error"}), QueryErrorCounts: promauto.NewCounterVec(prometheus.CounterOpts{ @@ -64,6 +72,7 @@ func newPoolMetrics(db string, user string) poolMetrics { ConstLabels: prometheus.Labels{ "db": db, "user": user, + "pod": hostname, }, }, []string{"error"}), WaitLatency: promauto.NewHistogramVec(prometheus.HistogramOpts{ @@ -73,6 +82,7 @@ func newPoolMetrics(db string, user string) poolMetrics { ConstLabels: prometheus.Labels{ "db": db, "user": user, + "pod": hostname, }, }, []string{}), ReceivedBytes: promauto.NewCounterVec(prometheus.CounterOpts{ @@ -81,6 +91,7 @@ func newPoolMetrics(db string, user string) poolMetrics { ConstLabels: prometheus.Labels{ "db": db, "user": user, + "pod": hostname, }, }, []string{}), SentBytes: promauto.NewCounterVec(prometheus.CounterOpts{ @@ -89,6 +100,7 @@ func newPoolMetrics(db string, user string) poolMetrics { ConstLabels: prometheus.Labels{ "db": db, "user": user, + "pod": hostname, }, }, []string{}), }