Private
Public Access
1
0
Files
lua-prometheus-exporter/logistic-network-stats.lua
2026-01-10 18:24:52 +01:00

45 lines
1.7 KiB
Lua

function GetAllLogisticGrids()
local resultParts = {}
resultParts[#resultParts+1] = "---logistic-grids---\n"
for _,surface in pairs(game.surfaces) do
local grids = game.forces["player"].logistic_networks[surface.name]
for _,grid in pairs(grids) do
resultParts[#resultParts+1] = ("%s:%d:%d:%d:%d:%d:%d"):format(
surface.name,
grid.network_id,
grid.all_construction_robots,
grid.all_logistic_robots,
grid.available_construction_robots,
grid.available_logistic_robots,
grid.robot_limit)
end
end
return table.concat(resultParts, "\n")
end
function GetLogisticNetworkContents()
local resultParts = {}
resultParts[#resultParts+1] = "---logistic-grids-contents---\n"
for _,surface in pairs(game.surfaces) do
local grids = game.forces["player"].logistic_networks[surface.name]
for _,grid in pairs(grids) do
for _,itemWithQuality in pairs(grid.get_contents())do
resultParts[#resultParts+1] = ("%s:%d:%s:%d"):format(surface.name,grid.network_id,itemWithQuality.name..":"..itemWithQuality.quality,itemWithQuality.count)
end
end
end
return table.concat(resultParts, "\n")
end
function SendLogisticStats()
if options.enableRobots then
local returnParts = {}
returnParts[#returnParts+1] = GetAllLogisticGrids()
returnParts[#returnParts+1] = GetLogisticNetworkContents()
log("Table size logistics "..table_size(returnParts))
log("Sending logistics")
--local send = GetAllLogisticGrids().."\n"..GetLogisticNetworkContents()
SendChunked(table.concat(returnParts,"\n"))
end
end