ekg 0.3.1.1 → 0.3.1.2
raw patch · 2 files changed
+79/−11 lines, 2 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- System/Remote/Monitoring.hs +78/−10
- ekg.cabal +1/−1
System/Remote/Monitoring.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE ExistentialQuantification, OverloadedStrings, RecordWildCards,+{-# LANGUAGE CPP, ExistentialQuantification, OverloadedStrings, RecordWildCards, FunctionalDependencies #-} -- | This module provides remote monitoring of a running process over -- HTTP. It can be used to run an HTTP server that provides both a@@ -171,14 +171,28 @@ -- -- [@peak_megabytes_allocated@] Maximum number of megabytes allocated --+#if MIN_VERSION_base(4,6,0)+-- [@par_tot_bytes_copied@] Number of bytes copied during GC, minus+-- space held by mutable lists held by the capabilities. Can be used+-- with 'parMaxBytesCopied' to determine how well parallel GC utilized+-- all cores.+--+-- [@par_avg_bytes_copied@] Deprecated alias for+-- @par_tot_bytes_copied@.+#else -- [@par_avg_bytes_copied@] Number of bytes copied during GC, minus -- space held by mutable lists held by the capabilities. Can be used -- with 'parMaxBytesCopied' to determine how well parallel GC utilized -- all cores.+#endif -- -- [@par_max_bytes_copied@] Sum of number of bytes copied each GC by -- the most active GC thread each GC. The ratio of+#if MIN_VERSION_base(4,6,0)+-- 'parTotBytesCopied' divided by 'parMaxBytesCopied' approaches 1 for+#else -- 'parAvgBytesCopied' divided by 'parMaxBytesCopied' approaches 1 for+#endif -- a maximally sequential run and approaches the number of threads -- (set by the RTS flag @-N@) for a maximally parallel run. @@ -340,8 +354,34 @@ ![(T.Text, Json)] -- Labels {-# UNPACK #-} !Double -- Milliseconds since epoch +emptyGCStats :: Stats.GCStats+emptyGCStats = Stats.GCStats+ { bytesAllocated = 0+ , numGcs = 0+ , maxBytesUsed = 0+ , numByteUsageSamples = 0+ , cumulativeBytesUsed = 0+ , bytesCopied = 0+ , currentBytesUsed = 0+ , currentBytesSlop = 0+ , maxBytesSlop = 0+ , peakMegabytesAllocated = 0+ , mutatorCpuSeconds = 0+ , mutatorWallSeconds = 0+ , gcCpuSeconds = 0+ , gcWallSeconds = 0+ , cpuSeconds = 0+ , wallSeconds = 0+#if MIN_VERSION_base(4,6,0)+ , parTotBytesCopied = 0+#else+ , parAvgBytesCopied = 0+#endif+ , parMaxBytesCopied = 0+ }+ instance A.ToJSON Stats where- toJSON (Stats gcStats@(Stats.GCStats {..}) counters gauges labels t) = A.object $+ toJSON (Stats gcStats counters gauges labels t) = A.object $ [ "server_timestamp_millis" .= t , "counters" .= Assocs (gcCounters ++ counters) , "gauges" .= Assocs (gcGauges ++ gauges)@@ -373,9 +413,15 @@ , "gc_wall_seconds" .= gcWallSeconds , "cpu_seconds" .= cpuSeconds , "wall_seconds" .= wallSeconds+#if MIN_VERSION_base(4,6,0)+ , "par_tot_bytes_copied" .= parTotBytesCopied+ , "par_avg_bytes_copied" .= parTotBytesCopied+#else , "par_avg_bytes_copied" .= parAvgBytesCopied+#endif , "par_max_bytes_copied" .= parMaxBytesCopied- ] ++ map (uncurry (.=)) counters +++ ] +++ map (uncurry (.=)) counters ++ map (uncurry (.=)) gauges ++ map (uncurry (.=)) labels @@ -438,7 +484,8 @@ -- | Get a snapshot of all values. Note that we're not guaranteed to -- see a consistent snapshot of the whole map.-readAllRefs :: (Ref r t, A.ToJSON t) => IORef (M.HashMap T.Text r) -> IO [(T.Text, Json)]+readAllRefs :: (Ref r t, A.ToJSON t) => IORef (M.HashMap T.Text r)+ -> IO [(T.Text, Json)] readAllRefs mapRef = do m <- readIORef mapRef forM (M.toList m) $ \ (name, ref) -> do@@ -455,6 +502,17 @@ writeLBS $ A.encode $ A.toJSON $ Group list time {-# INLINABLE serveMany #-} +getGcStats :: IO Stats.GCStats+getGcStats = do+#if MIN_VERSION_base(4,6,0)+ enabled <- Stats.getGCStatsEnabled+ if enabled+ then Stats.getGCStats+ else return emptyGCStats+#else+ Stats.getGCStats+#endif+ -- | Serve all counter, gauges and labels, built-in or not, as a -- nested JSON object. serveAll :: IORef Counters -> IORef Gauges -> IORef Labels -> Snap ()@@ -465,19 +523,20 @@ -- requests ought to go to the 'serveOne' handler. unless (S.null $ rqPathInfo req) pass modifyResponse $ setContentType "application/json"- gcStats <- liftIO Stats.getGCStats+ gcStats <- liftIO getGcStats counterList <- liftIO $ readAllRefs counters gaugeList <- liftIO $ readAllRefs gauges labelList <- liftIO $ readAllRefs labels time <- liftIO getTimeMillis- writeLBS $ A.encode $ A.toJSON $ Stats gcStats counterList gaugeList labelList time+ writeLBS $ A.encode $ A.toJSON $ Stats gcStats counterList gaugeList+ labelList time -- | Serve all counters and gauges, built-in or not, as a flattened -- JSON object. serveCombined :: IORef Counters -> IORef Gauges -> IORef Labels -> Snap () serveCombined counters gauges labels = do modifyResponse $ setContentType "application/json"- gcStats <- liftIO Stats.getGCStats+ gcStats <- liftIO getGcStats counterList <- liftIO $ readAllRefs counters gaugeList <- liftIO $ readAllRefs gauges labelList <- liftIO $ readAllRefs labels@@ -503,7 +562,7 @@ -- Try built-in (e.g. GC) refs case Map.lookup name builtinCounters of Just f -> do- gcStats <- liftIO Stats.getGCStats+ gcStats <- liftIO getGcStats writeBS $ S8.pack $ f gcStats Nothing -> do modifyResponse $ setResponseStatus 404 "Not Found"@@ -531,7 +590,12 @@ , ("gc_wall_seconds" , show . Stats.gcWallSeconds) , ("cpu_seconds" , show . Stats.cpuSeconds) , ("wall_seconds" , show . Stats.wallSeconds)+#if MIN_VERSION_base(4,6,0)+ , ("par_tot_bytes_copied" , show . Stats.parTotBytesCopied)+ , ("par_avg_bytes_copied" , show . Stats.parTotBytesCopied)+#else , ("par_avg_bytes_copied" , show . Stats.parAvgBytesCopied)+#endif , ("par_max_bytes_copied" , show . Stats.parMaxBytesCopied) ] @@ -542,8 +606,7 @@ toJSON (Json x) = A.toJSON x -- | Partition GC statistics into counters and gauges.-partitionGcStats :: Stats.GCStats- -> ([(T.Text, Json)], [(T.Text, Json)])+partitionGcStats :: Stats.GCStats -> ([(T.Text, Json)], [(T.Text, Json)]) partitionGcStats (Stats.GCStats {..}) = (counters, gauges) where counters = [@@ -565,7 +628,12 @@ , ("current_bytes_slop" , Json currentBytesSlop) , ("max_bytes_slop" , Json maxBytesSlop) , ("peak_megabytes_allocated" , Json peakMegabytesAllocated)+#if MIN_VERSION_base(4,6,0)+ , ("par_tot_bytes_copied" , Json parTotBytesCopied)+ , ("par_avg_bytes_copied" , Json parTotBytesCopied)+#else , ("par_avg_bytes_copied" , Json parAvgBytesCopied)+#endif , ("par_max_bytes_copied" , Json parMaxBytesCopied) ]
ekg.cabal view
@@ -1,5 +1,5 @@ name: ekg-version: 0.3.1.1+version: 0.3.1.2 synopsis: Remote monitoring of processes description: This library lets you remotely monitor a running process over HTTP.