packages feed

distributed-process-ekg (empty) → 0.1.0.0

raw patch · 6 files changed

+144/−0 lines, 6 filesdep +basedep +distributed-processdep +ekg-coresetup-changed

Dependencies added: base, distributed-process, ekg-core, text, unordered-containers

Files

+ CHANGELOG.md view
@@ -0,0 +1,13 @@+# Change Log++All notable changes to this project will be documented in this file.+This project adheres to [Semantic Versioning](http://semver.org/).++## [0.1.0.0] - 2016-02-27++### Added++- registerLocalNodeMetrics++[0.1.0.0]: https://bitbucket.org/dpwiz/distributed-process-ekg/commits/tag/0.1.0.0+
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Alexander Bondarenko (c) 2016++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Author name here nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,25 @@+1) Register node stats with EKG.++``` haskell++import System.Metrics                    -- ekg-core+import System.Metrics.DistributedProcess -- distributed-process-ekg+import System.Remote.Monitoring.Statsd   -- ekg-statsd++main = do+  -- ... init node++  store <- newStore+  registerGcMetrics store+  registerLocalNodeMetrics node store++  forkStatsd+    defaultStatsdOptions { flushInterval = 15e3 }+    store++  runProcess node procMain+```++2) Discover monitor leaks in your code.++![screenshot](https://i.imgur.com/5AeBIGG.png "collected and rendered in datadog")
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ distributed-process-ekg.cabal view
@@ -0,0 +1,36 @@+-- This file has been generated from package.yaml by hpack version 0.9.1.+--+-- see: https://github.com/sol/hpack++name:                distributed-process-ekg+version:             0.1.0.0+synopsis:            Collect node stats for EKG+category:            System, Network+license:             BSD3+license-file:        LICENSE+maintainer:          Alexander Bondarenko <aenor.realm@gmail.com>+build-type:          Simple+cabal-version:       >= 1.10++extra-source-files:+    CHANGELOG.md+    README.md++library+  hs-source-dirs:+      src+  ghc-options: -Wall+  build-depends:+      base >= 4.8 && < 5+    , text+    , unordered-containers+    , distributed-process+    , ekg-core+  exposed-modules:+      System.Metrics.DistributedProcess+  default-language: Haskell2010++source-repository head+  type: git+  location: https://bitbucket.org/dpwiz/distributed-process-ekg+
+ src/System/Metrics/DistributedProcess.hs view
@@ -0,0 +1,38 @@+module System.Metrics.DistributedProcess+    ( registerLocalNodeMetrics+    ) where++import Control.Concurrent.MVar          (newEmptyMVar, putMVar, takeMVar)+import Control.Distributed.Process      (NodeStats (..), getLocalNodeStats,+                                         liftIO)+import Control.Distributed.Process.Node (LocalNode, runProcess)+import System.Metrics                   (Store, Value (..), registerGroup)++import qualified Data.HashMap.Strict as HM+import qualified Data.Text           as T++registerLocalNodeMetrics :: LocalNode -> Store -> IO ()+registerLocalNodeMetrics node = registerGroup stats sample+  where+    sample :: IO NodeStats+    sample = do+      s <- newEmptyMVar+      runProcess node+        (getLocalNodeStats >>= liftIO . putMVar s)+      takeMVar s++    stats :: HM.HashMap T.Text (NodeStats -> Value)+    stats = HM.fromList+      [ ( T.pack "dp.node.reg_names"+        , Gauge . fromIntegral . nodeStatsRegisteredNames+        )+      , ( T.pack "dp.node.monitors"+        , Gauge . fromIntegral . nodeStatsMonitors+        )+      , ( T.pack "dp.node.links"+        , Gauge . fromIntegral . nodeStatsLinks+        )+      , ( T.pack "dp.node.processes"+        , Gauge . fromIntegral . nodeStatsProcesses+        )+      ]