server: add hasura_postgres_max_connection prometheus metric

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10669
GitOrigin-RevId: 6d6607a6dd520866d1aa556bab1007afd1793a01
This commit is contained in:
Naveen Naidu 2024-02-20 11:29:10 +05:30 committed by hasura-bot
parent 973035dbbb
commit acd3f33bb5
2 changed files with 8 additions and 0 deletions

View File

@ -15,6 +15,7 @@ module Database.PG.Query.Pool
PGPoolStats (..), PGPoolStats (..),
PGPoolMetrics (..), PGPoolMetrics (..),
getInUseConnections, getInUseConnections,
getMaxConnections,
defaultConnParams, defaultConnParams,
initPGPool, initPGPool,
resizePGPool, resizePGPool,
@ -97,6 +98,9 @@ data PGPoolMetrics = PGPoolMetrics
getInUseConnections :: PGPool -> IO Int getInUseConnections :: PGPool -> IO Int
getInUseConnections = RP.getInUseResourceCount . _pool getInUseConnections = RP.getInUseResourceCount . _pool
getMaxConnections :: PGPool -> IO Int
getMaxConnections = RP.getMaxResources . _pool
data ConnParams = ConnParams data ConnParams = ConnParams
{ cpStripes :: !Int, { cpStripes :: !Int,
cpConns :: !Int, cpConns :: !Int,

View File

@ -34,6 +34,7 @@ module Data.Pool
createPool, createPool,
createPool', createPool',
resizePool, resizePool,
getMaxResources,
tryTrimLocalPool, tryTrimLocalPool,
tryTrimPool, tryTrimPool,
withResource, withResource,
@ -231,6 +232,9 @@ resizePool Pool {..} maxResources' = do
"invalid maximum resource count " ++ show maxResources' "invalid maximum resource count " ++ show maxResources'
atomically $ writeTVar maxResources maxResources' atomically $ writeTVar maxResources maxResources'
getMaxResources :: Pool a -> IO Int
getMaxResources Pool {..} = readTVarIO maxResources
-- | Attempt to reduce resource allocation below maximum by dropping some unused -- | Attempt to reduce resource allocation below maximum by dropping some unused
-- resources -- resources
tryTrimLocalPool :: (a -> IO ()) -> TVar Int -> LocalPool a -> IO () tryTrimLocalPool :: (a -> IO ()) -> TVar Int -> LocalPool a -> IO ()