diff --git a/bench/ekg-restart-test/app/Main.hs b/bench/ekg-restart-test/app/Main.hs index 3dffaee0bef..dc7b69fb1d1 100644 --- a/bench/ekg-restart-test/app/Main.hs +++ b/bench/ekg-restart-test/app/Main.hs @@ -27,11 +27,13 @@ import Network.Wai import Network.Wai.Handler.Warp import Network.Wai.Handler.Warp import System.Metrics +import System.Random import Network.Wai.Middleware.RequestLogger import System.Remote.Monitoring.Wai import Network.HTTP.Types import qualified Data.Map as Map import Data.Map (Map) +import Data.Time.Clock.POSIX (getPOSIXTime) main = m 8000 @@ -44,12 +46,31 @@ connectedNodes = unsafePerformIO do m :: Int -> IO () m port = do - stores :: [Store] <- - replicateM 5 newStore - say - "run port" + stores :: [Store] <- genStores 5 + + say $ + "run port: " ++ show port + run port do logStdout do app stores + --_ <- forkServerWith (head stores) "localhost" port + --forever $ threadDelay $ 1000 * 1000 + + +genStores :: Int -> IO [Store] +genStores count = do + mapM genStore [1 .. fromIntegral count] + where + getTimeMs = (round . (* 1000)) `fmap` getPOSIXTime + + genStore ix = do + let base = ix * 1000 + s <- newStore + registerCounter "ekg.server_timestamp_ms" getTimeMs s + registerGauge "myval" ((base +) <$> randomRIO (1, 10)) s + pure s + + app :: [Store] -> Application app stores req send = do let @@ -59,15 +80,15 @@ app stores req send = do print (queryString req) case pathInfo req of - [] -> do - print req - monitor (stores !! 2) req send + [] -> + -- ok "Home page" + monitor (head stores) req send ["0"] -> do ok "/0" ["1"] -> ok "/1" - ["2"] -> monitor (stores !! 2) req send - ["3"] -> monitor (stores !! 3) req send - ["4"] -> monitor (stores !! 4) req send + ["2"] -> monitor (stores !! 2) req { pathInfo = tail (pathInfo req) } send + ["3"] -> monitor (stores !! 3) req { pathInfo = tail (pathInfo req) } send + ["4"] -> monitor (stores !! 4) req { pathInfo = tail (pathInfo req) } send path -> send do responseBuilder do status404 diff --git a/bench/ekg-restart-test/ekg-restart-test.cabal b/bench/ekg-restart-test/ekg-restart-test.cabal index 1afab1fa085..2f3eb0bc2a4 100644 --- a/bench/ekg-restart-test/ekg-restart-test.cabal +++ b/bench/ekg-restart-test/ekg-restart-test.cabal @@ -23,7 +23,7 @@ extra-source-files: CHANGELOG.md executable ekg-restart-test main-is: Main.hs - other-modules: + -- other-modules: ImportHidden -- Modules included in this executable, other than Main. -- other-modules: @@ -48,7 +48,7 @@ executable ekg-restart-test , text , containers , unordered-containers - ghc-options: -threaded + ghc-options: -threaded "-with-rtsopts=-T" hs-source-dirs: app default-language: Haskell2010