-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export image name and env variables as prometheus labels #780
Conversation
Can one of the admins verify this patch? |
ok to test |
@Marmelatze this looks good for the most part. I know image has been requested for a while. Env variables I'm not so sure we want to do however...what is the intended usecase? Just afraid that we're exposing data that is tricky to use and easy to abuse. |
I have the same use case as the guy in #546. I have some Mesos/Marathon hosts and Mesos assigns some random id as container name (I expect Mesos/kubernetes and Mesos/Swarm to do the same). In my dashboard (cadvisor on every host -> prometheus -> grafana) I can see that a container uses 100% CPU but I only can see the host its running on and the name (mesos-1234-5678...). To determine what application this container is running I have to SSH into that host and inspect the container. There I can see the mesos task-id, the marathon app name and version. The reverse way is also time consuming: I have more than one instance of this app running and I want to know how these are performing (CPU, RAM, Network). So I have to check Marathon or Mesos to get a list of hosts, that app is deployed to. Than I have to ssh into these. List all containers and look which could be my app. Inspect these to be sure. Go back to the dashboard and filter for the names. I know some sensitive data, like passwords and access tokens, are stored in env variables, so I made this optional and the exposed variables configurable. For Mesos/Marathon it would be: |
@@ -71,6 +71,10 @@ type dockerContainerHandler struct { | |||
|
|||
// Metadata labels associated with the container. | |||
labels map[string]string | |||
|
|||
image string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add comments for these
6a160c8
to
6e404da
Compare
Thanks for the feedback. With all container labels exported as prometheus labels it would also fix #688 |
LGTM, thanks @Marmelatze! Can you rebase and repush to kick the CI? |
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
CLAs look good, thanks! |
@Marmelatze thanks so much for taking this on. It is basically a requirement when using Prometheus with Consul if I want to populate graphs dynamically. Now I just have to LABEL my images and it will Just Work™ 😀 |
Rebased to current master and tests seem to pass |
+1 I have exactly the same usecase (mesos, classifying containers by appname for aggregation and averaging reasons across a cluster). Hopefully this can be merged ASAP |
cc5b3e0
to
19967f0
Compare
Would really like to see this merged, although only want the image name personally. |
@Marmelatze Let's split this up. I think image name makes a lot of sense. We can merge that quickly. Do the containers in Mesos use labels - something more structured than env variables and intended for exporting? We can pick up runtime image labels too for identifying the apps. |
Image name added in #869. |
OK thanks, but unfortunately mesos doesn't seem to set labels or something else. Just the env variables. |
@Marmelatze could you rebase this to remove the changes already introduced by #869? Unless you've found an alternative solution by now; if so, could you share? @rjnagal was the answer to your question satisfying? We've got the same usecase as @Marmelatze and would like to see this addressed. |
+1 for rebase |
1 similar comment
+1 for rebase |
I actually tried rebasing myself, but with my very limited understanding of Go, I couldn't figure out how to resolve the conflicts in |
19967f0
to
8940433
Compare
Rebased to current master and removed the image name parts. |
The commit message still mentions the image, but that should be trivial to fix when landing this. |
@Marmelatze awesome, works perfect. thx |
@@ -493,6 +493,11 @@ func (c *PrometheusCollector) collectContainersInfo(ch chan<- prometheus.Metric) | |||
} | |||
baseLabelValues := []string{id, name, image}[:len(baseLabels)] | |||
|
|||
for labelKey, labelValue := range container.Spec.Labels { | |||
baseLabels = append(baseLabels, labelKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
labelKey
will need to be sanitized as Prometheus labels need to match this regexp.
You can copy the sanitize method from here & please add a test for this.
@Marmelatze: Can you rebase? |
@vishh @Marmelatze im also interested to see this and ability to specify container labels as tags. Let me know if you want some help with this ( rebase / take over etc. ) |
Is anyone running this yet? |
yes https://hub.docker.com/r/mikemichel/cadvisor/tags/
|
@rjnagal feels like the security concerns are minimized by only exporting whitelisted ENV vars no? |
@jimmidyson or @vmarmol Any chance to see this merged now that we have to whitelist the env vars? |
@scalp42 If you can rebase I'll try to find time to review tomorrow. I have no security concerns now that you have added the whitelist for env vars. |
cc @Marmelatze 🍶 |
This looks fine with the whitelist. Can you rebase? Thanks. |
Can one of the admins verify that this patch is reasonable to test? (reply "ok to test", or if you trust the user, reply "add to whitelist") If this message is too spammy, please complain to ixdy. |
@Marmelatze any chance ? 🚨 |
Can one of the admins verify that this patch is reasonable to test? (reply "ok to test", or if you trust the user, reply "add to whitelist") If this message is too spammy, please complain to ixdy. |
@vishh @rjnagal @jimmidyson i like to use this patch. Should i take over and do a rebase on behalf of @Marmelatze ? |
Yeah. Feel free to work on top of existing patches. On Tue, Dec 15, 2015 at 10:34 AM, Daniel, Dao Quang Minh <
|
Carry #780: Export env variables as prometheus labels
Fixed by #780. |
I had the same issue as described in #546. The names from containers created with Mesos/Marathon are not telling something about the app this container is running. With this PR any env variable can be exported as prometheus label. I also added the current image a container is running for monitoring the performance of some images.
I hope this use case isn't to specific.