Fixes and performance improvements
This commit is contained in:
55
control.lua
55
control.lua
@@ -1,13 +1,27 @@
|
||||
require("game-stats")
|
||||
require("production-stats")
|
||||
require("pollution-stats")
|
||||
require("research-stats")
|
||||
require("power-stats")
|
||||
require("storage")
|
||||
|
||||
tickInterval = tonumber(settings.global["factorio-prometheus-exporter-tick-interval"].value) or 300
|
||||
udpAddress = tonumber(settings.startup["factorio-prometheus-exporter-udp-address"].value) or 52555
|
||||
|
||||
serverIndex = 1
|
||||
if game.is_multiplayer() then
|
||||
serverIndex = 0
|
||||
end
|
||||
|
||||
script.on_init(function ()
|
||||
storage.researchedTechnologies = {}
|
||||
storage.playerDeathCount = {}
|
||||
end)
|
||||
|
||||
script.on_load(function ()
|
||||
log("factorio-prometheus-exporter: on_load")
|
||||
log("tickInterval: "..tickInterval)
|
||||
log("udpAddress: "..udpAddress)
|
||||
|
||||
end)
|
||||
|
||||
|
||||
|
||||
-- Register the handler for the player movement event
|
||||
--script.on_event(defines.events.on_player_changed_position, on_player_moved)
|
||||
@@ -30,13 +44,40 @@ script.on_event(defines.events.on_runtime_mod_setting_changed, function(event)
|
||||
end
|
||||
end)
|
||||
|
||||
function SendStats(event)
|
||||
if(event.tick % (tickInterval) ~= 0) then
|
||||
return
|
||||
end
|
||||
SendProductionStats()
|
||||
SendFluidProductionStats()
|
||||
SendPollutionStats()
|
||||
SendKillStats()
|
||||
end
|
||||
|
||||
|
||||
function SendGameStats(event)
|
||||
if(event.tick % (tickInterval*2) ~= 0) then
|
||||
return
|
||||
end
|
||||
local returnParts = {}
|
||||
returnParts[#returnParts+1] = GetMods()
|
||||
returnParts[#returnParts+1] = GetMapSeed()
|
||||
returnParts[#returnParts+1] = GetRocketsLaunched()
|
||||
returnParts[#returnParts+1] = GetPlayerTime()
|
||||
returnParts[#returnParts+1] = GetPlayerDeaths()
|
||||
helpers.send_udp(udpAddress, table.concat(returnParts, "\n"), serverIndex)
|
||||
end
|
||||
|
||||
function SendAll(event)
|
||||
SendStats(event)
|
||||
SendGameStats(event)
|
||||
end
|
||||
|
||||
--script.on_event(defines.events.on_player_joined_game, on_player_joined)
|
||||
--script.on_nth_tick(300, SendSurfaceStats)
|
||||
--script.on_event(defines.events.on_tick, SendSurfaceStats)
|
||||
script.on_nth_tick(tickInterval, SendProductionStats)
|
||||
script.on_nth_tick(tickInterval, SendFluidProductionStats)
|
||||
script.on_nth_tick(tickInterval, GetPollutionStats)
|
||||
script.on_event(defines.events.on_tick, SendAll)
|
||||
--script.on_nth_tick(tickInterval*2, SendGameStats)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user