apiVersion: monitoring.coreos.com/v1kind: ServiceMonitormetadata:labels:app.kubernetes.io/name: kube-state-metricsapp.kubernetes.io/version: 1.9.7name: kube-state-metricsnamespace: kube-systemspec:endpoints:- bearerTokenSecret:key: ""interval: 15s # This parameter indicates the collection interval. You can increase it to reduce data storage costs. For example, you can set the interval to 300s for less critical metrics, which can reduce the amount of collected monitoring data by 20 times.port: http-metricsscrapeTimeout: 15s # This parameter indicates the collection timeout. TMP requires that this timeout must not be longer than the collection interval. In other words, the value of scrapeTimeout should be no greater than that of interval.jobLabel: app.kubernetes.io/namenamespaceSelector: {}selector:matchLabels:app.kubernetes.io/name: kube-state-metrics
kube_node_info
and kube_node_role
, add the configuration with the metricRelabelings
field to the endpoints list of ServiceMonitor. Note that the field is metricRelabelings
, not relabelings
.
Example of adding metricRelabelings
:apiVersion: monitoring.coreos.com/v1kind: ServiceMonitormetadata:labels:app.kubernetes.io/name: kube-state-metricsapp.kubernetes.io/version: 1.9.7name: kube-state-metricsnamespace: kube-systemspec:endpoints:- bearerTokenSecret:key: ""interval: 15s # This parameter indicates the collection interval. You can increase it to reduce data storage costs. For example, you can set the interval to 300s for less critical metrics, which can reduce the amount of collected monitoring data by 20 times.port: http-metricsscrapeTimeout: 15s# The following four lines are added:metricRelabelings: # Each metric will undergo the following process.- sourceLabels: ["__name__"] # The label name to be checked. __name__ refers to the metric name or any label of the metric.regex: kube_node_info|kube_node_role # Check whether the label matches this regular expression. Here, __name__ is expected to match kube_node_info or kube_node_role.action: keep # If the metric name meets the above conditions, the metric is kept. Otherwise, it is automatically discarded.jobLabel: app.kubernetes.io/namenamespaceSelector: {}selector:
scrape_configs:- job_name: job1scrape_interval: 15s # This parameter indicates the collection interval. You can increase it to reduce data storage costs. For example, you can set the interval to 300s for less critical metrics, which can reduce the amount of collected monitoring data by 20 times.static_configs:- targets:- '1.1.1.1'
kube_node_info
and kube_node_role
only, add the configuration with the field metric_relabel_configs
. Note: The field is metric_relabel_configs
, not relabel_configs
.
Example of adding metric_relabel_configs
:scrape_configs:- job_name: job1scrape_interval: 15s # This parameter indicates the collection interval. You can increase it to reduce data storage costs. For example, you can set the interval to 300s for less critical metrics, which can reduce the amount of collected monitoring data by 20 times.static_configs:- targets:- '1.1.1.1'# The following four lines are added:metric_relabel_configs: # Each metric will undergo the following process.- source_labels: ["__name__"] # The label name to be checked. __name__ refers to the metric name or any label of the metric.regex: kube_node_info|kube_node_role # Check whether the label matches this regular expression. Here, __name__ is expected to match kube_node_info or kube_node_role.action: keep # If the metric name meets the above conditions, the metric is kept. Otherwise, it is automatically discarded.
tps-skip-monitor: "true"
to the specified namespace. For label details, see Labels and Selectors.tps-skip-monitor: "true"
to these CRD resources. For label details, see Labels and Selectors.
Was this page helpful?