feat(inputs.kubernetes): Add option to node metric name (#15049)
This commit is contained in:
parent
c7466b8835
commit
6e8e7e5c15
|
|
@ -62,6 +62,12 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
## OR
|
## OR
|
||||||
# bearer_token_string = "abc_123"
|
# bearer_token_string = "abc_123"
|
||||||
|
|
||||||
|
## Kubernetes Node Metric Name
|
||||||
|
## The default Kubernetes node metric name (i.e. kubernetes_node) is the same
|
||||||
|
## for the kubernetes and kube_inventory plugins. To avoid conflicts, set this
|
||||||
|
## option to a different value.
|
||||||
|
# node_metric_name = "kubernetes_node"
|
||||||
|
|
||||||
## Pod labels to be added as tags. An empty array for both include and
|
## Pod labels to be added as tags. An empty array for both include and
|
||||||
## exclude will include all labels.
|
## exclude will include all labels.
|
||||||
# label_include = []
|
# label_include = []
|
||||||
|
|
|
||||||
|
|
@ -29,25 +29,19 @@ var sampleConfig string
|
||||||
|
|
||||||
// Kubernetes represents the config object for the plugin
|
// Kubernetes represents the config object for the plugin
|
||||||
type Kubernetes struct {
|
type Kubernetes struct {
|
||||||
URL string
|
URL string `toml:"url"`
|
||||||
|
BearerToken string `toml:"bearer_token"`
|
||||||
// Bearer Token authorization file path
|
BearerTokenString string `toml:"bearer_token_string" deprecated:"1.24.0;use 'BearerToken' with a file instead"`
|
||||||
BearerToken string `toml:"bearer_token"`
|
NodeMetricName string `toml:"node_metric_name"`
|
||||||
BearerTokenString string `toml:"bearer_token_string" deprecated:"1.24.0;use 'BearerToken' with a file instead"`
|
LabelInclude []string `toml:"label_include"`
|
||||||
|
LabelExclude []string `toml:"label_exclude"`
|
||||||
LabelInclude []string `toml:"label_include"`
|
ResponseTimeout config.Duration `toml:"response_timeout"`
|
||||||
LabelExclude []string `toml:"label_exclude"`
|
Log telegraf.Logger `toml:"-"`
|
||||||
|
|
||||||
labelFilter filter.Filter
|
|
||||||
|
|
||||||
// HTTP Timeout specified as a string - 3s, 1m, 1h
|
|
||||||
ResponseTimeout config.Duration
|
|
||||||
|
|
||||||
tls.ClientConfig
|
tls.ClientConfig
|
||||||
|
|
||||||
Log telegraf.Logger `toml:"-"`
|
labelFilter filter.Filter
|
||||||
|
httpClient *http.Client
|
||||||
httpClient *http.Client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -83,6 +77,10 @@ func (k *Kubernetes) Init() error {
|
||||||
k.InsecureSkipVerify = true
|
k.InsecureSkipVerify = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if k.NodeMetricName == "" {
|
||||||
|
k.NodeMetricName = "kubernetes_node"
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,7 +167,7 @@ func (k *Kubernetes) gatherSummary(baseURL string, acc telegraf.Accumulator) err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
buildSystemContainerMetrics(summaryMetrics, acc)
|
buildSystemContainerMetrics(summaryMetrics, acc)
|
||||||
buildNodeMetrics(summaryMetrics, acc)
|
buildNodeMetrics(summaryMetrics, acc, k.NodeMetricName)
|
||||||
buildPodMetrics(summaryMetrics, podInfos, k.labelFilter, acc)
|
buildPodMetrics(summaryMetrics, podInfos, k.labelFilter, acc)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +194,7 @@ func buildSystemContainerMetrics(summaryMetrics *SummaryMetrics, acc telegraf.Ac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildNodeMetrics(summaryMetrics *SummaryMetrics, acc telegraf.Accumulator) {
|
func buildNodeMetrics(summaryMetrics *SummaryMetrics, acc telegraf.Accumulator, metricName string) {
|
||||||
tags := map[string]string{
|
tags := map[string]string{
|
||||||
"node_name": summaryMetrics.Node.NodeName,
|
"node_name": summaryMetrics.Node.NodeName,
|
||||||
}
|
}
|
||||||
|
|
@ -219,7 +217,7 @@ func buildNodeMetrics(summaryMetrics *SummaryMetrics, acc telegraf.Accumulator)
|
||||||
fields["runtime_image_fs_available_bytes"] = summaryMetrics.Node.Runtime.ImageFileSystem.AvailableBytes
|
fields["runtime_image_fs_available_bytes"] = summaryMetrics.Node.Runtime.ImageFileSystem.AvailableBytes
|
||||||
fields["runtime_image_fs_capacity_bytes"] = summaryMetrics.Node.Runtime.ImageFileSystem.CapacityBytes
|
fields["runtime_image_fs_capacity_bytes"] = summaryMetrics.Node.Runtime.ImageFileSystem.CapacityBytes
|
||||||
fields["runtime_image_fs_used_bytes"] = summaryMetrics.Node.Runtime.ImageFileSystem.UsedBytes
|
fields["runtime_image_fs_used_bytes"] = summaryMetrics.Node.Runtime.ImageFileSystem.UsedBytes
|
||||||
acc.AddFields("kubernetes_node", fields, tags)
|
acc.AddFields(metricName, fields, tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *Kubernetes) gatherPodInfo(baseURL string) ([]Item, error) {
|
func (k *Kubernetes) gatherPodInfo(baseURL string) ([]Item, error) {
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ package kubernetes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/influxdata/telegraf/filter"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/filter"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
@ -29,8 +29,9 @@ func TestKubernetesStats(t *testing.T) {
|
||||||
labelFilter, _ := filter.NewIncludeExcludeFilter([]string{"app", "superkey"}, nil)
|
labelFilter, _ := filter.NewIncludeExcludeFilter([]string{"app", "superkey"}, nil)
|
||||||
|
|
||||||
k := &Kubernetes{
|
k := &Kubernetes{
|
||||||
URL: ts.URL,
|
URL: ts.URL,
|
||||||
labelFilter: labelFilter,
|
labelFilter: labelFilter,
|
||||||
|
NodeMetricName: "kubernetes_node",
|
||||||
}
|
}
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,12 @@
|
||||||
## OR
|
## OR
|
||||||
# bearer_token_string = "abc_123"
|
# bearer_token_string = "abc_123"
|
||||||
|
|
||||||
|
## Kubernetes Node Metric Name
|
||||||
|
## The default Kubernetes node metric name (i.e. kubernetes_node) is the same
|
||||||
|
## for the kubernetes and kube_inventory plugins. To avoid conflicts, set this
|
||||||
|
## option to a different value.
|
||||||
|
# node_metric_name = "kubernetes_node"
|
||||||
|
|
||||||
## Pod labels to be added as tags. An empty array for both include and
|
## Pod labels to be added as tags. An empty array for both include and
|
||||||
## exclude will include all labels.
|
## exclude will include all labels.
|
||||||
# label_include = []
|
# label_include = []
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue