Open
Description
I am working with kubelet cAdvisor that comes along with kubernetes cluster.
I know that cAdvisor exposes container stats as Prometheus metrics but I am not very familiar on how to retrieve them manually using curl.
What is the command to know 1) if cAdvisor is running on each node, 2) what version and 3) what port it is exposing?
Are the cAdvisor metrics always served on the /metrics endpoint?
Your help is greatly appreciated.
Activity
dashpole commentedon Jan 21, 2020
:10255/metrics/cadvisor is where you can find them in recent releases.
stevebail commentedon Jan 21, 2020
@dashpole
@juliusv
Thanks David!
I now know 3 different ways to scrape cAdvisor metrics.
See below.
Which option is recommended for current release and future direction?
Option 1) Scrape the API server for each node in the cluster
:--api-server-port--/api/v1/nodes//proxy/metrics/cadvisor
Example: :8443/api/v1/nodes/node01/proxy/metrics/cadvisor
Option 2)
Scrape the kubelet port on each node
:--kubelet-port--/metrics/cadvisor
Example: :10255/metrics/cadvisor
Option 3)
Scrape each cAdvisor pod deployed as a daemonset configured with
:--cadvisor-port--/metrics
Examples: :8080/metrics
dashpole commentedon Jan 21, 2020
Option 1 and option 2 are the same endpoint. One is just proxied by the API Server. Prefer (2) when possible because it is more direct. If you want to customize the set of metrics exposed by cAdvisor, you can run it yourself as a daemonset. If you just want the metrics in the kubelet's metrics/cadvisor endpoint, I would just use that to save on resource consumption.
stevebail commentedon Jan 22, 2020
@dashpole I have one specific question about cAdvisor. I noticed that node_explorer supports "collectors" with the ability to enable/disable them at the source. Does cAdvisor supports collectors so that user can select the group of cAdvisor metrics to enable/disable? Do I need to install cAdvisor daemonset for this? Or will Prometheus get all cAdvisor metrics during a pull request? If so, is it possible to filter some of them in Prometheus server?
dashpole commentedon Jan 22, 2020
You can use the
--disable_metrics
flag to specify the set of metrics you don't want.stevebail commentedon Jan 22, 2020
dashpole commentedon Jan 22, 2020
./cadvisor --help
stevebail commentedon Jan 22, 2020
I am at root directory on the node and cadvisor file cannot be found:
node01 $ /.cadvisor --help
-bash: /.cadvisor: No such file or directory
dashpole commentedon Jan 22, 2020
yeah, you will need to run that on the cAdvisor binary, which most likely isn't in the root directory of your node. Try:
docker run google/cadvisor --help
from anywhere you have docker.stevebail commentedon Jan 22, 2020
The k8s cluster is already running and I see kubelet is reachable on port 10250:
node01 $ netstat -plant | grep kubelet
tcp 0 0 127.0.0.1:38235 0.0.0.0:* LISTEN 1369/kubelet
tcp 0 0 127.0.0.1:10248 0.0.0.0:* LISTEN 1369/kubelet
tcp 0 0 172.17.0.42:53624 172.17.0.24:6443 ESTABLISHED 1369/kubelet
tcp 0 0 172.17.0.42:53676 172.17.0.24:6443 ESTABLISHED 1369/kubelet
tcp6 0 0 :::10250 :::* LISTEN 1369/kubelet
Do you think I still need to install cAdvisor binary on the node?
dashpole commentedon Jan 22, 2020
See this comment above. You only need to run cAdvisor seperately if you need to customize the set of metrics. Also, I would not recommend manually installing it. I would use a DaemonSet instead, and use the docker image.
stevebail commentedon Jan 22, 2020
Got it. Sorry for taking so much of your time.
Last Q.
If I don't want to customize metrics but I only want to see the current cAdvisor runtime flags in my k8s cluster environment running with kubelet on each node, how to do this?
dashpole commentedon Jan 22, 2020
In my cluster, the command line flags for the kubelet are stored in
/etc/default/kubelet
, but that may change based your setup...stevebail commentedon Jan 29, 2020
@dashpole
I have a use case where I just want to collect my container metrics and I don't have cluster admin rights. For instance. I am a cluster user and I just need cAdvisor metrics for containers in my namespace. So far cAdvisor scrapping options that I know of imply I have access to the node IP addresses or have sufficient RBAC privileges to scrape the cAdvisor endpoint via the API server. What are my options if RBAC is limited to my namespace and I just want cAdvisor metrics for containers in my namespace?
6 remaining items
dashpole commentedon Mar 18, 2020
That is a container label. We probably don't want to rely on that, as it isn't an actual API. We could potentially have label filtering (e.g. only collect metrics for containers where label foo=bar).
stevebail commentedon Mar 18, 2020
That would be great David!
[-]How to query cAdvisor metrics[/-][+]Support filtering monitored containers by container label[/+]mariadb-zdraganov commentedon May 20, 2020
Is there actual support for passing
match[]
parameters to the/metrics
endpoint?stevebail commentedon May 20, 2020
I don't think it currently does and this would be part of this proposed enhancement.
You also mean the /metrics/cadvisor endpoint (e.g. cAdvisor in kubelet).
This is for @dashpole to clarify.
dashpole commentedon May 21, 2020
cAdvisor in the kubelet has its own labeling for cAdvisor metrics: https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/server/server.go#L959
I think you should be able to use the store container labels and label whitelist flags here:
https://github.com/google/cadvisor/blob/master/cmd/cadvisor.go#L71
stevebail commentedon Sep 16, 2020
@dashpole
Hi David.
Is it possible to get an update on the filtering feature request i.e. the ability to collect cAdvisor metrics based on container label whitelist?
celian-garcia commentedon Aug 18, 2021
@stevebail Did you try to whitelist on the prometheus scrape job ?
I'm doing it with success :
Knowing that my whitelisted containers have the following label
stevebail commentedon Aug 18, 2021
@celian-garcia
Thank you for the suggestion.
I am looking for a way to keep a container metric for certain containers and filter out the same metric from unwanted containers.
celian-garcia commentedon Aug 18, 2021
Yeah I did the suggestion mainly for people like me who want to filter containers by label having the hand on the Prometheus configuration. If it is not your case, the solution won't fit your need.
I still think that the feature is worth it in cAdvisor.
zdraganov commentedon Feb 6, 2024
The issue with this configuration is that the filtering is done in Prometheus, not query time, which can lead to significant bigger memory usage.
fede843 commentedon May 12, 2025
You can achieve this with Prometheus relabelling, yes indeed.
Still, this is a valid request and having this option backed in code would be much appreciated.