module System.Metrics.Prometheus.Ridley.Metrics.Memory (
processMemory
) where
import qualified System.Metrics.Prometheus.Metric.Gauge as P
import System.Metrics.Prometheus.Ridley.Types
import System.Posix.Process
import System.Process
import Text.Read
getProcessMemory :: IO (Maybe Integer)
getProcessMemory = do
myPid <- getProcessID
readMaybe <$> readProcess "ps" ["-o", "rss=", "-p", show myPid] []
updateProcessMemory :: P.Gauge -> Bool -> IO ()
updateProcessMemory g _ = do
mbMem <- getProcessMemory
case mbMem of
Nothing -> return ()
Just m -> P.set (fromIntegral m) g
processMemory :: P.Gauge -> RidleyMetricHandler
processMemory g = RidleyMetricHandler {
metric = g
, updateMetric = updateProcessMemory
, flush = False
}