@@ -14,7 +14,7 @@ export class PgPoolPrometheusExporter {
1414 private readonly defaultOptions : PgPoolExporterOptions = { }
1515
1616 private readonly poolMaxSize : number | undefined
17- private readonly poolHost : string
17+ private readonly poolHost : string | undefined
1818 private readonly poolPort : number
1919 private readonly poolDatabase : string | undefined
2020
@@ -104,13 +104,15 @@ export class PgPoolPrometheusExporter {
104104 labelNames : mergeLabelNamesWithStandardLabels ( [ 'host' , 'database' ] , this . options . defaultLabels ) ,
105105 registers : [ this . register ] ,
106106 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+ }
114116 }
115117 } )
116118
@@ -124,13 +126,15 @@ export class PgPoolPrometheusExporter {
124126 labelNames : mergeLabelNamesWithStandardLabels ( [ 'host' , 'database' ] , this . options . defaultLabels ) ,
125127 registers : [ this . register ] ,
126128 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+ }
134138 }
135139 } )
136140
@@ -181,6 +185,7 @@ export class PgPoolPrometheusExporter {
181185 }
182186
183187 onPoolConnect ( client : PoolClient ) : void {
188+
184189 this . poolConnectionsCreatedTotal . inc (
185190 mergeLabelsWithStandardLabels ( { host : this . poolHost + ':' + this . poolPort . toString ( ) , database : this . poolDatabase } , this . options . defaultLabels )
186191 )
0 commit comments