diff --git a/Hash2Pub.cabal b/Hash2Pub.cabal index f7a1676..92ec096 100644 --- a/Hash2Pub.cabal +++ b/Hash2Pub.cabal @@ -46,7 +46,7 @@ category: Network extra-source-files: CHANGELOG.md common deps - build-depends: base ^>=4.12.0.0, containers ^>=0.6.0.1, bytestring, utf8-string ^>=1.0.1.1, network ^>=2.8.0.1, time ^>=1.8.0.2, cmdargs ^>= 0.10, cryptonite ^>= 0.25, memory, async, stm, asn1-encoding, asn1-types, asn1-parse, publicsuffix, network-byte-order, safe, iproute, mtl, random, servant, servant-server, servant-client, warp, text, unordered-containers, hashable, unicode-transforms, http-client, http-types, unbounded-delays, dlist + build-depends: base ^>=4.12.0.0, containers ^>=0.6.0.1, bytestring, utf8-string ^>=1.0.1.1, network ^>=2.8.0.1, time ^>=1.8.0.2, cmdargs ^>= 0.10, cryptonite ^>= 0.25, memory, async, stm, asn1-encoding, asn1-types, asn1-parse, publicsuffix, network-byte-order, safe, iproute, mtl, random, servant, servant-server, servant-client, warp, text, unordered-containers, hashable, unicode-transforms, http-client, http-types, unbounded-delays, dlist, formatting ghc-options: -Wall -Wpartial-fields diff --git a/src/Hash2Pub/PostService.hs b/src/Hash2Pub/PostService.hs index 2170945..662b0a1 100644 --- a/src/Hash2Pub/PostService.hs +++ b/src/Hash2Pub/PostService.hs @@ -35,6 +35,7 @@ import qualified Network.HTTP.Types as HTTPT import System.Random import Text.Read (readEither) +import Formatting (float, format, (%), fixed) import qualified Network.Wai.Handler.Warp as Warp import Servant import Servant.Client @@ -113,7 +114,10 @@ instance DHT d => Service PostService d where port' = fromIntegral (confServicePort conf) warpSettings = Warp.setPort port' . Warp.setHost (fromString . confServiceHost $ conf) $ Warp.defaultSettings -- log a start message, this also truncates existing files - TxtI.writeFile (confLogfilePath conf) "# Starting mock relay implementation\n" + TxtI.writeFile (confLogfilePath conf) $ Txt.unlines + [ "# Starting mock relay implementation\n" + , "#relay receive rate ;relay delivery rate ;instance publish rate ;instance fetch rate" + ] -- Run 'concurrently_' from another thread to be able to return the -- 'PostService'. -- Terminating that parent thread will make all child threads terminate as well. @@ -813,12 +817,11 @@ evaluateStatsThread serv statsAcc = getPOSIXTime >>= loop -- format: total relayReceiveRates;total relayDeliveryRates;postFetchRate;postPublishRate -- later: current (reported) load, target load TxtI.appendFile (confLogfilePath . serviceConf $ serv) $ - Txt.intercalate ";" (Txt.pack <$> ( - [ show . sum . relayReceiveRates - , show . sum . relayDeliveryRates - , show . postPublishRate - , show . postFetchRate - ] <*> pure rateStats)) <> "\n" + format ((fixed 20) % ";" % (fixed 20) % ";" % (fixed 20) % ";" % (fixed 20) % "\n") + (sum . relayReceiveRates $ rateStats) + (sum . relayDeliveryRates $ rateStats) + (postPublishRate rateStats) + (postFetchRate rateStats) loop now