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

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

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