The Kubelet exposes metrics about itself as well as cAdvisor metrics about containers running on its node.
Cloud Monitoring offers an out-of-the-box managed collection of cAdvisor/Kubelet metrics as an alternative to configuring this integration. The fully managed collection option provides an opinionated, curated set of metrics that is set up in new clusters by default.
The integration described in this document offers all of the cAdvisor metrics, many of which you are unlikely to need and will probably want to filter out, and it is available to Google Kubernetes Engine and other Kubernetes environments. The managed set of cAdvisor/Kubelet metrics has been curated to provide only the most useful metrics and is available only to GKE. For more information, see Package: cAdvisor/Kubelet metrics.
If you set up collection of cAdvisor metrics as described in this document, the configuration supersedes the GKE-managed cAdvisor configuration. The configuration described in this document enables a superset of the managed cAdvisor metrics.
When you use the approach described in this document, instead of using a
custom PodMonitoring config,
you can configure managed collection to automatically scrape
cAdvisor and Kubelet metrics by editing the OperatorConfig.
You can install manifests by copying them to a local file and then running
kubectl apply -f FILE_NAME
.
You can also install manifests by using Terraform.
Open the OperatorConfig resource for editing:
kubectl -n gmp-public edit operatorconfig config
Add the following
collection
section, shown in bold type, to the resource:apiVersion: monitoring.googleapis.com/v1 kind: OperatorConfig metadata: namespace: gmp-public name: config collection: kubeletScraping: interval: 30s
Save the file and close the editor.
After a short time, the Kubelet metric endpoints will be scraped and the metrics become available for querying in Managed Service for Prometheus.
Kubelet scraping comes with some default filters, and you can add additional
filters to the collection
section of the OperatorConfig resource as shown
below. The filter.matchOneOf
configuration section has the same
semantics as the match[]
parameters for Prometheus federation.
The following example filters out metrics that start with container_foo
or
container_bar
:
collection: filter: matchOneOf: - '{__name__!~"container_foo.*|container_bar.*"}'
You can also use this OperatorConfig collection filter for debugging purposes. For example, you might want to temporarily disable collection of a particular metric in your cluster without modifying any PodMonitoring resource.
Tips for advanced cAdvisor setups
If you self-deploy cAdvisor or provide advanced configuration to your Kubelet with cAdvisor, be aware that additional labels can be attached by using advanced cAdvisor settings.
Particularly avoid attaching Kubernetes container labels or environment
variables to your metrics, and if you do, strictly control these labels by using
an allowlist pattern (for example, using PodMonitoring's metricRelabeling
section).
Controlling the number of labels added to your metrics can help you avoid exceeding the limit on the number of labels.