mirror of
https://codeberg.org/scip/io-exporter.git
synced 2025-12-19 05:21:01 +01:00
separate read and write tests, collect separate latencies
This commit is contained in:
@@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
@@ -14,15 +15,17 @@ type Label struct {
|
||||
|
||||
// simple prometheus wrapper
|
||||
type Metrics struct {
|
||||
run *prometheus.GaugeVec
|
||||
latency *prometheus.GaugeVec
|
||||
registry *prometheus.Registry
|
||||
values []string
|
||||
run *prometheus.GaugeVec
|
||||
latency_r *prometheus.GaugeVec
|
||||
latency_w *prometheus.GaugeVec
|
||||
registry *prometheus.Registry
|
||||
values []string
|
||||
mode int
|
||||
}
|
||||
|
||||
func NewMetrics(conf *Config) *Metrics {
|
||||
labels := []string{"file", "maxwait"}
|
||||
LabelLen := 2
|
||||
labels := []string{"file", "maxwait", "exectime"}
|
||||
LabelLen := 3
|
||||
|
||||
for _, label := range conf.Labels {
|
||||
labels = append(labels, label.Name)
|
||||
@@ -36,10 +39,17 @@ func NewMetrics(conf *Config) *Metrics {
|
||||
},
|
||||
labels,
|
||||
),
|
||||
latency: prometheus.NewGaugeVec(
|
||||
latency_r: prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "io_exporter_io_latency",
|
||||
Help: "how long does the operation take in seconds",
|
||||
Name: "io_exporter_io_read_latency",
|
||||
Help: "how long does the read operation take in seconds",
|
||||
},
|
||||
labels,
|
||||
),
|
||||
latency_w: prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "io_exporter_io_write_latency",
|
||||
Help: "how long does the write operation take in seconds",
|
||||
},
|
||||
labels,
|
||||
),
|
||||
@@ -53,7 +63,8 @@ func NewMetrics(conf *Config) *Metrics {
|
||||
if conf.Internals {
|
||||
metrics.registry.MustRegister(
|
||||
metrics.run,
|
||||
metrics.latency,
|
||||
metrics.latency_r,
|
||||
metrics.latency_w,
|
||||
|
||||
// we might need to take care of the exporter in terms of
|
||||
// resources, so also report those internals
|
||||
@@ -65,28 +76,50 @@ func NewMetrics(conf *Config) *Metrics {
|
||||
),
|
||||
)
|
||||
} else {
|
||||
metrics.registry.MustRegister(metrics.run, metrics.latency)
|
||||
metrics.registry.MustRegister(metrics.run, metrics.latency_r, metrics.latency_w)
|
||||
}
|
||||
|
||||
// static labels
|
||||
metrics.values[0] = conf.File
|
||||
metrics.values[1] = fmt.Sprintf("%d", conf.Timeout)
|
||||
metrics.values[2] = fmt.Sprintf("%d", time.Now().UnixMilli())
|
||||
|
||||
// custom labels via -l label=value
|
||||
for idx, label := range conf.Labels {
|
||||
metrics.values[idx+LabelLen] = label.Value
|
||||
}
|
||||
|
||||
switch {
|
||||
case conf.ReadMode && conf.WriteMode:
|
||||
metrics.mode = O_RW
|
||||
case conf.ReadMode:
|
||||
metrics.mode = O_R
|
||||
case conf.WriteMode:
|
||||
metrics.mode = O_W
|
||||
}
|
||||
|
||||
return metrics
|
||||
}
|
||||
|
||||
func (metrics *Metrics) Set(result bool, elapsed float64) {
|
||||
func (metrics *Metrics) Set(result_r, result_w bool, elapsed_r, elapsed_w float64) {
|
||||
var res float64
|
||||
|
||||
if result {
|
||||
res = 1
|
||||
switch metrics.mode {
|
||||
case O_RW:
|
||||
if result_r && result_w {
|
||||
res = 1
|
||||
}
|
||||
case O_R:
|
||||
if result_r {
|
||||
res = 1
|
||||
}
|
||||
case O_W:
|
||||
if result_w {
|
||||
res = 1
|
||||
}
|
||||
}
|
||||
|
||||
metrics.run.WithLabelValues(metrics.values...).Set(res)
|
||||
metrics.latency.WithLabelValues(metrics.values...).Set(elapsed)
|
||||
metrics.latency_r.WithLabelValues(metrics.values...).Set(elapsed_r)
|
||||
metrics.latency_w.WithLabelValues(metrics.values...).Set(elapsed_w)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user