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 support v2 #342

Open
wants to merge 77 commits into
base: master
Choose a base branch
from

Conversation

SchumacherFM
Copy link

This is a refactored version of #195 by @kereis

  • Updates to the status screen of the webinterface to add model and SN
  • Remove too many prometheus measurements like: monitoring websocket connections, modbus connections but keeps of course all modbus measured values
  • some other minor refactorings

This PR runs at the moment at my home with SolarEdge SE10K, SE17K and the Meter.

vkz-screen-new

IMHO #195 can be closed.

Waiting for your review(s).

kereis added 30 commits March 4, 2024 20:47
If you open this project in GoLand, it will create a .idea/ directory which could have been tracked by Git.
Some metrics are implemented in handler.go and scan.go.
Each metrics is accessible via global variable.
Helper method UpdateMeasurementMetric adds flexibility to updating specific measurement without hardcoding Prometheus Metric in certain places.
When using newGaugeOpts/newCounterOpts, all objects will share the same namespace "mbmd"
…auges of measurements

Instead of creating a new counter/gauges for a measurement by hand, we simply just add a newly added measurement to the appropriate counterVeh/gaugesVeh map. This also means that everytime a new measurement in meters.Measurement is introduced, the maps in prometheus.go need to be updated as well.
Instead of actively managing and storing each measurement in gauges and counters map respectively, in measurements.go, each entry in `iec` is assigned a PrometheusMetricType.

When prometheus_metrics.Init is called, the appropriate prometheus.Metric will be initialized and will still be stored in gauges/counters map, but its content now dynamically changes based on meters.Measurements actually enum entries, making meters.Measurements the single instance of responsibility for handling metric types.
Instead of creating only one instance of each Prometheus metric measurement, each metric will now differ in each device's manufacturer
Each static metrics is now categorized by interface `collectable`. `collectable.Collect()` will be called when all static metrics are registered to the default Prometheus registry.
When using `prometheus.MustRegister(...)`, the app will panic if a slice entry is nil. Meanwhile fail fast isn't bad, the stack trace doesn't provide enough/precise information about the panic.

`prometheus.Register(prometheus.Collector)` however returns an error object which makes it much easier to troubleshoot metric registrations.
Previously, log.Fatalf was used for logging if a metric registration to default Prometheus registry fails. However, I don't think there's a need to panic - logging should be enough
Measurement labels are stripped to just serial_numbers as they can be accessed via Join with mbmd_device_info
than previous value, if set. if the current value is lower than we skip that value
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.

None yet

2 participants