Skip to content

Instantly share code, notes, and snippets.

@sandys
Last active March 19, 2023 20:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandys/9c3798f60caaa6449a889bd7b605a177 to your computer and use it in GitHub Desktop.
Save sandys/9c3798f60caaa6449a889bd7b605a177 to your computer and use it in GitHub Desktop.
Getting Datadog logs to work with Docker Swarm or journald
[Unit]
Description=Datadog Docker Swarm
After=systemd-journald.service
Requires=systemd-journald.service
[Service]
ExecStart=/bin/zsh -c "coproc while true; do ncat --ssl intake.logs.datadoghq.com 10516; done ;journalctl -o json -f | jq -r --unbuffered '\"c441ade4f5f4d04c \" + ({ message:.MESSAGE, service_name:.COM_DOCKER_SWARM_SERVICE_NAME, container:.CONTAINER_NAME, containerid:.CONTAINER_ID_FULL, host:._HOSTNAME,pid:(._PID // \"-\"), timestamp:(.__REALTIME_TIMESTAMP|tonumber/1000000|todate),\"syslog.severity\":((.PRIORITY|tonumber)) }|tostring)' >&p 2>&p"
ExecStop=/bin/sh -c "pkill -f 'journalctl -o json -f'"
TimeoutStartSec=0
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target
[X-Fleet]
Global=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment