DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • What Will Red Hat Acquiring CoreOS Mean for the Kubernetes Ecosystem?
  • Automated Testing Lifecycle
  • Docker and Kubernetes Transforming Modern Deployment
  • Using Open Source for Data Integration and Automated Synchronizations

Trending

  • Automate Migration Assessment With XML Linter
  • Supercharging Productivity in Microservice Development With AI Tools
  • Breaking Free From the Cloud With Kamal: Just Enough Orchestration for Your Apps
  • API Design
  1. DZone
  2. Software Design and Architecture
  3. Containers
  4. Sending CoreOS Logs to Loggly

Sending CoreOS Logs to Loggly

Trying to get CoreOS logs over to Loggly? There might be an easier way than you think.

Karen Sowa user avatar by
Karen Sowa
·
Oct. 30, 15 · Tutorial
Like (3)
Save
Tweet
Share
3.33K Views

Join the DZone community and get the full member experience.

Join For Free

There are many ways to send logs to Loggly from a Docker container environment:

  • Using a Loggly Docker container
  • My sidecar approach
  • Using logspout

All of these methods will work on CoreOS, but I have an even simpler way for you, one that doesn’t require you to run another container to send logs to Loggly. This blog will show you how to bind a lightweight logging unit to any process you start on a CoreOS cluster using the built-in CoreOS tool: Fleet. Fleet is a standard tool for controlling units (Docker processes) on a CoreOS cluster.

As with the other two solutions, the approach I describe will not maintain persistence of data when there is a network outage. This may or may not be important to you.

Here is an example that assumes we started up a Fleet unit named “nginx.service” and that this nginx service is a global unit which means it is on every machine on the cluster. Given that, we can start up our logging unit to get the logs out of each of those “nginx.service” units and send them over to Loggly.

Here is the Fleet unit file: logging-nginx.service

[Unit]Description=nginx-loggingAfter=docker.service
[Service]
EnvironmentFile=/etc/environment

EnvironmentFile=/etc/stackName

TimeoutStartSec=0

User=core

Restart=always

RestartSec=10
Environment=”LOGGLY_TAG_SERVICE_NAME=nginx”
ExecStart=/bin/bash -c ‘/usr/bin/journalctl -u nginx.service -o short-iso -f | /usr/bin/awk \'{ print “<34>1″, $1, $2, $3, ” – – “, “[<LOGGLY KEY>@41058 tag=\’${LOGGLY_TAG_SERVICE_NAME}\’ tag=\’${STACK_NAME}\’]”, $0; fflush(); }\’ | /usr/bin/ncat –ssl logs-01.loggly.com 6514′
[X-Fleet]

Global=true  

Start the logging unit by issuing this command on the CoreOS cluster:

fleetctl start nginx-logging.service

Let’s go through the “ExecStart” section to see what is going on. The rest is fairly standard Fleet usage. The command consists of three sections.  

The first section –“/usr/bin/journalctl -u nginx.service -o short-iso -f” – tails the log for the “nginx.service” unit.  

Then this is piped to the next section:“/usr/bin/awk \'{ print "<34>1", $1, $2, $3, " - - ", "[<LOGGLY_KEY>@41058tag=\’${LOGGLY_TAG_SERVICE_NAME}\’ tag=\’${STACK_NAME}\’]”, $0; fflush(); }\’ “. This section looks complicated but basically it is putting the log in a format to be sent to Loggly which includes your Loggly customer token. The red section should be replaced by your own Loggly customer token. Tags for Loggly are also added here. One tag is sourced from the CoreOS cluster’s environment file so that the environment name is included and the service this log belongs to is also added.

Here is the file content of the “stackName” file that the unit file sources.

File: /etc/stackName

STACK_NAME=”my-stack”    

Then all of that is finally piped to the last statement:“/usr/bin/ncat --ssl logs-01.loggly.com 6514”. This statement uses the simple but very effective “ncat” tool to send the log via SSL to Loggly. This would send it over reliable TCP and through an encrypted channel. (Most syslog solutions use UDP, a much less reliable  transport; if the packet is lost, there is no retransmission of it. Sending it over UDP can lead to lost log events. You can read more about UDP versus TCP here). 

The method described in this post is a quick and very efficient way to send logs to Loggly from Docker containers on a CoreOS cluster. The reason why we like using this method is because we don’t have to start a syslog container just to ship logs out. We can use the native cluster facilities to help us ship the logs to Loggly.  

This article was written by Garland Kan.

CoreOS Docker (software)

Published at DZone with permission of Karen Sowa. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • What Will Red Hat Acquiring CoreOS Mean for the Kubernetes Ecosystem?
  • Automated Testing Lifecycle
  • Docker and Kubernetes Transforming Modern Deployment
  • Using Open Source for Data Integration and Automated Synchronizations

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: