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 extra-source-files: CHANGELOG.md
common deps 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 ghc-options: -Wall -Wpartial-fields

View file

@ -35,6 +35,7 @@ import qualified Network.HTTP.Types as HTTPT
import System.Random import System.Random
import Text.Read (readEither) import Text.Read (readEither)
import Formatting (float, format, (%), fixed)
import qualified Network.Wai.Handler.Warp as Warp import qualified Network.Wai.Handler.Warp as Warp
import Servant import Servant
import Servant.Client import Servant.Client
@ -113,7 +114,10 @@ instance DHT d => Service PostService d where
port' = fromIntegral (confServicePort conf) port' = fromIntegral (confServicePort conf)
warpSettings = Warp.setPort port' . Warp.setHost (fromString . confServiceHost $ conf) $ Warp.defaultSettings warpSettings = Warp.setPort port' . Warp.setHost (fromString . confServiceHost $ conf) $ Warp.defaultSettings
-- log a start message, this also truncates existing files -- 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 -- Run 'concurrently_' from another thread to be able to return the
-- 'PostService'. -- 'PostService'.
-- Terminating that parent thread will make all child threads terminate as well. -- 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 -- format: total relayReceiveRates;total relayDeliveryRates;postFetchRate;postPublishRate
-- later: current (reported) load, target load -- later: current (reported) load, target load
TxtI.appendFile (confLogfilePath . serviceConf $ serv) $ TxtI.appendFile (confLogfilePath . serviceConf $ serv) $
Txt.intercalate ";" (Txt.pack <$> ( format ((fixed 20) % ";" % (fixed 20) % ";" % (fixed 20) % ";" % (fixed 20) % "\n")
[ show . sum . relayReceiveRates (sum . relayReceiveRates $ rateStats)
, show . sum . relayDeliveryRates (sum . relayDeliveryRates $ rateStats)
, show . postPublishRate (postPublishRate rateStats)
, show . postFetchRate (postFetchRate rateStats)
] <*> pure rateStats)) <> "\n"
loop now loop now