@@ -15,6 +15,7 @@ package collector
15
15
16
16
import (
17
17
"context"
18
+ "database/sql"
18
19
19
20
"github.com/go-kit/log"
20
21
"github.com/prometheus/client_golang/prometheus"
@@ -86,24 +87,62 @@ func (PGStatActivitySummaryCollector) Update(ctx context.Context, instance *inst
86
87
defer rows .Close ()
87
88
88
89
for rows .Next () {
89
- var usename , application , endpoint , command , state , waitEvent , waitEventType string
90
- var count , maxTxAge float64
90
+ var usename , application , endpoint , command , state , waitEvent , waitEventType sql. NullString
91
+ var count , maxTxAge sql. NullFloat64
91
92
92
93
if err := rows .Scan (& usename , & application , & endpoint , & command , & state , & waitEvent , & waitEventType , & count , & maxTxAge ); err != nil {
93
94
return err
94
95
}
96
+ usenameLabel := "unknown"
97
+ if usename .Valid {
98
+ usenameLabel = usename .String
99
+ }
100
+ applicationLabel := "unknown"
101
+ if application .Valid {
102
+ applicationLabel = application .String
103
+ }
104
+ endpointLabel := "unknown"
105
+ if endpoint .Valid {
106
+ endpointLabel = endpoint .String
107
+ }
108
+ commandLabel := "unknown"
109
+ if command .Valid {
110
+ commandLabel = command .String
111
+ }
112
+ stateLabel := "unknown"
113
+ if state .Valid {
114
+ stateLabel = state .String
115
+ }
116
+ waitEventLabel := "unknown"
117
+ if waitEvent .Valid {
118
+ waitEventLabel = waitEvent .String
119
+ }
120
+ waitEventTypeLabel := "unknown"
121
+ if waitEventType .Valid {
122
+ waitEventTypeLabel = waitEventType .String
123
+ }
124
+ labels := []string {usenameLabel , applicationLabel , endpointLabel , commandLabel , stateLabel , waitEventLabel , waitEventTypeLabel }
95
125
126
+ countMetric := 0.0
127
+ if count .Valid {
128
+ countMetric = count .Float64
129
+ }
96
130
ch <- prometheus .MustNewConstMetric (
97
131
statActivitySummaryActiveCount ,
98
132
prometheus .GaugeValue ,
99
- count ,
100
- usename , application , endpoint , command , state , waitEvent , waitEventType ,
133
+ countMetric ,
134
+ labels ... ,
101
135
)
136
+
137
+ maxTxAgeMetric := 0.0
138
+ if maxTxAge .Valid {
139
+ maxTxAgeMetric = maxTxAge .Float64
140
+ }
102
141
ch <- prometheus .MustNewConstMetric (
103
142
statActivitySummaryMaxTxAgeInSeconds ,
104
143
prometheus .GaugeValue ,
105
- maxTxAge ,
106
- usename , application , endpoint , command , state , waitEvent , waitEventType ,
144
+ maxTxAgeMetric ,
145
+ labels ... ,
107
146
)
108
147
}
109
148
if err := rows .Err (); err != nil {
0 commit comments