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

Roadmap suggestion: Prometheus integration #33

Open
udf2457 opened this issue Feb 20, 2022 · 3 comments
Open

Roadmap suggestion: Prometheus integration #33

udf2457 opened this issue Feb 20, 2022 · 3 comments

Comments

@udf2457
Copy link

udf2457 commented Feb 20, 2022

First thank you for your work on this great project which I have only discovered today !

Could I put the idea in your minds to add Prometheus integration to irtt.

To be more specific:

  • irtt-client support for Prometheus text-based exposition. This would enable irtt-client to publish output in a directory for collection by node_exporterwhen running with the --collector.textfile.directory flag; and/or
  • irtt-server publish a http metrics page for Prometheus to scrape

Given that both irtt and prometheus are written in Go and prometheus publish Go libraries, I think this should be relatively straightforward to implement. I'm a noob to Go programming but even I managed to hack together something (for my own personal unrelated project) that exports to text file using the following calls from the Prometheus go library:

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/expfmt"
)

# Create registry
reg := prometheus.NewRegistry()
var collectors []prometheus.Collector

# Gauge / Counters (Repeated as required)
gauge := prometheus.NewGauge(prometheus.GaugeOpts{}) 
gauge.Set(value)
collectors = append(
  collectors,
  gauge,
  )

# Collect and export to text file
reg.MustRegister(collectors...)
gathered, err := reg.Gather()
for _, item := range gathered {
  _, err := expfmt.MetricFamilyToText(
  tmp,
  item,
  )
@heistp
Copy link
Owner

heistp commented Feb 21, 2022

It sounds like a useful addition, but I'm trying to do it keep the binary size down so irtt can be run on embedded devices.

If I compile the binary as is, the size is 3983781. If I compile referencing the prometheus libs, the size increases 10049128. So, it's not something I would add by default. It could be done with build tags. Another option is to write a separate program to take the json and do whatever you want to do with prometheus separately.

I'll leave the issue open in case someone wants to work on it...

@udf2457
Copy link
Author

udf2457 commented Feb 21, 2022

Re: Seperate program taking JSON, I did start experimenting with that, but quickly found it would be nice if irtt codebase was made more friendly for use as a go library.

For example, I thought I the obvious easy solution would be to Unmarshal into the JSON struct from your codebase, but that failed miserably ( I can't remember the error now since I abandoned that test code but something like "unable to unmarshal text into irtt.Time") so I ended up having to write up my own structs.

Also in general, making it easier to call measurement runs directly from go instead of having to call-out to exec.command()

@heistp
Copy link
Owner

heistp commented Feb 21, 2022

Right, it could be useful. If someone writes it and keeps it opt-in with build tags I'll consider pulling that in...

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

No branches or pull requests

2 participants