diff --git a/src/Simplex/Messaging/Server/Env/STM.hs b/src/Simplex/Messaging/Server/Env/STM.hs index 4c0b1d566..79d029a1c 100644 --- a/src/Simplex/Messaging/Server/Env/STM.hs +++ b/src/Simplex/Messaging/Server/Env/STM.hs @@ -62,6 +62,7 @@ module Simplex.Messaging.Server.Env.STM defaultMsgQueueQuota, defMsgExpirationDays, defNtfExpirationHours, + defStatsSaveInterval, defaultMessageExpiration, defaultNtfExpiration, defaultInactiveClientExpiration, @@ -172,6 +173,8 @@ data ServerConfig s = ServerConfig serverStatsLogFile :: FilePath, -- | file to save and restore stats serverStatsBackupFile :: Maybe FilePath, + -- | interval to save stats, seconds + statsSaveInterval :: Int64, -- | interval and file to save prometheus metrics prometheusInterval :: Maybe Int, prometheusMetricsFile :: FilePath, @@ -233,6 +236,9 @@ defaultNtfExpiration = checkInterval = 3600 -- seconds, 1 hour } +defStatsSaveInterval :: Int64 +defStatsSaveInterval = 300 + defaultInactiveClientExpiration :: ExpirationConfig defaultInactiveClientExpiration = ExpirationConfig diff --git a/src/Simplex/Messaging/Server/Main.hs b/src/Simplex/Messaging/Server/Main.hs index 996624838..9cf6c1206 100644 --- a/src/Simplex/Messaging/Server/Main.hs +++ b/src/Simplex/Messaging/Server/Main.hs @@ -495,6 +495,7 @@ smpServerCLI_ generateSite serveStaticFiles attachStaticFiles cfgPath logPath = logStatsStartTime = 0, -- seconds from 00:00 UTC serverStatsLogFile = combine logPath "smp-server-stats.daily.log", serverStatsBackupFile = logStats $> combine logPath "smp-server-stats.log", + statsSaveInterval = readIniDefault defStatsSaveInterval "STORE_LOG" "stats_save_interval" ini, prometheusInterval = eitherToMaybe (lookupValue "STORE_LOG" "prometheus_interval" ini) >>= readMaybe . T.unpack, prometheusMetricsFile = combine logPath "smp-server-metrics.txt", pendingENDInterval = 15000000, -- 15 seconds diff --git a/src/Simplex/Messaging/Server/Main/Init.hs b/src/Simplex/Messaging/Server/Main/Init.hs index a0015b0cf..d08cdf03f 100644 --- a/src/Simplex/Messaging/Server/Main/Init.hs +++ b/src/Simplex/Messaging/Server/Main/Init.hs @@ -104,8 +104,10 @@ iniFileContent cfgPath logPath opts host basicAuth controlPortPwds = <> "# Log daily server statistics to CSV file\n" <> ("log_stats = " <> onOff logStats <> "\n\n") <> "# Log interval for real-time Prometheus metrics\n\ - \# prometheus_interval = 60\n\n\ - \[AUTH]\n\ + \# prometheus_interval = 60\n\n" + <> "# Interval to save server statistics, seconds (requires log_stats)\n" + <> ("# stats_save_interval = " <> tshow defStatsSaveInterval <> "\n\n") + <> "[AUTH]\n\ \# Set new_queues option to off to completely prohibit creating new messaging queues.\n\ \# This can be useful when you want to decommission the server, but not all connections are switched yet.\n\ \new_queues = on\n\n\ diff --git a/tests/SMPClient.hs b/tests/SMPClient.hs index 6d3df8122..9b67be3d1 100644 --- a/tests/SMPClient.hs +++ b/tests/SMPClient.hs @@ -264,6 +264,7 @@ cfgMS msType = withStoreCfg (testServerStoreConfig msType) $ \serverStoreCfg -> logStatsStartTime = 0, serverStatsLogFile = testPath "smp-server-stats.daily.log", serverStatsBackupFile = Nothing, + statsSaveInterval = defStatsSaveInterval, prometheusInterval = Nothing, prometheusMetricsFile = testPrometheusMetricsFile, pendingENDInterval = 500000,