File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ export class TypeORM {
46
46
namingStrategy : new DefaultNamingStrategy ( ) ,
47
47
extra : {
48
48
// default is 10 (see https://github.com/mysqljs/mysql#pool-options), which is too low for our use case
49
- connectionLimit : 20 ,
49
+ connectionLimit : 40 ,
50
50
} ,
51
51
} ;
52
52
}
Original file line number Diff line number Diff line change @@ -56,6 +56,8 @@ import { Container } from "inversify";
56
56
import { Server } from "./server" ;
57
57
import { log , LogrusLogLevel } from "@gitpod/gitpod-protocol/lib/util/logging" ;
58
58
import { TracingManager } from "@gitpod/gitpod-protocol/lib/util/tracing" ;
59
+ import { TypeORM } from "@gitpod/gitpod-db/lib" ;
60
+ import { dbConnectionsFree , dbConnectionsTotal } from "./prometheus-metrics" ;
59
61
if ( process . env . NODE_ENV === "development" ) {
60
62
require ( "longjohn" ) ;
61
63
}
@@ -76,9 +78,24 @@ export async function start(container: Container) {
76
78
}
77
79
} ) ;
78
80
81
+ const interval = setInterval ( async ( ) => {
82
+ try {
83
+ const connection = await container . get ( TypeORM ) . getConnection ( ) ;
84
+ const pool : any = ( connection . driver as any ) . pool ;
85
+ const activeConnections = pool . _allConnections . length ;
86
+ const freeConnections = pool . _freeConnections . length ;
87
+
88
+ dbConnectionsTotal . set ( activeConnections ) ;
89
+ dbConnectionsFree . set ( freeConnections ) ;
90
+ } catch ( error ) {
91
+ log . error ( "Error updating TypeORM metrics" , error ) ;
92
+ }
93
+ } , 5000 ) ;
94
+
79
95
process . on ( "SIGTERM" , async ( ) => {
80
96
log . info ( "SIGTERM received, stopping" ) ;
81
97
await server . stop ( ) ;
98
+ clearInterval ( interval ) ;
82
99
} ) ;
83
100
84
101
const tracing = container . get ( TracingManager ) ;
Original file line number Diff line number Diff line change @@ -33,8 +33,20 @@ export function registerServerMetrics(registry: prometheusClient.Registry) {
33
33
registry . registerMetric ( redisUpdatesReceived ) ;
34
34
registry . registerMetric ( redisUpdatesCompletedTotal ) ;
35
35
registry . registerMetric ( updateSubscribersRegistered ) ;
36
+ registry . registerMetric ( dbConnectionsTotal ) ;
37
+ registry . registerMetric ( dbConnectionsFree ) ;
36
38
}
37
39
40
+ export const dbConnectionsTotal = new prometheusClient . Gauge ( {
41
+ name : "gitpod_typeorm_total_connections" ,
42
+ help : "Total number of connections in TypeORM pool" ,
43
+ } ) ;
44
+
45
+ export const dbConnectionsFree = new prometheusClient . Gauge ( {
46
+ name : "gitpod_typeorm_free_connections" ,
47
+ help : "Number of free connections in TypeORM pool" ,
48
+ } ) ;
49
+
38
50
const loginCompletedTotal = new prometheusClient . Counter ( {
39
51
name : "gitpod_login_completed_total" ,
40
52
help : "Total number of logins completed into gitpod, by status" ,
You can’t perform that action at this time.
0 commit comments