-
Notifications
You must be signed in to change notification settings - Fork 22
/
control.lua
201 lines (165 loc) · 8.45 KB
/
control.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
prometheus = require("prometheus/prometheus")
require("train")
require("yarm")
require("events")
require("power")
require("research")
bucket_settings = train_buckets(settings.startup["graftorio2-train-histogram-buckets"].value)
nth_tick = settings.startup["graftorio2-nth-tick"].value
server_save = settings.startup["graftorio2-server-save"].value
disable_train_stats = settings.startup["graftorio2-disable-train-stats"].value
gauge_tick = prometheus.gauge("factorio_tick", "game tick")
gauge_connected_player_count = prometheus.gauge("factorio_connected_player_count", "connected players")
gauge_total_player_count = prometheus.gauge("factorio_total_player_count", "total registered players")
gauge_seed = prometheus.gauge("factorio_seed", "seed", { "surface" })
gauge_mods = prometheus.gauge("factorio_mods", "mods", { "name", "version" })
gauge_item_production_input = prometheus.gauge("factorio_item_production_input", "items produced", { "force", "name" })
gauge_item_production_output =
prometheus.gauge("factorio_item_production_output", "items consumed", { "force", "name" })
gauge_fluid_production_input =
prometheus.gauge("factorio_fluid_production_input", "fluids produced", { "force", "name" })
gauge_fluid_production_output =
prometheus.gauge("factorio_fluid_production_output", "fluids consumed", { "force", "name" })
gauge_kill_count_input = prometheus.gauge("factorio_kill_count_input", "kills", { "force", "name" })
gauge_kill_count_output = prometheus.gauge("factorio_kill_count_output", "losses", { "force", "name" })
gauge_entity_build_count_input =
prometheus.gauge("factorio_entity_build_count_input", "entities placed", { "force", "name" })
gauge_entity_build_count_output =
prometheus.gauge("factorio_entity_build_count_output", "entities removed", { "force", "name" })
gauge_pollution_production_input =
prometheus.gauge("factorio_pollution_production_input", "pollutions produced", { "force", "name" })
gauge_pollution_production_output =
prometheus.gauge("factorio_pollution_production_output", "pollutions consumed", { "force", "name" })
gauge_evolution = prometheus.gauge("factorio_evolution", "evolution", { "force", "type" })
gauge_research_queue = prometheus.gauge("factorio_research_queue", "research", { "force", "name", "level", "index" })
gauge_items_launched =
prometheus.gauge("factorio_items_launched_total", "items launched in rockets", { "force", "name" })
gauge_yarm_site_amount =
prometheus.gauge("factorio_yarm_site_amount", "YARM - site amount remaining", { "force", "name", "type" })
gauge_yarm_site_ore_per_minute =
prometheus.gauge("factorio_yarm_site_ore_per_minute", "YARM - site ore per minute", { "force", "name", "type" })
gauge_yarm_site_remaining_permille = prometheus.gauge(
"factorio_yarm_site_remaining_permille",
"YARM - site permille remaining",
{ "force", "name", "type" }
)
gauge_train_trip_time = prometheus.gauge("factorio_train_trip_time", "train trip time", { "from", "to", "train_id" })
gauge_train_wait_time = prometheus.gauge("factorio_train_wait_time", "train wait time", { "from", "to", "train_id" })
histogram_train_trip_time = prometheus.histogram(
"factorio_train_trip_time_groups",
"train trip time",
{ "from", "to", "train_id" },
bucket_settings
)
histogram_train_wait_time = prometheus.histogram(
"factorio_train_wait_time_groups",
"train wait time",
{ "from", "to", "train_id" },
bucket_settings
)
gauge_train_direct_loop_time =
prometheus.gauge("factorio_train_direct_loop_time", "train direct loop time", { "a", "b" })
histogram_train_direct_loop_time = prometheus.histogram(
"factorio_train_direct_loop_time_groups",
"train direct loop time",
{ "a", "b" },
bucket_settings
)
gauge_train_arrival_time = prometheus.gauge("factorio_train_arrival_time", "train arrival time", { "station" })
histogram_train_arrival_time =
prometheus.histogram("factorio_train_arrival_time_groups", "train arrival time", { "station" }, bucket_settings)
gauge_logistic_network_all_construction_robots = prometheus.gauge(
"factorio_logistic_network_all_construction_robots",
"the total number of construction robots in the network (idle and active + in roboports)",
{ "force", "location", "network" }
)
gauge_logistic_network_available_construction_robots = prometheus.gauge(
"factorio_logistic_network_available_construction_robots",
"the number of construction robots available for a job",
{ "force", "location", "network" }
)
gauge_logistic_network_all_logistic_robots = prometheus.gauge(
"factorio_logistic_network_all_logistic_robots",
"the total number of logistic robots in the network (idle and active + in roboports)",
{ "force", "location", "network" }
)
gauge_logistic_network_available_logistic_robots = prometheus.gauge(
"factorio_logistic_network_available_logistic_robots",
"the number of logistic robots available for a job",
{ "force", "location", "network" }
)
gauge_logistic_network_robot_limit = prometheus.gauge(
"factorio_logistic_network_robot_limit",
"the maximum number of robots the network can work with",
{ "force", "location", "network" }
)
gauge_logistic_network_items = prometheus.gauge(
"factorio_logistic_network_items",
"the number of items in a logistic network",
{ "force", "location", "network", "name" }
)
gauge_power_production_input =
prometheus.gauge("factorio_power_production_input", "power produced", { "force", "name", "network", "surface" })
gauge_power_production_output =
prometheus.gauge("factorio_power_production_output", "power consumed", { "force", "name", "network", "surface" })
script.on_init(function()
if game.active_mods["YARM"] then
global.yarm_on_site_update_event_id = remote.call("YARM", "get_on_site_updated_event_id")
script.on_event(global.yarm_on_site_update_event_id, handleYARM)
end
on_power_init()
script.on_nth_tick(nth_tick, register_events)
script.on_event(defines.events.on_player_joined_game, register_events_players)
script.on_event(defines.events.on_player_left_game, register_events_players)
script.on_event(defines.events.on_player_removed, register_events_players)
script.on_event(defines.events.on_player_kicked, register_events_players)
script.on_event(defines.events.on_player_banned, register_events_players)
-- train envents
if not disable_train_stats then
script.on_event(defines.events.on_train_changed_state, register_events_train)
end
-- power events
script.on_event(defines.events.on_built_entity, on_power_build)
script.on_event(defines.events.on_robot_built_entity, on_power_build)
script.on_event(defines.events.script_raised_built, on_power_build)
script.on_event(defines.events.on_player_mined_entity, on_power_destroy)
script.on_event(defines.events.on_robot_mined_entity, on_power_destroy)
script.on_event(defines.events.on_entity_died, on_power_destroy)
script.on_event(defines.events.script_raised_destroy, on_power_destroy)
-- research events
script.on_event(defines.events.on_research_finished, on_research_finished)
end)
script.on_load(function()
if global.yarm_on_site_update_event_id then
if script.get_event_handler(global.yarm_on_site_update_event_id) then
script.on_event(global.yarm_on_site_update_event_id, handleYARM)
end
end
on_power_load()
script.on_nth_tick(nth_tick, register_events)
script.on_event(defines.events.on_player_joined_game, register_events_players)
script.on_event(defines.events.on_player_left_game, register_events_players)
script.on_event(defines.events.on_player_removed, register_events_players)
script.on_event(defines.events.on_player_kicked, register_events_players)
script.on_event(defines.events.on_player_banned, register_events_players)
-- train events
if not disable_train_stats then
script.on_event(defines.events.on_train_changed_state, register_events_train)
end
-- power events
script.on_event(defines.events.on_built_entity, on_power_build)
script.on_event(defines.events.on_robot_built_entity, on_power_build)
script.on_event(defines.events.script_raised_built, on_power_build)
script.on_event(defines.events.on_player_mined_entity, on_power_destroy)
script.on_event(defines.events.on_robot_mined_entity, on_power_destroy)
script.on_event(defines.events.on_entity_died, on_power_destroy)
script.on_event(defines.events.script_raised_destroy, on_power_destroy)
-- research events
script.on_event(defines.events.on_research_finished, on_research_finished)
end)
script.on_configuration_changed(function(event)
if game.active_mods["YARM"] then
global.yarm_on_site_update_event_id = remote.call("YARM", "get_on_site_updated_event_id")
script.on_event(global.yarm_on_site_update_event_id, handleYARM)
end
end)