properly format stats log numbers: no e-notation

This commit is contained in:
Trolli Schmittlauch 2020-09-10 23:54:51 +02:00
parent 0f9727c05a
commit e12d8ef70a
2 changed files with 11 additions and 8 deletions

View file

@ -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