Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prometheus combinator #36

Closed
wants to merge 8 commits into from

Conversation

Zincfox
Copy link
Contributor

@Zincfox Zincfox commented Jul 21, 2024

Adds a new entity (+item+recipe), the prometheus combinator.

When placed it can be configured to export all connected signals (or a single specific one) to a customizable metric.
The metric named entered into the UI is prefixed with factorio_custom_ before being exported, to avoid name clashes with present/future metrics.
Multiple metrics can be created with multiple combinators, but any amount of them can also be configured to export to the same metric, in which case their signals are added together in each export tick.

Each custom metric contains two labels - the signal label, which follows the schema {signal.type}:{signal.name} and the addional group label. Unless enabled in the settings the latter is always "", once enabled it can be used to merge multiple related metrics together.

Example applications:

  • Monitor currently available power capacity with power-combinator and capacity-combinator -> Refined power metrics #21 (the network would probably have to be entered as group-label to allow a join in grafana)
  • Monitor item availability in specific chests / different locations (group-label could be the location)
  • Debug general signals (kind of Exporting signals from circuit networks #29, but I feel exporting all signal in all networks could result in high cardinality - adding the combinator forces the player to be selective and keep cardinality down. The ability to add multiple differently named metrics also helps here)
  • Monitor item throughput on belts (belt-reader on pulse, into arithmetic combinator for accumulation, exported as metric which is interpreted with rate)
  • Probably much more, as this should provide a complete bridge between factorio signals and prometheus metrics.

Zincfox added 3 commits July 20, 2024 15:29
Currently still contains a bug somewhere, combinators are seemingly not added to the runtime groups tables.
Still includes debug prints for now
@Zincfox
Copy link
Contributor Author

Zincfox commented Jul 21, 2024

Marked as a "draft" because while I tested it a bit locally, there are several possible code paths that I had to take into account. As such I want to spend a bit more time testing on my own server before I mark this as "ready".

Zincfox added 5 commits July 22, 2024 13:24
Also includes cleanup of invalidated prometheus combinators, which apparently causes desyncs to happen at the moment
Previous desync was caused by bad logging, game.print apparently affects game state.
Only made functions local and reordered their declaration to match this.
Can be toggled with right click on the respective textfield.
@remijouannet
Copy link
Owner

i don't know if this PR fit this project, the change might be too big.
you've added UI, a new dependencie, logging, i think you should created a separated mod just to deal with combinator

@Zincfox
Copy link
Contributor Author

Zincfox commented Aug 5, 2024

Yeah, I agree, somehow I initially thought that the scope would be way smaller, but this really should be its own project/mod.
I will have to look into how exactly Factorio sandboxes mods, I would really like to write to the same metrics file as graftorio2 so that users wont have to add another scrape target for each metrics-mod.
Ideally I would just require graftorio2 (or even just its prometheus library) and just register my events to the same ticks, for which I use your settings? That last part still feels a bit dirty.
The cleaner solution would probably be to add a script-interface for the prometheus library (if the required object is not shared across sandboxes) and a mod-event like on_prometheus_collect or on_prometheus_metrics_export.
That would result in something kind of similar to the OpenTelemetry SDK and API, where metric-adding mods could just use the script-interface and events, without caring which mod actually adds the prometheus export (graftorio2, graftorio-mp or factorio-prometheus-exporter).

Closing this PR, when/if I have time to add the script-interface and events I will put that in another PR and link it here.

@Zincfox Zincfox closed this Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants