heistp / irtt

Isochronous Round-Trip Tester
GNU General Public License v2.0
185 stars 23 forks source link

Roadmap suggestion: Prometheus integration #33

Open udf2457 opened 2 years ago

udf2457 commented 2 years ago

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:

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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