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 {
4646 namingStrategy : new DefaultNamingStrategy ( ) ,
4747 extra : {
4848 // 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 ,
5050 } ,
5151 } ;
5252 }
Original file line number Diff line number Diff line change @@ -56,6 +56,8 @@ import { Container } from "inversify";
5656import { Server } from "./server" ;
5757import { log , LogrusLogLevel } from "@gitpod/gitpod-protocol/lib/util/logging" ;
5858import { TracingManager } from "@gitpod/gitpod-protocol/lib/util/tracing" ;
59+ import { TypeORM } from "@gitpod/gitpod-db/lib" ;
60+ import { dbConnectionsFree , dbConnectionsTotal } from "./prometheus-metrics" ;
5961if ( process . env . NODE_ENV === "development" ) {
6062 require ( "longjohn" ) ;
6163}
@@ -76,9 +78,24 @@ export async function start(container: Container) {
7678 }
7779 } ) ;
7880
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+
7995 process . on ( "SIGTERM" , async ( ) => {
8096 log . info ( "SIGTERM received, stopping" ) ;
8197 await server . stop ( ) ;
98+ clearInterval ( interval ) ;
8299 } ) ;
83100
84101 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) {
3333 registry . registerMetric ( redisUpdatesReceived ) ;
3434 registry . registerMetric ( redisUpdatesCompletedTotal ) ;
3535 registry . registerMetric ( updateSubscribersRegistered ) ;
36+ registry . registerMetric ( dbConnectionsTotal ) ;
37+ registry . registerMetric ( dbConnectionsFree ) ;
3638}
3739
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+
3850const loginCompletedTotal = new prometheusClient . Counter ( {
3951 name : "gitpod_login_completed_total" ,
4052 help : "Total number of logins completed into gitpod, by status" ,
You can’t perform that action at this time.
0 commit comments