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

Fix logger in SdJournal, add optional filters and Docker journald tags #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

marcogroppo
Copy link

@marcogroppo marcogroppo commented Mar 20, 2017

Some fixes and additional features:

  • Fix: SdJournal was still using the old logger, which has been removed.
  • Fix: Check for nil-pointer in WriteBatch() before dereferencing it.
  • Fix: IdleFunc() listener was logging too much because lastMetricTime was never updated.
  • The user can now specify (optional) journald filters in the configuration file.
  • Docker's journald log driver stores additional metadata tags (for example: CONTAINER_ID) with each log message. These have been added to the Record struct.

SdJournal was still using the old logger, which has been removed.
Optional journald filters can now be specified in the configuration file.

Docker's journald logging driver stores additional fields in the journal
(CONTAINER_ID, CONTAINER_NAME, etc.). These fields can now be recorded.

Fix possible nil-pointer error in WriteBatch.
IdleFunc() listener was logging too much because lastMetricTime was
never updated.
@toanctruong
Copy link

@marcogroppo Would you be able to compile the binary and make it available to download? I'm having some trouble building directly from your fork.

@marcogroppo
Copy link
Author

@toanctruong If you are using Docker you can just docker run marcogroppo/systemd-cloud-watch. If you are not using Docker this is the exact sequence of commands I use to build the application: https://github.com/marcogroppo/systemd-cloud-watch/blob/master/Dockerfile

@fiunchinho
Copy link

hey @marcogroppo can you share a working systemd unit that uses the docker container of your fork to send journald logs to cloudwatch?
Thanks!!

@marcogroppo
Copy link
Author

@fiunchinho sorry I'm not using it via systemd, I'm using it directly via docker-compose. For example: https://gist.github.com/marcogroppo/cd8b635f4639ccbf4a8f04bf2a98f2ae Please notice that you need to mount /var/log/journal inside the container (like I'm doing in the "volumes" section of the file). Ignore the filters if you just want to send everything; ignore the AWS_* environment variables and the ec2_instance_id if you're running on EC2. Aside from the logging driver the docker-compose configuration in the example should be equivalent to this docker command:

docker run -d -v ./conf/systemd-cloud-watch:/conf:ro -v /var/log/journal:/var/log/journal:ro -e AWS_ACCESS_KEY_ID='XXX' -e AWS_SECRET_ACCESS_KEY='YYY' marcogroppo/systemd-cloud-watch /conf/systemd-cloud-watch.config

@iskandar
Copy link

iskandar commented Oct 8, 2017

I extracted the binary like this:

$ docker run --rm --entrypoint "/bin/bash"  -v $(pwd):/foo -it marcogroppo/systemd-cloud-watch 
root@b232f9660574:/go/src# cp -v /go/bin/systemd-cloud-watch /foo

And now have the binary in my current directory:

$ file systemd-cloud-watch
systemd-cloud-watch: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, not stripped

@holyjak
Copy link

holyjak commented Jan 12, 2018

@marcogroppo can this be used to filter by unit name? I.e. if I add something like

filters = ["systemdUnit=cron.service"]

then I will only get logs from cron? Thanks!

PS: It would be nice to also update the README with the filters option and ideally also an example?

@marcogroppo
Copy link
Author

@jakubholynet this should work (in theory):

filters = ["_SYSTEMD_UNIT=cron.service"]

but I have not tested it. The special fields are documented here:
https://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html

@holyjak
Copy link

holyjak commented Jan 13, 2018 via email

@analytically
Copy link

Is there an issue getting this merged?

@holyjak
Copy link

holyjak commented Feb 11, 2018

@RichardHightower hello, can this be merged and a new version released, please? Thank you!

@dokterbob
Copy link

poke

@donovan
Copy link

donovan commented Sep 18, 2018

@RichardHightower @MammatusPlatypus ping

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.

8 participants