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

Settings hostname for Kubernetes pods #176

Closed
tspecht opened this issue Apr 7, 2016 · 7 comments
Closed

Settings hostname for Kubernetes pods #176

tspecht opened this issue Apr 7, 2016 · 7 comments

Comments

@tspecht
Copy link

tspecht commented Apr 7, 2016

Hey,

I'm running logspout as a DaemonSet inside my Kubernetes cluster. Those containers are successfully set up to send the stdout and stderr from my pods to Papertrail. However when I see the logs coming in the "program" field (e.g. the "name") is pretty verbose and contains a lot of randomly generated UUID on a per-deployment-basis.
Is there any way I could teach logspout to use a static name per pod which I could use?

@filipegiusti
Copy link

You can pass parameters as in the routesapi using query params and set SYSLOG variables as environment variables. So if you want to only collects logs from containers named "application" and marks those in papertail as hostname start logspout container as

$ docker run --name="logspout" \
    --volume=/var/run/docker.sock:/var/run/docker.sock \
    -e "SYSLOG_HOSTNAME=application" \
    -e "SYSLOG_TAG={{.Container.Config.Hostname}}" \
    gliderlabs/logspout \
    syslog://logs.papertrailapp.com:55555?filter.name=application

Also stay tuned on the PR that add env vars on SYSLOG_TAG template.

@tspecht
Copy link
Author

tspecht commented May 18, 2016

@filipegiusti thanks for the reply! However I'm afraid this is not going to solve my problem. The underlying cause is that I'm running one logspout containers to collect data from many different applications each running in their own docker-container. Hence if I would do what you suggested I would get all my logs tagged as being from the same application although they are not :(

@filipegiusti
Copy link

I solved that using namespaces, not sure if that fits your environment.

        - name: SYSLOG_HOSTNAME
          value: '{{ index .Container.Config.Labels "io.kubernetes.pod.namespace" }}'

on that same idea you can set a name per Papertail program as an environment variable as

        - name: SYSLOG_TAG
          value: '{{ index .Container.Config.Env "PROGRAM_NAME" }}'

I spend a lot of time reading logspout source to keep that information to myself. 😄

@pstadler
Copy link

In case somebody else is running a Kubernetes cluster using Rancher. The following configuration works well for me:

- name: SYSLOG_HOSTNAME
  value: '{{ .Hostname }}'
- name: SYSLOG_TAG
  value: '{{ .Container.Config.Hostname }}'

The only issue is that containers deployed by Rancher (e.g. rancher/agent) are logged with their container id instead of a more descriptive name.

@josegonzalez
Copy link
Member

Seems like there are multiple ways to specify this from your cluster implementation of choice. Closing.

@mmoore0011
Copy link

syslog: template: syslog:1:67: executing "syslog" at <index .Container.Con...>: error calling index: cannot index slice/array with type string

@josegonzalez
Copy link
Member

@mmoore0011 if you're filing an issue about a bug, please open a new issue. Do not resurrect an old issue that was closed 2 years ago.

@gliderlabs gliderlabs locked and limited conversation to collaborators Mar 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants