@@ -14,7 +14,7 @@ export class PgPoolPrometheusExporter {
14
14
private readonly defaultOptions : PgPoolExporterOptions = { }
15
15
16
16
private readonly poolMaxSize : number | undefined
17
- private readonly poolHost : string
17
+ private readonly poolHost : string | undefined
18
18
private readonly poolPort : number
19
19
private readonly poolDatabase : string | undefined
20
20
@@ -104,13 +104,15 @@ export class PgPoolPrometheusExporter {
104
104
labelNames : mergeLabelNamesWithStandardLabels ( [ 'host' , 'database' ] , this . options . defaultLabels ) ,
105
105
registers : [ this . register ] ,
106
106
collect : ( ) => {
107
- this . poolWaitingConnections . set (
108
- mergeLabelsWithStandardLabels (
109
- { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
110
- this . options . defaultLabels
111
- ) ,
112
- this . pool . waitingCount
113
- )
107
+ if ( ( this . poolHost != null ) && this . poolDatabase != null ) {
108
+ this . poolWaitingConnections . set (
109
+ mergeLabelsWithStandardLabels (
110
+ { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
111
+ this . options . defaultLabels
112
+ ) ,
113
+ this . pool . waitingCount
114
+ )
115
+ }
114
116
}
115
117
} )
116
118
@@ -124,13 +126,15 @@ export class PgPoolPrometheusExporter {
124
126
labelNames : mergeLabelNamesWithStandardLabels ( [ 'host' , 'database' ] , this . options . defaultLabels ) ,
125
127
registers : [ this . register ] ,
126
128
collect : ( ) => {
127
- this . poolIdleConnections . set (
128
- mergeLabelsWithStandardLabels (
129
- { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
130
- this . options . defaultLabels
131
- ) ,
132
- this . pool . idleCount
133
- )
129
+ if ( ( this . poolHost != null ) && this . poolDatabase != null ) {
130
+ this . poolIdleConnections . set (
131
+ mergeLabelsWithStandardLabels (
132
+ { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
133
+ this . options . defaultLabels
134
+ ) ,
135
+ this . pool . idleCount
136
+ )
137
+ }
134
138
}
135
139
} )
136
140
@@ -181,6 +185,7 @@ export class PgPoolPrometheusExporter {
181
185
}
182
186
183
187
onPoolConnect ( client : PoolClient ) : void {
188
+
184
189
this . poolConnectionsCreatedTotal . inc (
185
190
mergeLabelsWithStandardLabels ( { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } , this . options . defaultLabels )
186
191
)
0 commit comments