mirror of
https://codeberg.org/scip/io-exporter.git
synced 2025-12-17 04:21: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
|
-t --timeout <int> When should the operation timeout in seconds
|
||||||
-s --sleeptime <int> Time to sleep between checks (default: 5s)
|
-s --sleeptime <int> Time to sleep between checks (default: 5s)
|
||||||
-l --label <label=value> Add label to exported metric
|
-l --label <label=value> Add label to exported metric
|
||||||
|
-i --internals Also add labels about resource usage
|
||||||
-h --help Show help
|
-h --help Show help
|
||||||
-v --version Show program version`
|
-v --version Show program version`
|
||||||
)
|
)
|
||||||
|
|
||||||
// config via commandline flags
|
// config via commandline flags
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Showversion bool `koanf:"version"` // -v
|
Showversion bool `koanf:"version"` // -v
|
||||||
Showhelp bool `koanf:"help"` // -h
|
Showhelp bool `koanf:"help"` // -h
|
||||||
Label []string `koanf:"label"` // -v
|
Internals bool `koanf:"internals"` // -i
|
||||||
Timeout int `koanf:"timeout"` // -t
|
Label []string `koanf:"label"` // -v
|
||||||
Port int `koanf:"port"` // -p
|
Timeout int `koanf:"timeout"` // -t
|
||||||
Sleeptime int `koanf:"sleep"` // -s
|
Port int `koanf:"port"` // -p
|
||||||
|
Sleeptime int `koanf:"sleep"` // -s
|
||||||
|
|
||||||
File string
|
File string
|
||||||
Labels []Label
|
Labels []Label
|
||||||
@@ -54,6 +56,7 @@ func InitConfig(output io.Writer) (*Config, error) {
|
|||||||
// parse commandline flags
|
// parse commandline flags
|
||||||
flagset.BoolP("version", "v", false, "show program version")
|
flagset.BoolP("version", "v", false, "show program version")
|
||||||
flagset.BoolP("help", "h", false, "show help")
|
flagset.BoolP("help", "h", false, "show help")
|
||||||
|
flagset.BoolP("internals", "i", false, "add internal metrics")
|
||||||
flagset.StringArrayP("label", "l", nil, "additional labels")
|
flagset.StringArrayP("label", "l", nil, "additional labels")
|
||||||
flagset.IntP("timeout", "t", 1, "timeout for file operation in seconds")
|
flagset.IntP("timeout", "t", 1, "timeout for file operation in seconds")
|
||||||
flagset.IntP("port", "p", 9187, "prometheus metrics port to listen to")
|
flagset.IntP("port", "p", 9187, "prometheus metrics port to listen to")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// custom labels
|
// custom labels
|
||||||
@@ -49,7 +50,23 @@ func NewMetrics(conf *Config) *Metrics {
|
|||||||
registry: prometheus.NewRegistry(),
|
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
|
// static labels
|
||||||
metrics.values[0] = conf.File
|
metrics.values[0] = conf.File
|
||||||
|
|||||||
Reference in New Issue
Block a user