local prometheus = require("utils.prometheus") local metrics_pole = require('prototypes.metrics-pole') local M = {} --- @param metrics_table table --- @param surface LuaSurface --- @param force LuaForce --- @return fun() function M.calc_item_production_statistics(metrics_table, surface, force) return function() local item_stats = force.get_item_production_statistics(surface.name) for item, count in pairs(item_stats.input_counts) do table.insert(metrics_table, prometheus.counter("production", "", { type = "item", surface = surface.name, force = force.name, name = item }, count)) end for item, count in pairs(item_stats.output_counts) do table.insert(metrics_table, prometheus.counter("consumption", "", { type = "item", surface = surface.name, force = force.name, name = item }, count)) end end end --- @param metrics_table table --- @param surface LuaSurface --- @param force LuaForce --- @return fun() function M.calc_fluid_production_statistics(metrics_table, surface, force) return function() local fluid_stats = force.get_fluid_production_statistics(surface.name) for item, count in pairs(fluid_stats.input_counts) do table.insert(metrics_table, prometheus.counter("production", "", { type = "fluid", surface = surface.name, force = force.name, name = item }, count)) end for item, count in pairs(fluid_stats.output_counts) do table.insert(metrics_table, prometheus.counter("consumption", "", { type = "fluid", surface = surface.name, force = force.name, name = item }, count)) end end end --- @param metrics_table table --- @param surface LuaSurface --- @return fun() function M.calc_power_statistics(metrics_table, surface) return function() local seen = {} for _, pole in pairs(surface.find_entities_filtered { name = metrics_pole.name }) do if table[pole.electric_network_id] then -- deduplication goto continue end table.insert(seen, pole.electric_network_id) local stats = pole.electric_network_statistics for name, count in pairs(stats.input_counts) do table.insert(metrics_table, prometheus.counter("energy_consumption", "_joules", { surface = surface.name, network_id = pole.electric_network_id, name = name }, count)) end for name, count in pairs(stats.output_counts) do table.insert(metrics_table, prometheus.counter("energy_production", "_joules", { surface = surface.name, network_id = pole.electric_network_id, name = name }, count)) end ::continue:: end end end return M