mirror of
https://codeberg.org/scip/io-exporter.git
synced 2025-12-16 20:11:00 +01:00
add flag to report internal metrics on resource usage
This commit is contained in:
@@ -22,18 +22,20 @@ Options:
|
||||
-t --timeout <int> When should the operation timeout in seconds
|
||||
-s --sleeptime <int> Time to sleep between checks (default: 5s)
|
||||
-l --label <label=value> Add label to exported metric
|
||||
-i --internals Also add labels about resource usage
|
||||
-h --help Show help
|
||||
-v --version Show program version`
|
||||
)
|
||||
|
||||
// config via commandline flags
|
||||
type Config struct {
|
||||
Showversion bool `koanf:"version"` // -v
|
||||
Showhelp bool `koanf:"help"` // -h
|
||||
Label []string `koanf:"label"` // -v
|
||||
Timeout int `koanf:"timeout"` // -t
|
||||
Port int `koanf:"port"` // -p
|
||||
Sleeptime int `koanf:"sleep"` // -s
|
||||
Showversion bool `koanf:"version"` // -v
|
||||
Showhelp bool `koanf:"help"` // -h
|
||||
Internals bool `koanf:"internals"` // -i
|
||||
Label []string `koanf:"label"` // -v
|
||||
Timeout int `koanf:"timeout"` // -t
|
||||
Port int `koanf:"port"` // -p
|
||||
Sleeptime int `koanf:"sleep"` // -s
|
||||
|
||||
File string
|
||||
Labels []Label
|
||||
@@ -54,6 +56,7 @@ func InitConfig(output io.Writer) (*Config, error) {
|
||||
// parse commandline flags
|
||||
flagset.BoolP("version", "v", false, "show program version")
|
||||
flagset.BoolP("help", "h", false, "show help")
|
||||
flagset.BoolP("internals", "i", false, "add internal metrics")
|
||||
flagset.StringArrayP("label", "l", nil, "additional labels")
|
||||
flagset.IntP("timeout", "t", 1, "timeout for file operation in seconds")
|
||||
flagset.IntP("port", "p", 9187, "prometheus metrics port to listen to")
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
)
|
||||
|
||||
// custom labels
|
||||
@@ -49,7 +50,23 @@ func NewMetrics(conf *Config) *Metrics {
|
||||
registry: prometheus.NewRegistry(),
|
||||
}
|
||||
|
||||
metrics.registry.MustRegister(metrics.run, metrics.latency)
|
||||
if conf.Internals {
|
||||
metrics.registry.MustRegister(
|
||||
metrics.run,
|
||||
metrics.latency,
|
||||
|
||||
// we might need to take care of the exporter in terms of
|
||||
// resources, so also report those internals
|
||||
collectors.NewGoCollector(
|
||||
collectors.WithGoCollectorMemStatsMetricsDisabled(),
|
||||
),
|
||||
collectors.NewProcessCollector(
|
||||
collectors.ProcessCollectorOpts{},
|
||||
),
|
||||
)
|
||||
} else {
|
||||
metrics.registry.MustRegister(metrics.run, metrics.latency)
|
||||
}
|
||||
|
||||
// static labels
|
||||
metrics.values[0] = conf.File
|
||||
|
||||
Reference in New Issue
Block a user