Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

[CSL-1585] Namespace cardano EKG metrics #1464

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions node/src/Pos/Launcher/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import Node (Node, NodeAction (..), NodeEnd
node, simpleNodeEndPoint)
import qualified Node.Conversation as N (Conversation, Converse,
converseWith)
import Pos.Util.Monitor (setupMonitor, stopMonitor)
import Node.Util.Monitor (registerMetrics)
import Pos.System.Metrics.Constants (cardanoNamespace)
import Pos.Util.Monitor (stopMonitor)
import qualified System.Metrics as Metrics
import System.Random (newStdGen)
import qualified System.Remote.Monitoring.Statsd as Monitoring
Expand Down Expand Up @@ -122,8 +124,8 @@ runRealModeDo NodeResources {..} outSpecs action =
case npEnableMetrics of
False -> return Nothing
True -> Just <$> do
ekgStore' <- setupMonitor
(runProduction . runToProd JsonLogDisabled oq) node' nrEkgStore
let ekgStore' = nrEkgStore
registerMetrics (Just cardanoNamespace) (runProduction . runToProd JsonLogDisabled oq) node' ekgStore'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need ekgStore' any more. It was only there because the old setupMonitor returned a possibly modified store, and no it doesn't, so there's no need to name the result.

liftIO $ Metrics.registerGcMetrics ekgStore'
mEkgServer <- case npEkgParams of
Nothing -> return Nothing
Expand Down
37 changes: 5 additions & 32 deletions node/src/Pos/Util/Monitor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

module Pos.Util.Monitor (

setupMonitor
, startMonitor
startMonitor
, stopMonitor

) where
Expand All @@ -16,40 +15,14 @@ import Control.Monad.IO.Class
import Mockable.Class
import qualified Mockable.Metrics as Metrics
import Node
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports should be qualified or contain explicit import list, according to style-guide.

import Pos.System.Metrics.Constants (withCardanoNamespace)
import Node.Util.Monitor (registerMetrics)
import Pos.System.Metrics.Constants (cardanoNamespace)
import qualified System.Metrics as Monitoring
import qualified System.Metrics.Distribution as Monitoring.Distribution
import qualified System.Remote.Monitoring.Wai as Monitoring

import Universum

-- | Put time-warp related metrics into an EKG store.
-- You must indicate how to run the monad into IO, so that EKG can produce
-- the metrics (it works in IO).
setupMonitor
:: ( Mockable Metrics.Metrics m
, Metrics.Distribution m ~ Monitoring.Distribution.Distribution
, MonadIO m
)
=> (forall t . m t -> IO t)
-> Node m
-> Monitoring.Store
-> m Monitoring.Store
setupMonitor lowerIO node store = do
liftIO $ flip (Monitoring.registerGauge (withCardanoNamespace "handlers.initiated_remotely")) store $ lowerIO $ do
stats <- nodeStatistics node
Metrics.readGauge (stRunningHandlersRemote stats)
liftIO $ flip (Monitoring.registerGauge (withCardanoNamespace "handlers.initiated_locally")) store $ lowerIO $ do
stats <- nodeStatistics node
Metrics.readGauge (stRunningHandlersLocal stats)
liftIO $ flip (Monitoring.registerDistribution (withCardanoNamespace "handlers.finished_normally.elapsed_time_microseconds")) store $ lowerIO $ do
stats <- nodeStatistics node
liftIO $ Monitoring.Distribution.read (stHandlersFinishedNormally stats)
liftIO $ flip (Monitoring.registerDistribution (withCardanoNamespace "handlers.finished_exceptionally.elapsed_time_microseconds")) store $ lowerIO $ do
stats <- nodeStatistics node
liftIO $ Monitoring.Distribution.read (stHandlersFinishedExceptionally stats)
return store

startMonitor
:: ( Mockable Metrics.Metrics m
, Metrics.Distribution m ~ Monitoring.Distribution.Distribution
Expand All @@ -61,8 +34,8 @@ startMonitor
-> m Monitoring.Server
startMonitor port lowerIO node = do
store <- liftIO Monitoring.newStore
store' <- setupMonitor lowerIO node store
liftIO $ Monitoring.registerGcMetrics store'
registerMetrics (Just cardanoNamespace) lowerIO node store
liftIO $ Monitoring.registerGcMetrics store
server <- liftIO $ Monitoring.forkServerWith store "127.0.0.1" port
liftIO . putStrLn $ "Forked EKG server on port " ++ show port
return server
Expand Down
Loading