Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

Marmelatze
Copy link
Contributor

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.

@cadvisorJenkinsBot
Copy link
Collaborator

Can one of the admins verify this patch?

@vmarmol
Copy link
Contributor

vmarmol commented Jun 29, 2015

ok to test

@vmarmol
Copy link
Contributor

vmarmol commented Jun 29, 2015

@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.

@Marmelatze
Copy link
Contributor Author

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:
--docker_metadata_env=MESOS_TASK_ID,MARATHON_APP_ID,MARATHON_APP_VERSION

@@ -71,6 +71,10 @@ type dockerContainerHandler struct {

// Metadata labels associated with the container.
labels map[string]string

image string
Copy link
Contributor

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

@Marmelatze Marmelatze force-pushed the metadata_env branch 2 times, most recently from 6a160c8 to 6e404da Compare July 7, 2015 09:52
@Marmelatze
Copy link
Contributor Author

Thanks for the feedback. With all container labels exported as prometheus labels it would also fix #688

@vmarmol
Copy link
Contributor

vmarmol commented Jul 8, 2015

LGTM, thanks @Marmelatze! Can you rebase and repush to kick the CI?

@googlebot
Copy link
Collaborator

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.

@googlebot
Copy link
Collaborator

CLAs look good, thanks!

@MrMMorris
Copy link

@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™ 😀

@Marmelatze
Copy link
Contributor Author

Rebased to current master and tests seem to pass

@gtmtech
Copy link

gtmtech commented Jul 27, 2015

+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

@Marmelatze Marmelatze force-pushed the metadata_env branch 2 times, most recently from cc5b3e0 to 19967f0 Compare August 4, 2015 12:53
@jimmidyson
Copy link
Collaborator

Would really like to see this merged, although only want the image name personally.

@rjnagal
Copy link
Contributor

rjnagal commented Aug 25, 2015

@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.

@jimmidyson
Copy link
Collaborator

Image name added in #869.

@Marmelatze
Copy link
Contributor Author

OK thanks, but unfortunately mesos doesn't seem to set labels or something else. Just the env variables.

@jzaefferer
Copy link

@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.

@MikeMichel
Copy link

+1 for rebase

1 similar comment
@koboltmarky
Copy link

+1 for rebase

@jzaefferer
Copy link

I actually tried rebasing myself, but with my very limited understanding of Go, I couldn't figure out how to resolve the conflicts in metrics/prometheus.go.

@Marmelatze
Copy link
Contributor Author

Rebased to current master and removed the image name parts.

@jzaefferer
Copy link

The commit message still mentions the image, but that should be trivial to fix when landing this.

@MikeMichel
Copy link

@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)
Copy link
Collaborator

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.

@vishh
Copy link
Contributor

vishh commented Oct 8, 2015

@Marmelatze: Can you rebase?

@dqminh
Copy link
Contributor

dqminh commented Oct 27, 2015

@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. )

@deedubs
Copy link

deedubs commented Nov 4, 2015

Is anyone running this yet?

@MikeMichel
Copy link

yes https://hub.docker.com/r/mikemichel/cadvisor/tags/

docker run --name cadvisor --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys
:ro --volume=/mnt/docker/:/var/lib/docker:ro --publish=8080:8080 --detach=true   mikemichel/cadvisor:metaenvs --docker_metadata_env=MESOS_TASK_ID,MARATHO
N_APP_ID,MARATHON_APP_VERSION

@deedubs
Copy link

deedubs commented Nov 13, 2015

@rjnagal feels like the security concerns are minimized by only exporting whitelisted ENV vars no?

@scalp42
Copy link

scalp42 commented Nov 17, 2015

@jimmidyson or @vmarmol Any chance to see this merged now that we have to whitelist the env vars?

@jimmidyson
Copy link
Collaborator

@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.

@scalp42
Copy link

scalp42 commented Nov 17, 2015

cc @Marmelatze 🍶

@rjnagal
Copy link
Contributor

rjnagal commented Nov 17, 2015

This looks fine with the whitelist. Can you rebase? Thanks.

@k8s-bot
Copy link
Collaborator

k8s-bot commented Dec 11, 2015

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.

@scalp42
Copy link

scalp42 commented Dec 11, 2015

@Marmelatze any chance ? 🚨

@k8s-bot
Copy link
Collaborator

k8s-bot commented Dec 12, 2015

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.

@dqminh
Copy link
Contributor

dqminh commented Dec 15, 2015

@vishh @rjnagal @jimmidyson i like to use this patch. Should i take over and do a rebase on behalf of @Marmelatze ?

@vishh
Copy link
Contributor

vishh commented Dec 15, 2015

Yeah. Feel free to work on top of existing patches.

On Tue, Dec 15, 2015 at 10:34 AM, Daniel, Dao Quang Minh <
notifications@github.com> wrote:

@vishh https://github.com/vishh @rjnagal https://github.com/rjnagal
@jimmidyson https://github.com/jimmidyson i like to use this patch.
Should i take over and do a rebase on behalf of @Marmelatze
https://github.com/Marmelatze ?


Reply to this email directly or view it on GitHub
#780 (comment).

vishh added a commit that referenced this pull request Jan 13, 2016
Carry #780: Export env variables as prometheus labels
@jimmidyson
Copy link
Collaborator

Fixed by #780.

@jimmidyson jimmidyson closed this Jan 14, 2016
@r0fls
Copy link

r0fls commented Oct 17, 2017

Fixed by #780.

Well hey now, that's a circular reference! 😄 Do you mean #1023 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.