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

Commit

Permalink
[CSL-1585] Namespace cardano EKG metrics (#1464)
Browse files Browse the repository at this point in the history
[CSL-1585] Namespace all the relevant IOHK's EKG metrics
  • Loading branch information
adinapoli-iohk authored Sep 1, 2017
1 parent 86e0787 commit ee50e1d
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 229 deletions.
12 changes: 12 additions & 0 deletions core/Pos/System/Metrics/Constants.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Pos.System.Metrics.Constants (
cardanoNamespace
, withCardanoNamespace
) where

import Universum

cardanoNamespace :: Text
cardanoNamespace = "cardano"

withCardanoNamespace :: Text -> Text
withCardanoNamespace label = cardanoNamespace <> "." <> label
2 changes: 2 additions & 0 deletions core/cardano-sl-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ library
Pos.Binary.Core.Version
Pos.Binary.Core.Genesis

Pos.System.Metrics.Constants

Pos.Util.Arbitrary
Pos.Util.Concurrent
Pos.Util.Concurrent.LockedTVar
Expand Down
9 changes: 5 additions & 4 deletions infra/Pos/Network/Types.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE CPP #-}

#if !defined(mingw32_HOST_OS)
#define POSIX
Expand Down Expand Up @@ -57,13 +57,14 @@ import Node.Internal (NodeId (..))
import Pos.Network.DnsDomains (DnsDomains (..))
import qualified Pos.Network.DnsDomains as DnsDomains
import qualified Pos.Network.Policy as Policy
import Pos.System.Metrics.Constants (cardanoNamespace)
import Pos.Util.TimeWarp (addressToNodeId)
import qualified System.Metrics as Monitoring
import System.Wlog.CanLog (WithLogger)
import Universum hiding (show)

#if !defined(POSIX)
import qualified Pos.Network.Windows.DnsDomains as Win
import qualified Pos.Network.Windows.DnsDomains as Win
#endif

{-------------------------------------------------------------------------------
Expand Down Expand Up @@ -290,7 +291,7 @@ topologyMaxBucketSize topology bucket =
BucketSubscriptionListener ->
case topologySubscribers topology of
Just (_subscriberType, maxBucketSize) -> maxBucketSize
Nothing -> OQ.BucketSizeMax 0 -- subscription not allowed
Nothing -> OQ.BucketSizeMax 0 -- subscription not allowed
_otherBucket ->
OQ.BucketSizeUnlimited

Expand Down Expand Up @@ -339,7 +340,7 @@ initQueue NetworkConfig{..} mStore = do

case mStore of
Nothing -> return () -- EKG store not used
Just store -> liftIO $ OQ.registerQueueMetrics oq store
Just store -> liftIO $ OQ.registerQueueMetrics (Just (toString cardanoNamespace)) oq store

case ncTopology of
TopologyLightWallet peers -> do
Expand Down
3 changes: 2 additions & 1 deletion node/cardano-sl.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ library
-- Utilities/helpers
Pos.Util
Pos.Util.LoggerName
Pos.Util.Monitor
Pos.Util.Undefined
Pos.Util.BackupPhrase
Pos.Util.JsonLog
Expand Down Expand Up @@ -358,7 +359,7 @@ library
, dlist
, dns
, ed25519
, ekg
, ekg-wai
, ekg-core
, ekg-statsd
, ether >= 0.5
Expand Down
15 changes: 8 additions & 7 deletions node/src/Pos/Launcher/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ import Node (Node, NodeAction (..), NodeEnd
node, simpleNodeEndPoint)
import qualified Node.Conversation as N (Conversation, Converse,
converseWith)
import Node.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 as Monitoring
import qualified System.Remote.Monitoring.Statsd as Monitoring
import qualified System.Remote.Monitoring.Wai as Monitoring
import System.Wlog (WithLogger, logInfo)

import Pos.Binary ()
Expand Down Expand Up @@ -122,13 +124,12 @@ runRealModeDo NodeResources {..} outSpecs action =
case npEnableMetrics of
False -> return Nothing
True -> Just <$> do
ekgStore' <- setupMonitor
(runProduction . runToProd JsonLogDisabled oq) node' nrEkgStore
liftIO $ Metrics.registerGcMetrics ekgStore'
registerMetrics (Just cardanoNamespace) (runProduction . runToProd JsonLogDisabled oq) node' nrEkgStore
liftIO $ Metrics.registerGcMetrics nrEkgStore
mEkgServer <- case npEkgParams of
Nothing -> return Nothing
Just (EkgParams {..}) -> Just <$> do
liftIO $ Monitoring.forkServerWith ekgStore' ekgHost ekgPort
liftIO $ Monitoring.forkServerWith nrEkgStore ekgHost ekgPort
mStatsdServer <- case npStatsdParams of
Nothing -> return Nothing
Just (StatsdParams {..}) -> Just <$> do
Expand All @@ -140,7 +141,7 @@ runRealModeDo NodeResources {..} outSpecs action =
, Monitoring.prefix = statsdPrefix
, Monitoring.suffix = statsdSuffix
}
liftIO $ Monitoring.forkStatsd statsdOptions ekgStore'
liftIO $ Monitoring.forkStatsd statsdOptions nrEkgStore
return (mEkgServer, mStatsdServer)

stopMonitoring Nothing = return ()
Expand Down
46 changes: 46 additions & 0 deletions node/src/Pos/Util/Monitor.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}

module Pos.Util.Monitor (

startMonitor
, stopMonitor

) where

import Control.Concurrent (killThread)
import Control.Monad.IO.Class (MonadIO)
import Mockable.Class (Mockable)
import qualified Mockable.Metrics as Metrics
import Node (Node)
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

startMonitor
:: ( Mockable Metrics.Metrics m
, Metrics.Distribution m ~ Monitoring.Distribution.Distribution
, MonadIO m
)
=> Int
-> (forall t . m t -> IO t)
-> Node m
-> m Monitoring.Server
startMonitor port lowerIO node = do
store <- liftIO Monitoring.newStore
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

stopMonitor
:: ( MonadIO m )
=> Monitoring.Server
-> m ()
stopMonitor server = liftIO $ killThread (Monitoring.serverThreadId server)
Loading

0 comments on commit ee50e1d

Please sign in to comment.