@@ -73,13 +73,15 @@ export class PgPoolPrometheusExporter {
7373 labelNames : mergeLabelNamesWithStandardLabels ( [ 'host' , 'database' ] , this . options . defaultLabels ) ,
7474 registers : [ this . register ] ,
7575 collect : ( ) => {
76- this . poolSizeMax . set (
77- mergeLabelsWithStandardLabels (
78- { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
79- this . options . defaultLabels
80- ) ,
81- this . poolMaxSize !
82- )
76+ if ( this . poolHost != null && this . poolDatabase != null ) {
77+ this . poolSizeMax . set (
78+ mergeLabelsWithStandardLabels (
79+ { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
80+ this . options . defaultLabels
81+ ) ,
82+ this . poolMaxSize !
83+ )
84+ }
8385 }
8486 } )
8587
@@ -104,7 +106,7 @@ export class PgPoolPrometheusExporter {
104106 labelNames : mergeLabelNamesWithStandardLabels ( [ 'host' , 'database' ] , this . options . defaultLabels ) ,
105107 registers : [ this . register ] ,
106108 collect : ( ) => {
107- if ( ( this . poolHost != null ) && this . poolDatabase != null ) {
109+ if ( this . poolHost != null && this . poolDatabase != null ) {
108110 this . poolWaitingConnections . set (
109111 mergeLabelsWithStandardLabels (
110112 { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
@@ -126,7 +128,7 @@ export class PgPoolPrometheusExporter {
126128 labelNames : mergeLabelNamesWithStandardLabels ( [ 'host' , 'database' ] , this . options . defaultLabels ) ,
127129 registers : [ this . register ] ,
128130 collect : ( ) => {
129- if ( ( this . poolHost != null ) && this . poolDatabase != null ) {
131+ if ( this . poolHost != null && this . poolDatabase != null ) {
130132 this . poolIdleConnections . set (
131133 mergeLabelsWithStandardLabels (
132134 { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
@@ -185,42 +187,69 @@ export class PgPoolPrometheusExporter {
185187 }
186188
187189 onPoolConnect ( client : PoolClient ) : void {
188-
189- this . poolConnectionsCreatedTotal . inc (
190- mergeLabelsWithStandardLabels ( { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } , this . options . defaultLabels )
191- )
192- this . poolSize . inc (
193- mergeLabelsWithStandardLabels ( { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } , this . options . defaultLabels )
194- )
190+ if ( this . poolHost != null && this . poolDatabase != null ) {
191+ this . poolConnectionsCreatedTotal . inc (
192+ mergeLabelsWithStandardLabels (
193+ { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
194+ this . options . defaultLabels
195+ )
196+ )
197+ this . poolSize . inc (
198+ mergeLabelsWithStandardLabels (
199+ { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
200+ this . options . defaultLabels
201+ )
202+ )
203+ }
195204 }
196205
197206 onPoolConnectionAcquired ( client : PoolClient ) : void {
198- this . poolActiveConnections . inc (
199- mergeLabelsWithStandardLabels ( { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } , this . options . defaultLabels )
200- )
207+ if ( this . poolHost != null && this . poolDatabase != null ) {
208+ this . poolActiveConnections . inc (
209+ mergeLabelsWithStandardLabels (
210+ { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
211+ this . options . defaultLabels
212+ )
213+ )
214+ }
201215 }
202216
203217 onPoolError ( error : Error ) : void {
204- this . poolErrors . inc (
205- mergeLabelsWithStandardLabels (
206- { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase , error : error . message } ,
207- this . options . defaultLabels
218+ if ( this . poolHost != null && this . poolDatabase != null ) {
219+ this . poolErrors . inc (
220+ mergeLabelsWithStandardLabels (
221+ { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase , error : error . message } ,
222+ this . options . defaultLabels
223+ )
208224 )
209- )
225+ }
210226 }
211227
212228 onPoolConnectionReleased ( _error : Error , client : PoolClient ) : void {
213- this . poolActiveConnections . dec (
214- mergeLabelsWithStandardLabels ( { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } , this . options . defaultLabels )
215- )
229+ if ( this . poolHost != null && this . poolDatabase != null ) {
230+ this . poolActiveConnections . dec (
231+ mergeLabelsWithStandardLabels (
232+ { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
233+ this . options . defaultLabels
234+ )
235+ )
236+ }
216237 }
217238
218239 onPoolConnectionRemoved ( client : PoolClient ) : void {
219- this . poolSize . dec (
220- mergeLabelsWithStandardLabels ( { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } , this . options . defaultLabels )
221- )
222- this . poolConnectionsRemovedTotal . inc (
223- mergeLabelsWithStandardLabels ( { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } , this . options . defaultLabels )
224- )
240+ if ( this . poolHost != null && this . poolDatabase != null ) {
241+ this . poolSize . dec (
242+ mergeLabelsWithStandardLabels (
243+ { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
244+ this . options . defaultLabels
245+ )
246+ )
247+ this . poolConnectionsRemovedTotal . inc (
248+ mergeLabelsWithStandardLabels (
249+ { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } ,
250+ this . options . defaultLabels
251+ )
252+ )
253+ }
225254 }
226255}
0 commit comments