diff --git a/cmd/collectors/rest/rest.go b/cmd/collectors/rest/rest.go index 59c2fe473..4ff25cb2c 100644 --- a/cmd/collectors/rest/rest.go +++ b/cmd/collectors/rest/rest.go @@ -30,6 +30,7 @@ type endPoint struct { } type prop struct { + object string query string instanceKeys []string instanceLabels map[string]string @@ -84,18 +85,32 @@ func (r *Rest) Init(a *collector.AbstractCollector) error { return err } - r.Logger.Info().Str("cluster", r.client.Cluster().Name).Msgf("connected to %s", r.client.Cluster().Info) - - r.Matrix.SetGlobalLabel("cluster", r.client.Cluster().Name) - if err = r.initCache(); err != nil { return err } + + if err = r.InitMatrix(); err != nil { + return err + } r.Logger.Info().Msgf("initialized cache with %d metrics", len(r.Matrix.GetMetrics())) return nil } +func (r *Rest) InitMatrix() error { + // overwrite from abstract collector + r.Matrix.Object = r.prop.object + // Add system (cluster) name + r.Matrix.SetGlobalLabel("cluster", r.client.Cluster().Name) + if r.Params.HasChildS("labels") { + for _, l := range r.Params.GetChildS("labels").GetChildren() { + r.Matrix.SetGlobalLabel(l.GetNameS(), l.GetContentS()) + } + } + + return nil +} + func (r *Rest) getClient(a *collector.AbstractCollector, config *node.Node) (*rest.Client, error) { var ( poller *conf.Poller diff --git a/cmd/collectors/rest/templating.go b/cmd/collectors/rest/templating.go index 5a7c5f3c1..ce82f0c73 100644 --- a/cmd/collectors/rest/templating.go +++ b/cmd/collectors/rest/templating.go @@ -29,14 +29,12 @@ func (r *Rest) initCache() error { display, name, kind string ) - if r.Object == "" { - if x := r.Params.GetChildContentS("object"); x != "" { - r.Object = x - } + if x := r.Params.GetChildContentS("object"); x != "" { + r.prop.object = x + } else { + r.prop.object = strings.ToLower(r.Object) } - r.Matrix.Object = strings.ToLower(r.Object) - if e := r.Params.GetChildS("export_options"); e != nil { r.Matrix.SetExportOptions(e) }