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

feat: add labels defined in harvest config to metadata metrics #2456

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/poller/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ func Init(c Collector) error {
md.SetGlobalLabel("object", object)
md.SetGlobalLabel("datacenter", params.GetChildContentS("datacenter"))

if params.HasChildS("labels") {
for _, l := range params.GetChildS("labels").GetChildren() {
md.SetGlobalLabel(l.GetNameS(), l.GetContentS())
}
}

_, _ = md.NewMetricInt64("poll_time")
_, _ = md.NewMetricInt64("task_time")
_, _ = md.NewMetricInt64("api_time")
Expand Down
12 changes: 11 additions & 1 deletion cmd/poller/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Exporter interface {
Init() error // initialize exporter
GetClass() string // the class of the exporter, e.g. Prometheus, InfluxDB
GetName() string // the name of the exporter instance
// Name is different from Class, since we can have multiple instances of the same Class
// GetExportCount Name is different from Class, since we can have multiple instances of the same Class
rahulguptajss marked this conversation as resolved.
Show resolved Hide resolved
GetExportCount() uint64 // return and reset number of exported data points, used by Poller to keep stats
AddExportCount(uint64) // add count to the export count, called by the exporter itself
GetStatus() (uint8, string, string) // return current state of the exporter
Expand Down Expand Up @@ -72,6 +72,16 @@ func New(c, n string, o *options.Options, p conf.Exporter, params *conf.Poller)
}
if params != nil {
abc.Metadata.SetGlobalLabel("datacenter", params.Datacenter)
labels := params.Labels
if labels != nil {
for _, labelPtr := range *labels {
rahulguptajss marked this conversation as resolved.
Show resolved Hide resolved
if labelPtr != nil {
for key, value := range *labelPtr {
abc.Metadata.SetGlobalLabel(key, value)
}
}
}
}
}
return &abc
}
Expand Down
11 changes: 11 additions & 0 deletions cmd/poller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,17 @@ func (p *Poller) loadMetadata() {
if p.options.PromPort != 0 {
p.status.SetGlobalLabel("promport", strconv.Itoa(p.options.PromPort))
}
labels := p.params.Labels
if labels != nil {
for _, labelPtr := range *labels {
if labelPtr != nil {
for key, value := range *labelPtr {
p.metadata.SetGlobalLabel(key, value)
p.status.SetGlobalLabel(key, value)
}
}
}
}
p.status.SetExportOptions(matrix.DefaultExportOptions())
}

Expand Down
Loading