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

Prometheus support #193

Open
kereis opened this issue Feb 10, 2021 · 3 comments
Open

Prometheus support #193

kereis opened this issue Feb 10, 2021 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@kereis
Copy link

kereis commented Feb 10, 2021

Hey everyone!

I'd like to implement Prometheus support for our project "LibreWB". You can consider it as an alternative to InfluxDB.

If things work out well, I'll create a pull request.

@andig
Copy link
Contributor

andig commented Feb 13, 2021

Sounds good. Please let me know if you need support! The. Ain task would be mapping the plethora of measurements to Prometheus metric types, the rest should be staightforward?

@andig andig added enhancement New feature or request help wanted Extra attention is needed labels Feb 13, 2021
@kereis
Copy link
Author

kereis commented Feb 13, 2021

I guess 👍 . Currently

  • I added a router for /metrics in the existing HTTP daemon and a YAML property api.prometheus (maybe move it to prometheus as standalone) that can be set if Prometheus support is needed.
  • Added a "Prometheusd" struct which takes care of registring Prometheus metrics and also provides a Run method for snip runners.

I decided to create Prometheusd even though Prometheus Go library provides a global default registry. But I think it does make sense to have a "single instance of responsibility" for Prometheus stuff. Technically it's not really a daemon so it may be renamed at some point.

@kereis
Copy link
Author

kereis commented Feb 26, 2021

I'm slowly getting close to finish. I have a "proposal" for refactoring Measurement structs (for a better context, check out commit 19e54e9.):

  • I refactored Measurement to be more strongly typed.
  • Units are now typed as well with enumer and struct Unit.
  • I implemented a optional pattern which allows flexible creation of future Measurement structs, without adding too unnecessary clutter like filling parameters for factory function with empty/nil values.
  • Required measurementOptions for creating a Measurement are:
    • WithDescription(string)
    • WithUnit(string)
    • WithMetricType(MetricType)

Moreover, for Measurement specifically, I implemented a dynamic creation of Prometheus metrics.

  • At its current state, Prometheus metric names and help text for Measurement are derrived from a Measurement's description and unit.
    1. Measurement's description is transformed to lower case and each whitespace character is replaced with an underscore character
    2. Description and the Measurement's Unit's plural form are concatenated with underscores.
      • If the Unit's plural form is not present, we simply take the alternative representation (for Prometheus) and append an s.
      • The default plural form can be overridden by simply setting a custom plural form for a Unit
    3. In order to distinguish measurement metrics, measurement is prepended.
    4. For help texts:
      • If a Unit is present: Measurement of DESCRIPTION in UNIT
      • Else: Measurement of DESCRIPTION
    5. Possible name at Prometheus metric creation: mbmd_measurement_l1_power_watts
  • If you don't like these "auto-generated" names and help texts, you can simply override them by using the measurementOptions (however, make sure to follow the usual Prometheus naming conventions):
    • WithPrometheusName(string)
    • WithPrometheusDescription(string)

The last steps would be to check where metrics can be embedded as well and to test if the result of /metrics HTTP API is good for us. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants