<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Stefan Thies</title>
    <description>The latest articles on Forem by Stefan Thies (@seti321).</description>
    <link>https://forem.com/seti321</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F138892%2F70ce1f6d-f731-49e4-a58b-50b2a8430627.png</url>
      <title>Forem: Stefan Thies</title>
      <link>https://forem.com/seti321</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/seti321"/>
    <language>en</language>
    <item>
      <title>How To Centralize Logs: Linux System Journal</title>
      <dc:creator>Stefan Thies</dc:creator>
      <pubDate>Tue, 16 Jul 2019 15:09:55 +0000</pubDate>
      <link>https://forem.com/sematext/how-to-centralize-logs-linux-system-journal-jpa</link>
      <guid>https://forem.com/sematext/how-to-centralize-logs-linux-system-journal-jpa</guid>
      <description>&lt;p&gt;Did you know that most Linux systems have a complete log management solution onboard? Distributions based on &lt;code&gt;systemd&lt;/code&gt; contain &lt;code&gt;journald&lt;/code&gt; and &lt;code&gt;journalctl&lt;/code&gt;.   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;systemd-journald&lt;/strong&gt; - All Linux system processes write logs to the system journal, which is managed by &lt;code&gt;journald&lt;/code&gt;. The system journal is local log storage. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;journalctl&lt;/strong&gt;* is the command-line client to display logs with various filter options like time, system unit or any other field stored in the log event. For advanced searches, it is possible to pipe the output to grep, which makes it easy to apply complex search expressions to journalctl output. &lt;br&gt;
The journalctl client is not only useful for log search, but it also provides various other functions such as management of the system journal storage. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;systemd-journal-upload&lt;/strong&gt; is a service to forward log events to a remote &lt;code&gt;journald&lt;/code&gt; instance. Configuring &lt;code&gt;journal-upload&lt;/code&gt; on all your Linux machines forwarding log events to a central log server is the best way to centralize logs. Then you can use &lt;code&gt;journalctl&lt;/code&gt; on the central log server for log search.  Even though the Linux console is cool, you want a web UI to search logs and visualize extracted data for easier and more practical troubleshooting.&lt;/p&gt;

&lt;p&gt;Shipping the logs to the Elastic Stack is a common practice to centralize logs, but how can this be done with journald? &lt;/p&gt;

&lt;p&gt;Unlike rsyslog, journald has no option to forward logs directly to Elasticsearch. As we need json data the output of &lt;code&gt;journalctl -o json&lt;/code&gt; could be useful. Piping the output of journalctl to Logagent could be a solution:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;journalctl -o json -f | logagent -i mylogs -u http://elasticsearch:9200&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Cool, it works! However, the running processes would not catch logs at boot time or recover gracefully after a restart - we might lose some logs - a nogo!&lt;/p&gt;

&lt;p&gt;Luckily, &lt;a href="https://sematext.com/logagent/" rel="noopener noreferrer"&gt;Logagent&lt;/a&gt; has got a &lt;a href="https://sematext.com/docs/logagent/input-plugin-journald-upload/" rel="noopener noreferrer"&gt;plugin&lt;/a&gt; that receives logs from the &lt;code&gt;systemd-journal-upload&lt;/code&gt; service. Let’s start from scratch and set up Logagent to receive journald logs and store them in Elasticsearch or Sematext Cloud.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/systemd-journal-upload.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/systemd-journal-upload.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Logagent as a local logging hub
&lt;/h2&gt;

&lt;p&gt;To run Logagent you will need a Logs App Token first. If you don't have Sematext Logs Apps yet, you can &lt;a href="https://apps.sematext.com/ui/integrations" rel="noopener noreferrer"&gt;create Logs Apps now&lt;/a&gt;.&lt;br&gt;
Then you can &lt;a href="https://sematext.com/docs/logagent/installation/" rel="noopener noreferrer"&gt;install Logagent&lt;/a&gt;. The default setup ships log files from /var/log to Sematext Cloud. To run Logagent you will need a Logs App Token. &lt;/p&gt;

&lt;p&gt;To receive logs from the &lt;code&gt;journal-upload&lt;/code&gt; service, activate the plugin in &lt;code&gt;/etc/sematext/logagent.conf&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Global options&lt;/span&gt;
&lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;includeOriginalLine&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;


&lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
   &lt;span class="na"&gt;journal-upload&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;input-journald-upload&lt;/span&gt;
    &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;9090&lt;/span&gt;
    &lt;span class="na"&gt;worker&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
    &lt;span class="na"&gt;systemdUnitFilter&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
      &lt;span class="na"&gt;include&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!!js/regexp&lt;/span&gt; &lt;span class="s"&gt;/.*/i&lt;/span&gt;
    &lt;span class="c1"&gt;# exclude: !!js/regexp /docker|containerd/i&lt;/span&gt;
    &lt;span class="c1"&gt;# add static tags to every log event &lt;/span&gt;
    &lt;span class="na"&gt;tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
     &lt;span class="na"&gt;log_shipper&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;logagent&lt;/span&gt;
     &lt;span class="c1"&gt;# _index is special tag for log routing with elasticsearch output-plugin&lt;/span&gt;
     &lt;span class="c1"&gt;# Set the index name here in case journald logs should be &lt;/span&gt;
     &lt;span class="c1"&gt;# stored in a separate index&lt;/span&gt;
     &lt;span class="c1"&gt;# _index: MY_INDEX_FOR_ELASTICSEARCH_OUTPUT or &lt;/span&gt;
     &lt;span class="c1"&gt;#         YOUR_SEMATEXT_LOGS_TOKEN_HERE&lt;/span&gt;
     &lt;span class="c1"&gt;# you can add any other static tag &lt;/span&gt;
     &lt;span class="c1"&gt;# node_role: kubernetes_worker&lt;/span&gt;
     &lt;span class="c1"&gt;# journald might provide many fields, &lt;/span&gt;
     &lt;span class="c1"&gt;# to reduce storage usage you can remove redundant fields&lt;/span&gt;
    &lt;span class="na"&gt;removeFields&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;__CURSOR&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;__REALTIME_TIMESTAMP&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;_SOURCE_REALTIME_TIMESTAMP&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;__MONOTONIC_TIMESTAMP&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;_TRANSPORT&lt;/span&gt;

&lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
  &lt;span class="c1"&gt;# output data for debugging on stdout in YAML format&lt;/span&gt;
  &lt;span class="c1"&gt;# stdout: yaml&lt;/span&gt;
  &lt;span class="na"&gt;sematext-cloud&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;elasticsearch&lt;/span&gt;
    &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://logsene-receiver.sematext.com&lt;/span&gt;
    &lt;span class="c1"&gt;# url: https://logsene-receiver.eu.sematext.com&lt;/span&gt;
    &lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;YOUR_SEMATEXT_LOGS_TOKEN_HERE&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can restart the &lt;code&gt;logagent&lt;/code&gt; service with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl restart logagent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfect, our logging hub for journald logs is running. &lt;/p&gt;

&lt;p&gt;Let’s move on to set up the &lt;code&gt;systemd-journal-upload&lt;/code&gt; on our Linux server.&lt;/p&gt;

&lt;h1&gt;
  
  
  Setup systemd-journal-upload
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Note: Please note the example uses 127.0.0.1 as IP address for Logagent. You should replace 127.0.0.1 with the IP address with the actual IP of the server you run logagent.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use the following command to install &lt;code&gt;systemd-journal-remote&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install systemd-journal-remote
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Edit &lt;code&gt;/etc/systemd/journal-upload.conf&lt;/code&gt; and change the URL property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Upload]
URL=http://127.0.0,1:9090
# ServerKeyFile=/etc/ssl/private/journal-upload.pem
# ServerCertificateFile=/etc/ssl/certs/journal-upload.pem
# TrustedCertificateFile=/etc/ssl/ca/trusted.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will make sure &lt;code&gt;journal-upload&lt;/code&gt; starts on boot. &lt;/p&gt;

&lt;p&gt;Note that the upload service might stop if creating the HTTP connection doesn't work. Should that happen the service stores the current cursor position in the system-journal. Therefore, you should set useful restart options in the service definition. &lt;/p&gt;

&lt;p&gt;Edit &lt;code&gt;/etc/systemd/system/multi-user.target.wants/systemd-journal-upload.service&lt;/code&gt; to change restart options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Unit]
Description=Journal Remote Upload Service
Documentation=man:systemd-journal-upload(8)
After=network.target


[Service]
ExecStart=/lib/systemd/systemd-journal-upload \
          --save-state
User=systemd-journal-upload
SupplementaryGroups=systemd-journal
PrivateTmp=yes
PrivateDevices=yes
#WatchdogSec=3min
Restart=always
TimeoutStartSec=1
TimeoutStopSec=1
StartLimitBurst=1000
StartLimitIntervalSec=5
# If there are many split up journal files we need a lot of fds to
# access them all and combine
LimitNOFILE=16384
[Install]
WantedBy=multi-user.target
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the changes and restart &lt;code&gt;journal-upload&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl daemon-reload
sudo systemctl enable systemd-journal-upload.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check if your logs arrive in Sematext Cloud by opening your Logs App. &lt;br&gt;
The following &lt;a href="https://www.youtube.com/embed/glwZ8OCV0kc?list=PLT_fd32OFYpfLBFZz_HiafnqjdlTth1NS" rel="noopener noreferrer"&gt;video&lt;/a&gt; shows how to use the Sematext UI.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/glwZ8OCV0kc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>linux</category>
      <category>devops</category>
      <category>elasticstack</category>
    </item>
    <item>
      <title>Best Practices for Efficient Log Management and Monitoring</title>
      <dc:creator>Stefan Thies</dc:creator>
      <pubDate>Tue, 16 Apr 2019 10:52:13 +0000</pubDate>
      <link>https://forem.com/sematext/best-practices-for-efficient-log-management-and-monitoring-577d</link>
      <guid>https://forem.com/sematext/best-practices-for-efficient-log-management-and-monitoring-577d</guid>
      <description>

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--INsKCoEK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/04/Log-Management-best-practices-final-Fl-1024x560.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--INsKCoEK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/04/Log-Management-best-practices-final-Fl-1024x560.jpg" alt="log management and monitoring best practices"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When managing cloud-native applications, it’s essential to have end-to-end visibility into what’s happening at any given time. This is especially true because of the distributed and dynamic nature of cloud-native apps, which are often deployed using ephemeral technologies like containers and serverless functions.&lt;/p&gt;

&lt;p&gt;With so much flux and complexity across a cloud-native system, it’s important to have robust monitoring and logging in place to control and manage the inevitable chaos. This post discusses what we consider to be some of the ** best practices and standards to follow when logging and monitoring cloud-native applications**.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Use a managed logging solution vs building your own infrastructure
&lt;/h2&gt;

&lt;p&gt;First off, logging should reflect your applications. In a world of cloud-native applications, logging solutions should be built on the same principles as high availability, distributed processing, and intelligent failover that consequently lay the foundation for the applications themselves. This is what differentiates modern cloud-native apps from legacy monolithic apps.&lt;/p&gt;

&lt;p&gt;The tools to implement this approach include Elasticsearch, Fluentd, Kibana (which, together, are often called the EFK stack), and others. They are architected to handle large-scale data analysis and deliver results in real time. They facilitate complex search queries over data and enable open API-based integration with other tools. However, though the raw materials are available, bringing it all together and making sure it meets your purposes is a whole other challenge.&lt;/p&gt;

&lt;p&gt;Rather than build out this system on your own, it makes sense to use a &lt;a href="https://sematext.com/logsene/"&gt;managed logging solution&lt;/a&gt; that is built and scaled by a vendor. We go over that in detail in &lt;a href="https://sematext.com/blog/5-benefits-run-elastic-stack-in-the-cloud/"&gt;5 Reasons to Run Elastic Stack in the Cloud&lt;/a&gt;.  With &lt;a href="https://sematext.com/integrations/"&gt;ready-made integrations&lt;/a&gt;, all you need to do is connect your sources and destinations, and you’re all set to analyze application logs the easy way. This leaves you free to spend more time &lt;a href="https://sematext.com/metrics-and-logs/"&gt;monitoring and logging your application&lt;/a&gt; rather than building out logging infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Know what logs to monitor, and what not to monitor
&lt;/h2&gt;

&lt;p&gt;Know what not to log. Just because you can log something doesn’t mean you should — and logging too much data can make it harder to find the data that actually matters. It also adds complexity to your log storage and management processes because it gives you more logs to manage.&lt;/p&gt;

&lt;p&gt;Thus, consider carefully what you actually need to log. Any types of production-environment data that are critical for compliance or auditing purposes should certainly be logged. So should data that helps you troubleshoot performance problems, &lt;a href="https://sematext.com/experience/"&gt;solve user-experience issues&lt;/a&gt; or monitor security-related events.&lt;/p&gt;

&lt;p&gt;On the other hand, there are categories of data that you do not need to log, such as data from test environments that are not an essential part of your software delivery pipeline. There are also some kinds of data that you should not log for compliance or security reasons. For example, if a user has enabled a do-not-track setting, you should not log data associated with that user. Similarly, you should avoid logging highly sensitive data, such as credit-card numbers, unless you are certain that your logging and storage processes meet the security requirements for that data.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Implement a log security and retention policy
&lt;/h2&gt;

&lt;p&gt;Logs contain sensitive data. A log security policy should review sensitive data – like personal data of your clients or internal access keys for APIs. Make sure that sensitive data gets anonymized or encrypted before you ship logs to any third party. &lt;a href="https://dev.to/seti321/gdpr-top-5-logging-best-practices-3fal-temp-slug-3630712"&gt;GDPR log management best practices&lt;/a&gt; teaches you about good practices for data protection of sensitive data &lt;a href="https://sematext.com/docs/logagent/how-to-gdpr_web_logs/"&gt;and personal data in web server logs&lt;/a&gt;. The secure transport of log data to log management servers requires the setup of encrypted endpoints for TLS or HTTPS on client and server side.&lt;/p&gt;

&lt;p&gt;Logs from different sources might require different retention times. Some applications are only relevant for troubleshooting for a few days. Security-related or business transaction logs require longer retention times. Therefore, a retention policy should be flexible, depending on the log source.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Log Storage
&lt;/h2&gt;

&lt;p&gt;Planning the capacity for log storage should consider high load peaks. When systems run well, the amount of data produced per day is nearly constant and depends mainly on the system utilization and amount of transactions per day.  In the case of critical system errors, we typically see accelerated growth in the log volume. If the log storage hits storage limits, you lose the latest logs, which are essential to fix system errors. The log storage must work as a cyclic buffer, which deletes the oldest data first before any storage limit is applied.&lt;/p&gt;

&lt;p&gt;Design your log storage so that it’s scalable and reliable – there is nothing worse than having system downtimes and a lack of information for troubleshooting, which in turn, can elongate downtime.&lt;/p&gt;

&lt;p&gt;Log storage should have a separate security policy. Every attacker will try to avoid or delete his traces in log files. Therefore you should ship logs in real-time to the central log storage. If the attacker has access to your infrastructure, sending logs off-site, e.g., using a &lt;a href="https://sematext.com/logsene/"&gt;logging SaaS&lt;/a&gt; will help keep evidence untampered.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Review &amp;amp; constantly maintain your logs
&lt;/h2&gt;

&lt;p&gt;Unmaintained log data could lead to longer troubleshooting times, risks of exposing sensitive data or higher costs for log storage. Review the log output of your applications and adjust it to your needs. Reviews should cover usability, operational and security aspects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create meaningful log messages
&lt;/h3&gt;

&lt;p&gt;Readable and useful log messages are key for faster troubleshooting. If logs contain only some error codes or ‘cryptic’ error messages it can be difficult to understand. As a Developer, you can save your organization a lot of time by providing a meaningful log message.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use structured log formats
&lt;/h3&gt;

&lt;p&gt;The log format should be structured (e.g., JSON or key/value format) having various fields like timestamp, severity, message and any other relevant data fields like process ID, transaction ID, etc. If you don’t use a unique log format for all your applications, normalize the logs in the log shipper. Parse logs and store logs in a structured format.&lt;/p&gt;

&lt;h3&gt;
  
  
  Make log level configurable
&lt;/h3&gt;

&lt;p&gt;Some applications logs are too verbose and other application logs don’t provide enough information about the activities. Adjustable log levels are the key to configure the verbosity of logs. Another topic for log reviews is the challenge to balance between logging relevant information and not exposing personal data or security-related information. If so, make sure that those messages can be anonymized or encrypted.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inspect audit logs frequently
&lt;/h3&gt;

&lt;p&gt;Acting on security issues is crucial – so you should always have an eye on audit logs. Setup security tools such as auditd or OSSEC agents. The tools implement real-time log analysis and generate alert logs pointing to potential security issues. On top of such audit logs, you should define alerts on logs in order to be notified quickly on any suspicious activity. For more details, check out &lt;a href="https://dev.to/sematext/monitoring-linux-audit-logs-with-auditd-and-auditbeat-2m2n-temp-slug-9179415"&gt;a quick tutorial on using auditd&lt;/a&gt;, plus you’ll find some complementary frameworks too.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use a checklist for log reviews:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Is the log message meaningful for users?&lt;/li&gt;
&lt;li&gt;Does the log message include context for troubleshooting?&lt;/li&gt;
&lt;li&gt;Are the log message structured and include

&lt;ul&gt;
&lt;li&gt;timestamp,&lt;/li&gt;
&lt;li&gt;severity/log level&lt;/li&gt;
&lt;li&gt;message&lt;/li&gt;
&lt;li&gt;additional troubleshooting information in separate fields&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Are 3rd party logs parsed and structured (configure log shipper)?&lt;/li&gt;
&lt;li&gt;Are log levels configurable?&lt;/li&gt;
&lt;li&gt;Does the log message include personal data or security-related data?&lt;/li&gt;
&lt;li&gt;Inspect audit logs and adjust log alert rules&lt;/li&gt;
&lt;li&gt;Setup alerts on logs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. Don’t do log analysis in a silo: Correlate all data sources
&lt;/h2&gt;

&lt;p&gt;Connect the dots. Logging is one part of an entire monitoring strategy. To practice truly effective monitoring, you need to complement your logging with other types of monitoring like monitoring based on &lt;a href="https://sematext.com/events/"&gt;events&lt;/a&gt;, &lt;a href="https://sematext.com/alerts/"&gt;alerts&lt;/a&gt; and &lt;a href="http://www.sematext.com/tracing"&gt;tracing&lt;/a&gt;. This is the only way to get the whole story of what’s happening at any point in time. Logs are great for giving you high-definition detail on issues, but this is useful only once you’ve seen the forest and are ready to zoom into the trees. Metrics and events at an aggregate level may be more effective, especially when starting to troubleshoot an issue.&lt;/p&gt;

&lt;p&gt;Don’t look at logs in a silo — Complement them with other types of monitoring like &lt;a href="https://sematext.com/application-monitoring/"&gt;APM&lt;/a&gt;, &lt;a href="https://sematext.com/network-monitoring/"&gt;network monitoring&lt;/a&gt;,&lt;a href="https://sematext.com/spm/"&gt; infrastructure monitoring&lt;/a&gt;, and more. See &lt;a href="https://sematext.com/blog/apm-vs-log-management/"&gt;APM vs. Log Management&lt;/a&gt; for more detail. This also means that the monitoring solution you use should be comprehensive enough to provide all your monitoring information in one place, or flexible enough to easily integrate with other tools that provide this information. This way, as a user, you have a &lt;a href="https://sematext.com/"&gt;single-pane view of your entire stack&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. View logging as an enabler of GitOps
&lt;/h2&gt;

&lt;p&gt;For busy DevOps teams, it’s easy to view logging as a nice-to-have, or an add-on that you can embrace once you’ve figured out automated CI/CD pipelines and are releasing more frequently. However, another way to look at logging is to see it as an enabler of DevOps and CI/CD. To practice automation at every step of the development pipeline, you need the visibility to know where issues are introduced, and what the main sources of these issues are — faulty code, dependency issues, external attacks, insufficient resources, or something else. The causes can be innumerable, but logging gives you the insight you need to find and fix these issues.&lt;/p&gt;

&lt;p&gt;As continuous integration increasingly becomes about enabling GitOps at the very start of the pipeline, there’s a need to not compromise on quality and security authentication in the name of automation and speed.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Get real-time feedback on any type of events
&lt;/h2&gt;

&lt;p&gt;Automated testing and new approaches like headless testing are making it possible to get real-time feedback on every single code change in a developer environment, even before a commit. As testing shifts left, and there is an increasing focus on the start of the pipeline, logging is essential to gain visibility and enable GitOps. Without the appropriate testing and logging, you’ll be left with runaway releases and deployment hell.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Use logging to identify automation opportunities &amp;amp; trends
&lt;/h2&gt;

&lt;p&gt;Logging helps to catch issues early on in the pipeline and saves your team valuable time and energy. It also helps you find opportunities for automation. You can set up custom alerts to trigger when something breaks, and even set up automated actions to be initiated when these alerts are triggered. Whether it’s through Slack, a custom script, or a Jenkins automation plugin, you can drive automation in your GitOps process using logs. For all these reasons, you need to view logging as an enabler and driver of GitOps rather than an add-on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion &amp;amp; next steps
&lt;/h2&gt;

&lt;p&gt;In conclusion, logging is an essential part of building and managing cloud-native apps. For logging to be successful, it should reflect the state of your applications and be able to scale along with them. Logging should never be done in a silo. This is why a monitoring solution for cloud-native applications should consider other types of monitoring and metrics. Logging can often be viewed as an afterthought, but teams that want to go all the way with GitOps see logging as a driver and enabler of observability, and hence, as indispensable.&lt;/p&gt;

&lt;p&gt;Looking for a full stack monitoring solution? &lt;a href="https://apps.sematext.com/ui/registration?utm_source=blog&amp;amp;utm_medium=BestStrategies"&gt;Try Sematext Cloud free for 30 days.&lt;/a&gt; Sematext bridges the gap between logs, metrics, real user monitoring and tracing allowing you to benefit from faster actionable insights&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;About the Authors *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SzWg99AK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/04/twain-profile-150x150.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SzWg99AK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/04/twain-profile-150x150.png" alt="twain profile"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Twain Taylor | Contributor&lt;/p&gt;

&lt;p&gt;Twain is a Fixate IO Contributor and began his career at Google, where, among other things, he was involved in technical support for the AdWords team. His work involved reviewing stack traces, and resolving issues affecting both customers and the Support team, and handling escalations. Later, he built branded social media applications, and automation scripts to help startups better manage their marketing operations. Today, as a technology journalist he helps IT magazines, and startups change the way teams build and ship applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--esaY6uES--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/03/stefan-Thies-150x150.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--esaY6uES--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/03/stefan-Thies-150x150.png" alt="stefan Thies"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Stefan Thies | DevOps Evangelist | Sematext&lt;/p&gt;

&lt;p&gt;10+ years of work experience as a product manager and pre-sales engineer in the telecommunications industry. Passionate about new software technologies and scalable system architectures. Likes NodeJS for POCs.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://sematext.com/blog/best-practices-for-efficient-log-management-and-monitoring/"&gt;Best Practices for Efficient Log Management and Monitoring&lt;/a&gt; appeared first on &lt;a href="https://sematext.com"&gt;Sematext&lt;/a&gt;.&lt;/p&gt;


</description>
      <category>logging</category>
      <category>centralisedlog</category>
      <category>logmanagement</category>
    </item>
    <item>
      <title>Better Observability with New Container Agents</title>
      <dc:creator>Stefan Thies</dc:creator>
      <pubDate>Wed, 03 Apr 2019 09:33:56 +0000</pubDate>
      <link>https://forem.com/sematext/better-observability-with-new-container-agents-16c</link>
      <guid>https://forem.com/sematext/better-observability-with-new-container-agents-16c</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FV2_better-observability-new-monitoring-agent-FI-1024x560.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FV2_better-observability-new-monitoring-agent-FI-1024x560.jpg" alt="better observability new container monitoring agent sematext"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a New Docker Agent?
&lt;/h2&gt;

&lt;p&gt;If you liked Sematext Docker Agent you’ll love our new agent for Docker monitoring that provides you with even more insight into your Docker, Kubernetes, and Swarm clusters.  Because of its power, small footprint, and ease of installation the old Sematext Docker Agent enjoyed high adoption by the Docker DevOps community.&lt;/p&gt;

&lt;p&gt;An all-in-one Docker monitoring tool, certified by Docker since 2015, it could &lt;a href="https://sematext.com/blog/top-docker-metrics-to-watch/" rel="noopener noreferrer"&gt;monitor all key Docker metrics&lt;/a&gt;, container events, as well as &lt;a href="https://sematext.com/docs/logagent/parser/" rel="noopener noreferrer"&gt;collect and parse logs&lt;/a&gt;.  However, container technology is developing rapidly – Docker Enterprise and Kubernetes gained in popularity, as did cloud container platforms like Google GKE.  It was time for an update.  Except, we didn’t just update it.  We rewrote it, made it even smaller and more modular, and much more powerful.  The new Sematext Agent can monitor not only Docker containers but also see inside them.  It has &lt;a href="https://sematext.com/blog/streamlined-kubernetes-cluster-agent/" rel="noopener noreferrer"&gt;first-class Kubernetes monitoring&lt;/a&gt; support and &lt;a href="https://sematext.com/blog/linux-kernel-observability-ebpf/" rel="noopener noreferrer"&gt;kernel tracing&lt;/a&gt; capabilities, all with super low CPU and memory footprint.&lt;/p&gt;

&lt;p&gt;To better serve the need for advanced monitoring and advanced logging functionality we’ve split the agent in two.  This enables faster release cycles and even easier deployment for each specific use case – embracing containerized architectures and orchestration tools. There are two separate images but – importantly – you still benefit from having a single deployment via Helm on Kubernetes.&lt;/p&gt;

&lt;p&gt;The following new images replace the old Sematext Docker Agent:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://hub.docker.com/r/sematext/agent" rel="noopener noreferrer"&gt;sematext/agent&lt;/a&gt; – container monitoring, infrastructure monitoring, cluster monitoring and events from container engines and orchestration tools&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://hub.docker.com/r/sematext/logagent/" rel="noopener noreferrer"&gt;sematext/logagent&lt;/a&gt; – log collection, log parsing, log enrichment, and log shipping for containers&lt;/li&gt;
&lt;li&gt;Both images are &lt;a href="https://hub.docker.com/publishers/sematext" rel="noopener noreferrer"&gt;Docker certified&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together with the new monitoring agent, we introduced new Dashboards to display the collected data, such as &lt;a href="https://sematext.com/blog/docker-container-monitoring-with-sematext/" rel="noopener noreferrer"&gt;Container Infrastructure monitoring&lt;/a&gt; and Kubernetes cluster metrics.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fserver-monitoring-2-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fserver-monitoring-2-1.png" alt="Container monitoring with heatmap"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Container monitoring with heatmap&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FScreen-Shot-2018-11-26-at-14.55.15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FScreen-Shot-2018-11-26-at-14.55.15.png" alt="Kubernetes Dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Kubernetes Dashboard –&lt;/em&gt; tracking deployment status and Pod restarts over time&lt;/p&gt;

&lt;p&gt;So let’s introduce you to sematext/logagent &amp;amp; sematext/agent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Container Logs Processing with Logagent
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://sematext.com/logagent/" rel="noopener noreferrer"&gt;Logagent&lt;/a&gt; is a general purpose open-source log shipper. The &lt;a href="https://hub.docker.com/_/logagent" rel="noopener noreferrer"&gt;Logagent Docker image&lt;/a&gt; is pre-configured for the &lt;a href="https://sematext.com/blog/docker-container-monitoring-with-sematext/#toc-container-logs-0" rel="noopener noreferrer"&gt;log collection on container platforms&lt;/a&gt;. It runs as a tiny container on every Docker host and collects logs for all cluster nodes and their containers. All container logs are enriched with Kubernetes, Docker Enterprise, and Docker Swarm metadata.&lt;/p&gt;

&lt;p&gt;The deployment of Logagent is very similar to the deployment of Sematext Docker Agent and is fully compatible with all its &lt;a href="https://sematext.com/docs/logagent/installation-docker/#configuration-parameters" rel="noopener noreferrer"&gt;configurations options for logs&lt;/a&gt;. The format for &lt;a href="https://sematext.com/docs/logagent/parser/" rel="noopener noreferrer"&gt;log parser patterns&lt;/a&gt; also remains the same. Logagent, like its predecessor, recognizes log formats from various applications / official images out of the box.&lt;/p&gt;

&lt;p&gt;The following little example shows how easy it is to deploy Logagent, run a web server, and get structured web server logs for web analytics in Sematext.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="c"&gt;# Start Logagent&lt;/span&gt;
docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--restart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;always &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;LOGS_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YourLogsToken &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-v&lt;/span&gt; /var/run/docker.sock:/var/run/docker.socksematext/logagent
&lt;span class="c"&gt;# Start Nginx web server&lt;/span&gt;
docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 8081:80 nginx
&lt;span class="c"&gt;# Access the web server&lt;/span&gt;
curl http://127.0.0.1:8081

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few seconds later, we see the result in Sematext, beautiful, structured web server logs including container metadata.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FScreen-Shot-2019-03-12-at-14.35.26.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FScreen-Shot-2019-03-12-at-14.35.26.png" alt="Structured web server logs with container metadata"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Structured web server logs with container metadata&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;With a few clicks, we can add widgets to create a web server logs dashboard, showing Top IP addresses and Top URLs or containers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FScreen-Shot-2019-03-12-at-14.43.56.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FScreen-Shot-2019-03-12-at-14.43.56.png" alt="Sematext UI with Top N widgets for various log fields"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Sematext UI with Top N widgets for various log fields&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That was easy for logs, so let’s have a look at the new Docker monitoring agent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Monitoring Containers with Sematext Agent
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://sematext.com/docs/containers/sematext-agent/" rel="noopener noreferrer"&gt;Sematext Agent&lt;/a&gt; collects metrics about hosts (CPU, memory, disk, network, processes), containers and orchestrator platforms and ships that to &lt;a href="https://sematext.com/cloud" rel="noopener noreferrer"&gt;Sematext Cloud&lt;/a&gt;. To gain deep insight into the Linux kernel, Sematext Agent relies on eBPF to implant instrumentation points (attach eBPF programs to kprobes) on kernel functions. Using Linux kernel instrumentation allows Sematext Agent a very efficient and powerful system exploration approach. It has the ability to auto-discover services deployed on physical machines, virtual hosts, and containers, as well as a mechanism for collecting &lt;a href="https://sematext.com/inventory-monitoring" rel="noopener noreferrer"&gt;infrastructure inventory&lt;/a&gt; info. It also collects events from different sources such as OOM notifications, container or Kubernetes events.&lt;/p&gt;

&lt;p&gt;The plethora of information collected to provide you with full stack observability of your applications, services, and infrastructure is neatly organized in dashboards for &lt;a href="https://sematext.com/spm" rel="noopener noreferrer"&gt;infrastructure monitoring&lt;/a&gt;, &lt;a href="https://sematext.com/docker" rel="noopener noreferrer"&gt;container monitoring&lt;/a&gt; and &lt;a href="https://sematext.com/kubernetes" rel="noopener noreferrer"&gt;Kubernetes cluster monitoring&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Kernel Tracing with eBPF&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Many traditional monitoring agents are based on checks running periodically. Such checks run scripts and may even use commands like ‘ps -efa’ to discover running processes. There are several disadvantages to periodical checks. For example, periodical checks could miss short-running processes. Depending on the frequency of the checks they have their own overhead. &lt;a href="https://sematext.com/blog/linux-kernel-observability-ebpf/" rel="noopener noreferrer"&gt;Linux kernel observability using eBPF&lt;/a&gt;, on the other hand, can trace &lt;em&gt;any&lt;/em&gt; kernel function call in the user space. Using eBPF makes it possible to automatically discover new processes without periodical checks. There is a lot more eBPF can do.  For instance, it can also discover any file system changes or network activity of all processes, including containers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fimage8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fimage8.png" alt="eBPF architecture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;eBPF architecture – Source:&lt;/em&gt; &lt;em&gt;&lt;a href="https://github.com/cilium/cilium/#what-is-ebpf-and-xdp" rel="noopener noreferrer"&gt;https://github.com/cilium/cilium/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The new Sematext Agent makes heavy use of eBPF for auto-discovery of processes and their activity. To do that, Sematext Agent attaches bytecode at various hook points in the kernel to detect:&lt;br&gt;&lt;br&gt;
– Process creation and termination&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Socket listen/accept&lt;/li&gt;
&lt;li&gt;Signals&lt;/li&gt;
&lt;li&gt;Out of memory errors&lt;/li&gt;
&lt;li&gt;File system activity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because eBPF is not available in older Linux kernels the agent also has fallback mechanisms like polling /procfs. If you are curious whether eBPF is available on your machines, have a look at the new &lt;a href="https://sematext.com/inventory-monitoring" rel="noopener noreferrer"&gt;Inventory Monitoring&lt;/a&gt; in Sematext, as it displays all Linux kernel versions used across your infrastructure.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Low CPU &amp;amp; Memory Footprint&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Saving money on cloud resources is a hot topic for every company deploying applications to the cloud.  Keeping costs down is a must for any company that wants to be competitive in today’s markets.  We are very keenly aware of that, being a fully bootstrapped and cost-conscious organization ourselves.  Sematext Agent is a native binary.  As such, it doesn’t have the overhead of a runtime environment such as JVM, Ruby, Python, etc.  Moreover, we have put a lot of effort into profiling and minimizing the Sematext Agent memory and CPU footprint to make it nearly invisible when it’s running on your infrastructure.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Container and Kubernetes Monitoring&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;What are the advantages of the new agent for container monitoring?&lt;/p&gt;

&lt;p&gt;First of all the Docker Remote API is limited to Docker environments, while Kubernetes emerged to the most popular orchestration tool. In addition more and more alternative container runtimes are available on the market. Therefore the new Sematext Agent takes a container runtime agnostic approach for container monitoring.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Container runtime agnostic discovery and monitoring

&lt;ul&gt;
&lt;li&gt;Automatic container discovery&lt;/li&gt;
&lt;li&gt;Support for &lt;a href="https://www.docker.com/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt; and &lt;a href="https://github.com/rkt/rkt" rel="noopener noreferrer"&gt;Rkt&lt;/a&gt; container engines&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Container metrics

&lt;ul&gt;
&lt;li&gt;CPU usage&lt;/li&gt;
&lt;li&gt;Disk space usage and IO stats&lt;/li&gt;
&lt;li&gt;Memory usage, memory limits, and memory fail counters&lt;/li&gt;
&lt;li&gt;Network IO stats&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Host inventory information

&lt;ul&gt;
&lt;li&gt;Host kernel version and other system information, like distro, architecture, number of CPUs, etc.&lt;/li&gt;
&lt;li&gt;Information about installed software packages&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Container metadata

&lt;ul&gt;
&lt;li&gt;Container name&lt;/li&gt;
&lt;li&gt;Image name&lt;/li&gt;
&lt;li&gt;Container networks&lt;/li&gt;
&lt;li&gt;Container volumes&lt;/li&gt;
&lt;li&gt;Container environment&lt;/li&gt;
&lt;li&gt;Container labels including relevant information about orchestration&lt;/li&gt;
&lt;li&gt;Kubernetes metadata such as Pod name, UUID, namespace&lt;/li&gt;
&lt;li&gt;Docker Swarm metadata such as service name, swarm task, etc.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Collection of container events

&lt;ul&gt;
&lt;li&gt;Docker events such as start/stop/die/volume mount, etc.&lt;/li&gt;
&lt;li&gt;Kubernetes events such as Pod status changes deployed, destroyed, etc.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Tracking deployment status and Pod restarts over time&lt;/li&gt;

&lt;li&gt;Process metrics such as CPU usage, memory usage and disk IO&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Let’s see how Sematext Agent is deployed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started with Sematext Agent
&lt;/h3&gt;

&lt;p&gt;To run Sematext Agent you will need a Docker App token. If you don’t have any Docker Apps yet, you can &lt;a href="https://apps.sematext.com/ui/integrations" rel="noopener noreferrer"&gt;create one now&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
The Sematext UI &lt;a href="https://apps.sematext.com/ui/howto/docker/overview" rel="noopener noreferrer"&gt;displays copy and paste instructions&lt;/a&gt; for various ways of deployments for Docker, Docker Enterprise/Swarm, Kubernetes DaemonSets or Helm charts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fezgif-4-9c0c90a37622-1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fezgif-4-9c0c90a37622-1.gif" alt="setup sematext agent"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://sematext.com/docs/containers/sematext-agent/" rel="noopener noreferrer"&gt;Sematext Agent Documentation&lt;/a&gt; contains all configuration options. After a short time you will see container information in the infrastructure monitoring, Docker and Kubernetes reports.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Migration&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When migrating to the new agents you can do a simple “nearly in-place replacement” by first removing the old agent and then quickly setting up the new ones.  This may result in a bit of gap in your metrics and logs between the time you remove the old Sematext Docker Agent and set up the new ones, but the switch to new agents should take only a few minutes.  If this short gap in data is not acceptable, but a bit of data duplication is, then you can switch the order of operations – set up new agents first and then remove the old one.&lt;/p&gt;

&lt;p&gt;Please read &lt;a href="https://sematext.com/blog/docker-container-monitoring-with-sematext/" rel="noopener noreferrer"&gt;Monitoring Docker With Sematext&lt;/a&gt;, it shows all details, useful options for the agent deployments, log search tips, alert rule definition and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What Else is Planned in the Near Future?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The new Sematext Agent has the ability to auto-discover running inside containers.  Once the discovered services are exposed in Sematext the Sematext Agent will enable you to seamlessly start monitoring applications you have running inside your containers. The automatic deployment will work on bare metal and VM servers, Docker Enterprise and Kubernetes.&lt;/p&gt;

&lt;p&gt;Logagent will grow its &lt;a href="https://github.com/sematext/logagent-js" rel="noopener noreferrer"&gt;open-source repository&lt;/a&gt; of supported log formats and plugins for hands-free log collection and parsing.&lt;/p&gt;

&lt;p&gt;The new agent includes process monitoring and package inventory collection capabilities, which will soon start showing up in the Sematext UI, so if you don’t have the new agent now is a good time to upgrade your Sematext Agent!&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://sematext.com/blog/better-observability-new-container-agents/" rel="noopener noreferrer"&gt;Better Observability with New Container Agents&lt;/a&gt; appeared first on &lt;a href="https://sematext.com" rel="noopener noreferrer"&gt;Sematext&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>monitoring</category>
      <category>containermonitoring</category>
      <category>devops</category>
      <category>docker</category>
    </item>
    <item>
      <title>Docker Container Monitoring Open Source Tools</title>
      <dc:creator>Stefan Thies</dc:creator>
      <pubDate>Mon, 01 Apr 2019 16:30:05 +0000</pubDate>
      <link>https://forem.com/sematext/docker-container-monitoring-open-source-tools-2afj</link>
      <guid>https://forem.com/sematext/docker-container-monitoring-open-source-tools-2afj</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo23z83gp2ln226mrsrxh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo23z83gp2ln226mrsrxh.jpg" alt="Docker Container Monitoring Open Source Tools"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Part 1: &lt;a href="https://sematext.com/blog/docker-container-monitoring-management-challenges/" rel="noopener noreferrer"&gt;Docker Container monitoring and management Challenges&lt;/a&gt; – we discussed why container monitoring is challenging, especially in the context of orchestration tools. In Part 2 we described &lt;a href="https://sematext.com/blog/top-docker-metrics-to-watch/" rel="noopener noreferrer"&gt;Top 10 Container Metrics to Monitor&lt;/a&gt;.  Next, let’s have a look at examples and available container monitoring tools for better operational insights into container deployments.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Command Line Tools&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The first step to get visibility into your container infrastructure is probably using the built-in tools like &lt;a href="https://sematext.com/docker-commands-cheat-sheet/" rel="noopener noreferrer"&gt;docker command line&lt;/a&gt; and &lt;a href="https://sematext.com/kubernetes-cheat-sheet/" rel="noopener noreferrer"&gt;kubectl for Kubernetes&lt;/a&gt;. There’s a whole set of commands that are used to find the relevant information about containers. Please note that the usage of kubectl and docker command is typically available to only a few people who have direct access to the orchestration tool. Nevertheless, all cloud engineers require command line skills and, in some situations, command line tools are indeed the only tools available.&lt;/p&gt;

&lt;p&gt;Before we start looking at Docker log collection tools, check out these two useful Docker Cheatsheets.&lt;/p&gt;

&lt;p&gt;Check out &lt;a href="https://dev.to/docker-commands-cheat-sheet/?utm_medium=blogpost&amp;amp;utm_source=blogpost&amp;amp;utm_campaign=docker-container-monitoring-open-source-tools-blogpost&amp;amp;utm_content=blog-docker-commands-cheatsheet"&gt;Docker Commands Cheat Sheet&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check out &lt;a href="https://dev.to/docker-swarm-cheat-sheet/?utm_medium=blogpost&amp;amp;utm_source=blogpost&amp;amp;utm_campaign=docker-container-monitoring-open-source-tools-blogpost&amp;amp;utm_content=blog-doecker-smarm-cheatsheet"&gt;Docker Swarm Cheat Sheet&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are several monitoring dashboards available for orchestration tools like Rancher, Portainer, Docker Enterprise. They typically provide a simple real-time metrics and a real-time logs view. The navigation to containers takes a few clicks.  However, overviews with aggregated metrics or cluster-wide log search are typically not integrated. As such, the basic monitoring functionality in most orchestration tools is simply too basic.  Better tools are needed.  Let’s look at some more attractive and capable monitoring and log management solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Open Source Tools for Docker Monitoring, Logging and Tracing&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Several &lt;a href="https://sematext.com/blog/open-source-docker-monitoring-logging/" rel="noopener noreferrer"&gt;open source tools are available for DIY-style container monitoring and logging&lt;/a&gt;. Typically logs and metrics are stored in different data stores. Elastic Stack is the tool of choice for logs while &lt;a href="https://prometheus.io/" rel="noopener noreferrer"&gt;Prometheus&lt;/a&gt; is popular for metrics.&lt;/p&gt;

&lt;p&gt;Depending on your metrics and logs data store choices you may need to use a different set of data collectors and dashboard tools. &lt;a href="https://github.com/influxdata/telegraf" rel="noopener noreferrer"&gt;Telegraf&lt;/a&gt; and Prometheus are the most flexible open source data collectors we’ve evaluated. Prometheus exporters need a scraper (Prometheus Server or alternative 3rd party scraper) or a remote storage interface for Prometheus Server to store metrics in alternative data stores. Grafana is the most flexible monitoring dashboard tool with support for most data sources like Prometheus, InfluxDB, Elasticsearch, etc.&lt;/p&gt;

&lt;p&gt;Kibana and metric beats for data collection are tightly bound to Elasticsearch and are thus not usable with any other data store.&lt;/p&gt;

&lt;p&gt;The following matrix shows which data collectors typically play with which storage engine and monitoring dashboard tool. Note there are several other variations possible.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Data Collector for Containers&lt;/th&gt;
&lt;th&gt;Storage / Time Series DB&lt;/th&gt;
&lt;th&gt;User Interface&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Log collectors&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;---&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fluentd&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Filebeat&lt;/td&gt;
&lt;td&gt;Elasticsearch&lt;/td&gt;
&lt;td&gt;Kibana&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Telegraf / syslog + docker syslog driver&lt;/td&gt;
&lt;td&gt;InfluxDB&lt;/td&gt;
&lt;td&gt;Grafana, Chronograf&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logagent&lt;/td&gt;
&lt;td&gt;Elasticsearch &amp;amp; Sematext Cloud&lt;/td&gt;
&lt;td&gt;Kibana &amp;amp; Sematext&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Metric collectors&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;---&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Prometheus Exporters&lt;/td&gt;
&lt;td&gt;Prometheus&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Various 3rd party and commercial integrations&lt;/td&gt;
&lt;td&gt;Promdash, Grafana&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Metric Beats&lt;/td&gt;
&lt;td&gt;Elasticsearch&lt;/td&gt;
&lt;td&gt;Kibana&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Telegraf&lt;/td&gt;
&lt;td&gt;InfluxDB&lt;/td&gt;
&lt;td&gt;Grafana, Chronograf&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Telegraf Elasticsearch output&lt;/td&gt;
&lt;td&gt;Elasticsearch&lt;/td&gt;
&lt;td&gt;Kibana&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sematext Agent&lt;/td&gt;
&lt;td&gt;InfluxDB &amp;amp; Sematext Cloud&lt;/td&gt;
&lt;td&gt;Chronograf &amp;amp; Sematext Cloud&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Compatibility of monitoring tools and time series storage engines&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The Elastic Stack might seem like an excellent candidate to unify metrics and logs in one data store.  As providers of &lt;a href="https://semaext.com/consulting/elasticsearch" rel="noopener noreferrer"&gt;Elasticsearch consulting&lt;/a&gt;, training, and &lt;a href="https://semaext.com/support/elasticsearch" rel="noopener noreferrer"&gt;Elasticsearch support&lt;/a&gt; we would love nothing more than everyone using Elasticsearch for not just logs, but also metrics. However, the truth is that &lt;strong&gt;Elasticsearch is not the most efficient as time series databases for metrics&lt;/strong&gt;. Trust us, we’ve run numerous benchmarks, applied all kinds of performance tuning tricks from our rather big back of Elasticsearch tricks, but it turns out there are better, more efficient, faster data stores for metrics than Elasticsearch.  The setup and maintenance of logging and monitoring infrastructure become complicated when it reaches a larger scale.&lt;/p&gt;

&lt;p&gt;After the initial setup of storage engines for metrics and logs the time-consuming work starts: the setup of log shippers and monitoring agents, dashboards and alert rules. Dealing with log collection for containers can be tricky, so you’ll want to consult &lt;a href="https://sematext.com/blog/top-10-docker-logging-gotchas/" rel="noopener noreferrer"&gt;top 10 Docker logging gotchas&lt;/a&gt; and &lt;a href="https://sematext.com/blog/docker-log-driver-alternatives/" rel="noopener noreferrer"&gt;Docker log driver alternatives&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Docker Monitoring with Grafana&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After the setup of data collectors, we need to visualize metrics and logs. The most popular dashboard tools are Grafana and Kibana. Grafana does an excellent job as a dashboard tool for showing data from a number of data sources including Elasticsearch, InfluxDB, and Prometheus. In general, though, Grafana is really more tailored for metrics even though &lt;a href="https://sematext.com/blog/using-grafana-with-elasticsearch-for-log-analytics-2/" rel="noopener noreferrer"&gt;using Grafana for logs with Elasticsearch&lt;/a&gt; is possible, too. Grafana is still very limited for ad-hoc log searches but has integrated alerting on logs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9070da2f0g8nlflbtxa7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9070da2f0g8nlflbtxa7.png" alt="grafana"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Docker Monitoring with Kibana&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Kibana, on the other hand, supports only Elasticsearch as a data source. Some dashboard views are “impossible” to implement because different monitoring and logging tools have limited options to correlate data from different data stores. Once dashboards are built and ready to share with the team, the next hot topic for Kibana users is security, authentication and role-based access control (RBAC).  Grafana supports user authentication and simple roles, while Kibana (or in general the Elastic Stack) requires X-Pack as commercial extensions to support various security features like user authentication and RBAC. Depending on the requirements of your organization one of the &lt;a href="https://sematext.com/blog/x-pack-alternatives/" rel="noopener noreferrer"&gt;X-Pack Alternatives&lt;/a&gt; might be helpful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpdqk7stf85kccahakulb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpdqk7stf85kccahakulb.png" alt="kibana"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Total Cost of Ownership
&lt;/h3&gt;

&lt;p&gt;When planning the setup of open source monitoring people often underestimate the amount of data generated by monitoring agents and log shippers. More specifically, most organizations underestimate the resources needed for processing, storage, and retrieval of metrics and logs as their volume grows and, even more importantly, organizations often underestimate the human effort and time that will have to be invested into ongoing maintenance of the monitoring infrastructure and open-source tools. When that happens not only does the cost of infrastructure for monitoring and logging jump beyond anyone’s predictions, but so does the time and thus money required for maintenance.  A common way to deal with this is to limit data retention.  This requires fewer resources, less expertise needed to scale the infrastructure and tools and thus less maintenance, but this, of course, limits visibility and insights one can derive from long-term data.&lt;/p&gt;

&lt;p&gt;Infrastructure costs are only one reason why we often see limited storage for metrics, traces, and logs. For example, InfluxDB has no clustering or sharding in the open source edition, and &lt;a href="https://prometheus.io/docs/prometheus/latest/storage/#remote-storage-integrations" rel="noopener noreferrer"&gt;Prometheus supports only short retention time&lt;/a&gt; to avoid performance problems.&lt;/p&gt;

&lt;p&gt;Another approach used for dealing with that is the reduction of granularity of metrics from 10-second accuracy to a minute or even more, sampling, and such. As a consequence, DevOps teams have less accurate information with less time to analyze problems, and limited view visibility for permanent or recurring issues, conducting historical trend analysis, or capacity planning.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Microservices Distributed Transaction Tracing&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this post, we discussed only monitoring and logging.  We completely ignoring &lt;a href="https://sematext.com/tracing/" rel="noopener noreferrer"&gt;distributed transaction tracing&lt;/a&gt; as the third pillar of observability for a moment. Keep in mind that as soon we start collecting transaction traces across microservices, the amount of data will explode and thus further increase the total cost of ownership of an on-premise monitoring setup. Note that data collection tools mentioned in this post handle only metrics and logs, not traces (for more on transaction tracing and, more specifically OpenTracing-compatible tracers see our &lt;a href="https://sematext.com/blog/jaeger-vs-zipkin-opentracing-distributed-tracers/" rel="noopener noreferrer"&gt;Jaeger vs. Zipkin)&lt;/a&gt;. Similarly, the dashboard tools we covered here don’t come with data collection and visualizations for transaction traces. &lt;strong&gt;This means that for distributed transaction tracing we need the third set of tools if we want to put together and run our own monitoring setup – welcome to the DevOps jungle!&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;DIY Container Monitoring Pros and Cons&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There are a number of &lt;a href="https://sematext.com/blog/open-source-docker-monitoring-logging/" rel="noopener noreferrer"&gt;open source container observability tools for logging, monitoring, and tracing&lt;/a&gt;. If you and your team have time and if observability really needs to be your team’s core competency, you’ll need to invest time into finding the most promising tools, learning how to actually use them while evaluating them, and finally install, configure, and maintaining them. It would be wise to compare multiple solutions and check how well various tools play together.   We suggest the following evaluation criteria:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Coverage of collected metrics&lt;/strong&gt;. Some tools collect only a few metrics, some gather a ton of metrics (which you may not really need), while other tools let you configure which metrics to collect. Missing relevant metrics can be frustrating when one is working under pressure to solve a production issue, just like having too many or wrong metrics will make it harder to locate signals that truly matter. Tools that &lt;em&gt;require&lt;/em&gt; configuration for collection or visualization of each metric are time-consuming to set up and maintain. Don’t choose such tools.  Instead, look for tools that give you good defaults and freedom to customize which metrics to collect.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Coverage of log formats&lt;/strong&gt;. A typical application stack consists of multiple components like databases, web servers, message queues, etc. Make sure that you can &lt;a href="https://sematext.com/logagent/" rel="noopener noreferrer"&gt;structure logs&lt;/a&gt; from your applications. This is key if you want to use your logs not only for troubleshooting, but also for deriving insights from logs.  Defining &lt;a href="https://sematext.com/docs/logagent/parser/" rel="noopener noreferrer"&gt;log parser patterns&lt;/a&gt; with regular expressions or grok is time-consuming. It is very helpful having a &lt;a href="https://github.com/sematext/logagent-js/blob/master/patterns.yml" rel="noopener noreferrer"&gt;library of existing patterns&lt;/a&gt;. This is a time saver, especially in the container world when you use official docker images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collection of events&lt;/strong&gt;. Any indication of why a service was restarted or crashed will help you classify problems quickly and get to the root cause faster. Any container monitoring tool should thus be collecting &lt;a href="https://docs.docker.com/engine/reference/commandline/events/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;&lt;a href="https://docs.docker.com/engine/reference/commandline/events/" rel="noopener noreferrer"&gt; events&lt;/a&gt; and Kubernetes status events if you run Kubernetes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Correlation of metrics, logs, and traces&lt;/strong&gt;. Whether you initially spot a problem through metrics, logs, or traces, having access to all these observability data makes troubleshooting so much faster. A single UI displaying data from various sources is thus key for an interactive drill down, fast troubleshooting, faster MTTR and, frankly, makes devops’ job more enjoyable. &lt;a href="https://sematext.com/metrics-and-logs/" rel="noopener noreferrer"&gt;See example&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Machine Learning capabilities and&lt;/strong&gt; &lt;strong&gt;&lt;a href="https://sematext.com/alerts/" rel="noopener noreferrer"&gt;anomaly detection for alerting on logs and metrics&lt;/a&gt;&lt;/strong&gt;. Threshold-based alerts work well only for known and constant workloads. In dynamic environments, threshold-based alerts create too much noise.  Make sure the solution you select has this core capability and that it doesn’t take ages to learn the baseline or require too much tweaking, training, and such.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Detect and&lt;/strong&gt; &lt;strong&gt;&lt;a href="https://sematext.com/product-updates/#/2018/automatic-metrics-correlation" rel="noopener noreferrer"&gt;correlate metrics&lt;/a&gt;&lt;/strong&gt;** with the same behavior.** When metrics behave in similar patterns, we typically find one of the metrics is the symptom of the root cause of a performance bottleneck. A good example we have seen in practice is high CPU usage paired with container swap activity and disk IO – in such a case CPU usage and even more disk IO could be reduced by switching off swapping for containers.   For system metrics above the correlation is often known – but when you track your application-specific metrics you might find new correlation and bottlenecks in your microservices to optimize.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Single sign-on.&lt;/strong&gt;  Correlating data stored in silos is impossible.  Moreover, using multiple services often requires multiple accounts and forces you to learn not one, but multiple services, their UIs, etc.  Each time you need to use both of them there is the painful overhead of needing to adjust things like time ranges before you can look at data in them in separate windows. This costs time and money and makes it harder to share data with the team.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Role-based access control.&lt;/strong&gt;  Lack of RBAC ** ** is going to be a show-stopper for any tool seeking adoption at the corporate level. Tools that work fine for small teams and SMBs, but lack multi-user support with roles and permissions almost never meet requirements of large enterprises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Concluding above, DevOps engineers need well-integrated monitoring, logging and tracing solution with advanced functionality like correlating between metrics, traces and logs. The saved costs of engineering and infrastructure required to run in-house monitoring can quickly pay off. Adjustable data retention times per monitored service help to optimize costs and satisfy operational needs. The better user experience for your DevOps team helps a lot, especially faster troubleshooting minimizes the revenue loss once a critical bug or performance issue hits your commercial services. In part 4 we will describe &lt;a href="https://sematext.com/blog/docker-container-monitoring-with-sematext/" rel="noopener noreferrer"&gt;container monitoring with Sematext&lt;/a&gt;. While developing &lt;a href="https://sematext.com/cloud/" rel="noopener noreferrer"&gt;Sematext Cloud&lt;/a&gt;, we had had the above ideas in mind with the goal to provide a better container monitoring solution.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://sematext.com/blog/open-source-docker-monitoring-logging/" rel="noopener noreferrer"&gt;Docker Container Monitoring Open Source Tools&lt;/a&gt; appeared first on &lt;a href="https://sematext.com" rel="noopener noreferrer"&gt;Sematext&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>logging</category>
      <category>monitoring</category>
      <category>devops</category>
      <category>docker</category>
    </item>
    <item>
      <title>Docker Container Performance Metrics</title>
      <dc:creator>Stefan Thies</dc:creator>
      <pubDate>Mon, 01 Apr 2019 16:25:18 +0000</pubDate>
      <link>https://forem.com/sematext/docker-container-performance-metrics-3a09</link>
      <guid>https://forem.com/sematext/docker-container-performance-metrics-3a09</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FDocker-monitoring-part-2-FI_black-1024x560.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FDocker-monitoring-part-2-FI_black-1024x560.jpg" alt="Docker container performance metrics"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Part 1 we’ve described &lt;a href="https://dev.to/sematext/docker-container-monitoring-and-management-challenges-4480-temp-slug-2993350"&gt;what makes monitoring container environments challenging&lt;/a&gt;. Because each container typically runs a single process, has its own environment, utilizes virtual networks, or has various methods of managing storage. Traditional monitoring solutions take metrics from each server and the applications they run. These servers and applications running on them are typically very static, with very long uptimes. Container deployments are different: a set of containers may run many applications, all sharing the resources of one or more underlying hosts. It’s not uncommon for Docker servers to run thousands of short-term containers (e.g.. for batch jobs) while a set of permanent services runs in parallel. Traditional monitoring tools not used to such dynamic environments are not suited for such deployments. On the other hand, some modern monitoring solutions were built with such dynamic systems in mind and even have out of the box reporting for &lt;a href="https://sematext.com/docker" rel="noopener noreferrer"&gt;docker monitoring&lt;/a&gt;. Moreover, container resource sharing calls for stricter enforcement of resource usage limits, an additional issue you must watch carefully. To make appropriate adjustments for resource quotas you need good visibility into any limits containers may have reached or errors they may have encountered or caused. We recommend using &lt;a href="https://sematext.com/alerts" rel="noopener noreferrer"&gt;monitoring alerts&lt;/a&gt; according to defined limits; this way you can adjust limits or resource usage even before errors start happening.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fdocker-overview.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fdocker-overview.png" alt="docker container monitoring overview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: All screenshots in this post are from&lt;/em&gt; &lt;em&gt;&lt;a href="https://sematext.com/cloud" rel="noopener noreferrer"&gt;Sematext Cloud&lt;/a&gt;&lt;/em&gt;_ and its_ &lt;em&gt;&lt;a href="https://sematext.com/docker" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;&lt;/em&gt;&lt;em&gt;&lt;a href="https://sematext.com/docker" rel="noopener noreferrer"&gt;monitoring&lt;/a&gt;&lt;/em&gt;&lt;em&gt;&lt;a href="https://sematext.com/docker" rel="noopener noreferrer"&gt;integration&lt;/a&gt;&lt;/em&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Watch Resources of Your Docker Hosts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Host CPU
&lt;/h3&gt;

&lt;p&gt;Understanding the CPU utilization of hosts and containers helps one optimize the resource usage of Docker hosts.  The container CPU usage can be throttled in order to avoid a single busy container slowing down other containers by using up all available CPU resources.  Throttling the CPU time is a good way to ensure the minimum of processing power needed by essential services – it’s like the good old nice levels in Unix/Linux.&lt;/p&gt;

&lt;p&gt;When the resource usage is optimized, a high CPU utilization might actually be expected and even desired, and alerts might make sense only for when CPU utilization drops (think service outages) or increases for a longer period over some max limit (e.g. 85%).&lt;/p&gt;

&lt;h3&gt;
  
  
  Host Memory
&lt;/h3&gt;

&lt;p&gt;The total memory used in each Docker host is important to know for the current operations and for capacity planning. Dynamic cluster managers like Docker Swarm use the total memory available on the host and the requested memory for containers to decide on which host a new container should ideally be launched. Deployments might fail if a cluster manager is unable to find a host with sufficient resources for the container. That’s why it is important to know the host memory usage and the memory limits of containers. Adjusting the capacity of new cluster nodes according to the footprint of Docker applications could help optimize resource usage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Host Disk Space
&lt;/h3&gt;

&lt;p&gt;Docker images and containers consume additional disk space. For example, an application image might include a Linux operating system and might have a size of 150-700 MB depending on the size of the base image and installed tools in the container. Persistent Docker volumes consume disk space on the host as well. In our experience watching the disk space and using cleanup tools are essential for continuous operations of Docker hosts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FBildschirmfoto-2016-03-22-um-22.48.09.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FBildschirmfoto-2016-03-22-um-22.48.09.png" alt="Host Disk Space"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because disk space is very critical it makes sense to define alerts for disk space utilization to serve as early warnings and provide enough time to clean up disks or add additional volumes. For example, &lt;a href="https://sematext.com/spm/" rel="noopener noreferrer"&gt;Sematext Monitoring&lt;/a&gt; automatically sets alert rules for disk space usage for you, so you don’t have to remember to do it.&lt;/p&gt;

&lt;p&gt;A good practice is to run tasks to clean up the disk by removing unused containers and images frequently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Total Number of Running Containers
&lt;/h2&gt;

&lt;p&gt;The current and historical number of containers is an interesting metric for many reasons.  For example, it is very handy during deployments and updates to check that everything is running like before.&lt;/p&gt;

&lt;p&gt;When cluster managers like Docker Swarm, Mesos, Kubernetes automatically schedule containers to run on different hosts using different scheduling policies, the number of containers running on each host can help one verify the activated scheduling policies. A stacked bar chart displaying the number of containers on each host and the total number of containers provides a quick visualization of how the cluster manager distributed the containers across the available hosts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FScreen-Shot-2019-03-06-at-13.58.27.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FScreen-Shot-2019-03-06-at-13.58.27.png" alt="Container counts per Docker host over time"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Container counts per Docker host over time&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This metric can have different “patterns” depending on the use case. For example, batch jobs running in containers vs. long-running services commonly result in different container count patterns.  A batch job typically starts a container on demand or starts it periodically, and the container with that job terminates after a relatively short time.  In such a scenario one might see a big variation in the number of containers running resulting in a “spiky” container count metric. On the other hand, long-running services such as web servers or databases typically run until they get re-deployed during software updates. Although scaling mechanisms might increase or decrease the number of containers depending on load, traffic, and other factors, the container count metric will typically be relatively steady because in such cases containers are often added and removed more gradually. Because of that, there is no general pattern we could use for a default Docker alert rule on the number of running containers.&lt;/p&gt;

&lt;p&gt;Nevertheless, alerts based on &lt;a href="https://sematext.com/alerts/" rel="noopener noreferrer"&gt;anomaly detection&lt;/a&gt;, which detect sudden changes in the number of the containers in total (or for specific hosts) in a short time window, can be very handy for most of the use cases. The simple threshold-based alerts make sense only when the maximum or the minimum number of running containers is known, and in dynamic environments that scale up and down based on external factors, this is often not the case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker Container Metrics
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://sematext.com/docs/integration/docker" rel="noopener noreferrer"&gt;Docker container metrics&lt;/a&gt; are basically the same metrics available for every Linux process but include limits set via cgroups by Docker, such as limits for CPU or memory usage. Please note that sophisticated monitoring solutions like &lt;a href="https://sematext.com/cloud" rel="noopener noreferrer"&gt;Sematext Cloud&lt;/a&gt; are able to aggregate container metrics on different levels like Docker Hosts/Cluster Nodes, Image Name or ID and Container Name or ID.  Having the ability to do that makes it easy to track resources usage by hosts, application types (image names) or specific containers. In the following examples, we might use aggregations on various levels.&lt;/p&gt;

&lt;h3&gt;
  
  
  Container CPU  – Throttled CPU Time
&lt;/h3&gt;

&lt;p&gt;One of the most basic bits of information is information about how much CPU is being consumed by all containers, images, or by specific containers. A great advantage of using Docker is the capability to limit CPU utilization by containers.  Of course, you can’t tune and optimize something if you don’t measure it, so monitoring such limits is essential.  Observing the total time a container’s CPU usage was throttled provides the information one needs to adjust the setting for &lt;a href="https://docs.docker.com/engine/reference/run/#cpu-share-constraint" rel="noopener noreferrer"&gt;CPU shares in Docker&lt;/a&gt;. Please note that CPU time is throttled only when the host CPU usage is maxed out.  As long as the host has spare CPU cycles available for Docker it will not throttle containers’ CPU usage. Therefore, the throttled CPU is typically zero and a spike of this metric is typically a good indication of one or more containers needing more CPU power than the host can provide.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FScreen-Shot-2019-03-06-at-13.49.47.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FScreen-Shot-2019-03-06-at-13.49.47.png" alt="Container CPU usage and throttled CPU time"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Container CPU usage and throttled CPU time&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Container Memory – Fail Counters
&lt;/h3&gt;

&lt;p&gt;It is a good practice to set memory limits for containers.  Doing that helps avoid a memory-hungry container taking all available memory and starving all other containers on the same server. Runtime constraints on resources can be defined in the &lt;a href="https://docs.docker.com/engine/reference/run/" rel="noopener noreferrer"&gt;Docker run command&lt;/a&gt;.  For example, “-m 300M” sets the memory limit for the container to 300 MB. Docker exposes a metric called container memory fail counters.  This counter is increased each time memory allocation fails — that is, each time the pre-set memory limit is hit.  Thus, spikes in this metric indicate one or more containers needing more memory than was allocated.  If the process in the container terminates because of this error, we might also see out of memory events from Docker.&lt;/p&gt;

&lt;p&gt;A spike in memory fail counters is a critical event and putting alerts on the memory fail counter is very helpful to detect wrong settings for the memory limits or to discover containers that try to consume more memory than expected.&lt;/p&gt;

&lt;h3&gt;
  
  
  Container Memory Usage
&lt;/h3&gt;

&lt;p&gt;Different applications have different memory footprints. ** ** Knowing the memory footprint of the application containers is important for having a stable environment. ** ** Container memory limits ensure that applications perform well, without using too much memory, which could affect other containers on the same host.  The best practice is to tune memory setting in a few iterations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Monitor memory usage of the application container&lt;/li&gt;
&lt;li&gt;Set memory limits according to the observations&lt;/li&gt;
&lt;li&gt;Continue monitoring of memory, memory fail counters and Out-Of-Memory events. If OOM events happen, the container memory limits may need to be increased, or debugging is required to find the reason for the high memory consumptions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FBildschirmfoto-2016-03-22-um-22.53.56.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FBildschirmfoto-2016-03-22-um-22.53.56.png" alt="Container memory usage"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Container memory usage&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Container Swap
&lt;/h3&gt;

&lt;p&gt;Like the memory of any other process, a container’s memory could be swapped to disk. For applications like Elasticsearch or Solr one often finds instructions to deactivate swap on the Linux host – but if you run such applications on Docker it might be sufficient just to set  “–memory-swappiness=0” in the Docker run command!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FBildschirmfoto-2016-03-22-um-22.57.21.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FBildschirmfoto-2016-03-22-um-22.57.21.png" alt="Container swap, memory pages, and swap rate"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Container swap, memory pages, and swap rate&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Container Disk I/O
&lt;/h3&gt;

&lt;p&gt;In Docker, multiple applications use the same resources concurrently.  Thus, watching the disk I/O helps one define limits for specific applications and give higher throughput to critical applications like data stores or web servers, while throttling disk I/O for batch operations. For example, the command docker run -it –device-write-bps /dev/sda:1mb mybatchjob would limit the container disk writes to a maximum of 1 MB/s.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FBildschirmfoto-2016-02-08-um-19.09.55.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FBildschirmfoto-2016-02-08-um-19.09.55.png" alt="Container I/O throughput"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Container I/O throughput&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Container Network Metrics
&lt;/h3&gt;

&lt;p&gt;Networking for containers can be very challenging.  By default, all containers share a network, or containers might be linked together to share a separated network on the same host. However, when it comes to networking between containers running on different hosts an &lt;a href="https://en.wikipedia.org/wiki/Overlay_network" rel="noopener noreferrer"&gt;overlay network&lt;/a&gt; is required, or &lt;a href="https://docs.docker.com/network/network-tutorial-host/" rel="noopener noreferrer"&gt;containers could share the host network&lt;/a&gt;. Having many options for network configurations means there are many possible causes of network errors.&lt;/p&gt;

&lt;p&gt;Moreover, not only errors or dropped packets are important to watch out for.  Today, most of the applications are deeply dependent on network communication. The throughput of virtual networks could be a bottleneck especially for containers like load balancers. In addition, the network traffic might be a good indicator how much applications are used by clients and sometimes you might see high spikes, which could indicate denial of service attacks, load tests, or failures in client apps.&lt;/p&gt;

&lt;p&gt;So watch the container network traffic – it is a useful metric in many cases and complements &lt;a href="https://sematext.com/network-monitoring/" rel="noopener noreferrer"&gt;IT network monitoring&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FBildschirmfoto-2016-03-23-um-20.23.40.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FBildschirmfoto-2016-03-23-um-20.23.40.png" alt="Network traffic and transmission rates"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Network traffic and transmission rates&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;There you have it — the top Docker metrics to watch. Staying focused on these top metrics and corresponding analysis will help you stay on the road while driving towards successful Docker deployments on many platforms such as Docker Enterprise, Kubernetes, AWS EKS, Google GKS or any other platform supporting Docker containers.&lt;/p&gt;

&lt;p&gt;If you’d like to learn even more about Docker Monitoring and Logging continue to read Part 3  &lt;a href="https://sematext.com/blog/open-source-docker-monitoring-logging/" rel="noopener noreferrer"&gt;Container Monitoring Tools&lt;/a&gt; of this series.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://sematext.com/blog/top-docker-metrics-to-watch/" rel="noopener noreferrer"&gt;Docker Container Performance Metrics&lt;/a&gt; appeared first on &lt;a href="https://sematext.com" rel="noopener noreferrer"&gt;Sematext&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>monitoring</category>
      <category>docker</category>
      <category>dockercloud</category>
      <category>dockerswarm</category>
    </item>
    <item>
      <title>Docker Container Monitoring and Management Challenges</title>
      <dc:creator>Stefan Thies</dc:creator>
      <pubDate>Mon, 01 Apr 2019 16:22:06 +0000</pubDate>
      <link>https://forem.com/sematext/docker-container-monitoring-and-management-challenges-3jfe</link>
      <guid>https://forem.com/sematext/docker-container-monitoring-and-management-challenges-3jfe</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FDocker-monitoring-part-1-FI_black-1024x560.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2FDocker-monitoring-part-1-FI_black-1024x560.jpg" alt="container monitoring challenges"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Organizations that adopt container orchestration tools for application deployment face a new maintenance challenge. Orchestration tools like Kubernetes or Docker Swarm are designed to decide to which host a container should be deployed and potentially do that on an ongoing basis. Although this functionality is great for helping us make better use of the underlying infrastructure, it creates new challenges in production. While troubleshooting a common first question is “Which specific container is having issues?”.  The second question is often “On which host is it running?“. Being able to map container deployments to the underlying container hosts is essential for troubleshooting. But there is more to learn about &lt;a href="https://sematext.com/docker" rel="noopener noreferrer"&gt;container monitoring&lt;/a&gt;, let us see why &lt;a href="https://sematext.com/spm" rel="noopener noreferrer"&gt;infrastructure monitoring&lt;/a&gt; is different for containers.&lt;/p&gt;

&lt;p&gt;Monitoring a container infrastructure is different from traditional &lt;a href="https://sematext.com/server-monitoring" rel="noopener noreferrer"&gt;server monitoring&lt;/a&gt;. First of all, containers present a new infrastructure layer we simply didn’t have before. Secondly, we have to cope with dynamic placement in one or more clusters possibly running on different cloud services. Finally, containers provide new ways for resource management.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;New Infrastructure Layers&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Containers add a new layer to the infrastructure and the mapping of containers to servers lets us see where exactly in our infrastructure each container is running. Modern container monitoring tools must thus discover all running containers automatically in order to capture dynamic changes in the deployment and update the container to host mapping in real-time. Thus, the traditional server performance monitoring that is not designed with such requirements in mind is inadequate for monitoring containers.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;New Dynamic Deployment and Orchestration&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Container orchestration tools like &lt;a href="https://sematext.com/kubernetes" rel="noopener noreferrer"&gt;Kubernetes&lt;/a&gt; or &lt;a href="https://docs.docker.com/engine/swarm/" rel="noopener noreferrer"&gt;Docker Swarm&lt;/a&gt; are often used to dynamically allocate containers to the most suitable hosts, typically those that have sufficient resources to run them. Containers might thus move from one host to another, especially while scaling the number of containers up or down or during container redeployments. There is no static relation between hosts and services they are running anymore! For troubleshooting, this means one must first figure out which host is running which containers. And, vice versa, when a host exhibits poor performance, it’s highly valuable to be able to isolate which container is the source of the problem and if any containers suffer from the performance issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;New Resource Management and Metrics&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Containers use of resources can be restricted. Using inadequate container resource limits can lead to situations where a container performs poorly simply because it can’t allocate enough resources. At the same time, the cluster host itself might not be fully utilized. How could this problem be discovered and fixed?    A good example is monitoring memory fail counters – one of the &lt;a href="https://sematext.com/blog/top-docker-metrics-to-watch/" rel="noopener noreferrer"&gt;key container metrics&lt;/a&gt; or throttled CPU time. In such situations, monitoring just the overall server performance would not indicate any slowness of containers hitting resource limits. Only monitoring of the actual &lt;a href="https://sematext.com/docs/integration/docker/#metrics" rel="noopener noreferrer"&gt;container metrics&lt;/a&gt; for each container helps in this situation. Setting the right resource limits requires detailed knowledge of the resources a container might need under load. A good practice is to &lt;a href="https://sematext.com/docker" rel="noopener noreferrer"&gt;monitor container metrics&lt;/a&gt; and adjust the resource limits to match the actual needs or scale the number of containers behind a load balancer.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;New Log Management Needs&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Docker not only changed the deployment of applications, but also the workflow for log management. Instead of writing logs to files, Docker logs are console output streams from containers. Docker Logging Drivers collect and forward logs to their destinations.  To match this new logging paradigm, legacy applications need to be updated to write logs to the console instead of writing them to local log files. Some containers start multiple processes, therefore log streams might contain a mix of plain text messages from start scripts and unstructured or structured logs from different containerized applications.  The problem is obvious – you can’t just take both log streams (stderr/stdout) from multiple processes and containers, all mixed up, and treat them like a blob, or assume they all use the same log structure and format.  You need to be able to tell which log event belongs to what container, what app, parse it correctly, etc.&lt;/p&gt;

&lt;p&gt;To do log parsing right, the origin of the container log output needs to be identified.  That knowledge can then be used to apply the right parser and add metadata like container name, container image, container ID to each log event. Docker Log Drivers simplified logging a lot, but there are still many &lt;a href="https://dev.to/sematext/top-10-docker-logging-gotchas-1mlk"&gt;Docker logging gotchas&lt;/a&gt;.  Luckily, &lt;a href="https://sematext.com/logagent/" rel="noopener noreferrer"&gt;modern log shippers&lt;/a&gt; integrate with Docker API or Kubernetes API and are able to apply log parsers for different applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;New Microservice Architecture and Distributed Transaction Tracing&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Microservices have been around for over a decade under one name or another.  Now often deployed in separate containers it became obvious we needed a way to trace transactions through various microservice layers, from the client all the way down to queues, storage, calls to external services, etc.  This created a new interest in &lt;a href="https://sematext.com/tracing/" rel="noopener noreferrer"&gt;Distributed Transaction Tracing&lt;/a&gt; that, although not new, has now re-emerged as the &lt;a href="https://sematext.com/blog/opentracing-distributed-tracing-emerging-industry-standard/" rel="noopener noreferrer"&gt;third pillar of observability&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;New Container Monitoring Tools&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In Part 2 we’ll explore &lt;a href="https://sematext.com/blog/top-docker-metrics-to-watch/" rel="noopener noreferrer"&gt;key container metrics&lt;/a&gt; and in Part 3 we will learn &lt;a href="https://sematext.com/blog/open-source-docker-monitoring-logging/" rel="noopener noreferrer"&gt;essential monitoring commands and open-source monitoring tools for containers&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://sematext.com/blog/docker-container-monitoring-management-challenges/" rel="noopener noreferrer"&gt;Docker Container Monitoring and Management Challenges&lt;/a&gt; appeared first on &lt;a href="https://sematext.com" rel="noopener noreferrer"&gt;Sematext&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>monitoring</category>
      <category>containermonitoring</category>
      <category>containers</category>
    </item>
    <item>
      <title>Monitoring Elasticsearch with Sematext</title>
      <dc:creator>Stefan Thies</dc:creator>
      <pubDate>Wed, 27 Mar 2019 14:07:19 +0000</pubDate>
      <link>https://forem.com/sematext/monitoring-elasticsearch-with-sematext-2lcd</link>
      <guid>https://forem.com/sematext/monitoring-elasticsearch-with-sematext-2lcd</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2FNew_Elasticsearch-monitoring-part-4-1024x560.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2FNew_Elasticsearch-monitoring-part-4-1024x560.jpg" alt="Elasticsearch monitoring with sematext"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown in &lt;a href="https://sematext.com/blog/top-10-elasticsearch-metrics-to-watch/" rel="noopener noreferrer"&gt;Elasticsearch Key Metrics&lt;/a&gt;, the setup, tuning, and operations of Elasticsearch require deep insights into the performance metrics such as index rate, query rate, query latency, merge times, and many more. &lt;a href="https://sematext.com/" rel="noopener noreferrer"&gt;Sematext&lt;/a&gt; provides an excellent alternative to other Elasticsearch monitoring tools.&lt;/p&gt;

&lt;p&gt;Open-source tools to monitor Elasticsearch are free, but your time is not. Relatively speaking, they’re rather expensive. Thus, &lt;a href="https://sematext.com/cloud/" rel="noopener noreferrer"&gt;Sematext&lt;/a&gt;&lt;a href="https://sematext.com/cloud/" rel="noopener noreferrer"&gt; Cloud&lt;/a&gt; aims to save you time, effort, and your hair!&lt;/p&gt;

&lt;h2&gt;
  
  
  How Sematext Helps you Save Time
&lt;/h2&gt;

&lt;p&gt;Here are a few &lt;strong&gt;things you will&lt;/strong&gt;  &lt;strong&gt;NOT&lt;/strong&gt;**  have to do when using Sematext for Elasticsearch** monitoring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;figure out which metrics to collect and which ones to ignore&lt;/li&gt;
&lt;li&gt;give metrics meaningful labels&lt;/li&gt;
&lt;li&gt;hunt for metric descriptions in the docs so that you know what each one actually shows&lt;/li&gt;
&lt;li&gt;build charts to group metrics that you really want on the same charts, not several separate charts&lt;/li&gt;
&lt;li&gt;figure out which aggregation to use for each set of metrics (min? max? avg? something else?)&lt;/li&gt;
&lt;li&gt;build dashboards to combine charts with metrics you typically want to see together&lt;/li&gt;
&lt;li&gt;set up basic alert rules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of the above is not even a complete story. Do you want to collect Elasticsearch logs? How about structuring them? Sematext does all this automatically for you!&lt;/p&gt;

&lt;p&gt;In this post, we will look at how Sematext provides more comprehensive – and easy to set up – monitoring for Elasticsearch and other technologies in your infrastructure. By combining events, logs, and metrics together in one integrated &lt;a href="https://sematext.com/cloud" rel="noopener noreferrer"&gt;full stack observability platform&lt;/a&gt; and using the Sematext &lt;a href="https://sematext.com/blog/now-open-source-sematext-monitoring-agent/" rel="noopener noreferrer"&gt;open-source monitoring agent&lt;/a&gt; and its integrations, which are also open-source, you can monitor your whole infrastructure and apps, not just your Elasticsearch cluster. You can also get deeper visibility into your entire software stack by collecting, processing, and analyzing your logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Elasticsearch Monitoring&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Collecting Elasticsearch Metrics&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Sematext Elasticsearch integration collects &lt;a href="https://sematext.com/docs/integration/elasticsearch/" rel="noopener noreferrer"&gt;over 100 different Elasticsearch metrics&lt;/a&gt; for JVM, index performance, cluster health, query performance and more. Sematext maintains and supports &lt;a href="https://github.com/sematext/sematext-agent-integrations/tree/master/clickhouse" rel="noopener noreferrer"&gt;official Elasticsearch monitoring integration&lt;/a&gt;. Moreover, the Sematext Elasticsearch integration is customizable and open source.&lt;/p&gt;

&lt;p&gt;Bottom line: you don’t need to deal with configuring the agent for metrics collection, which is the first huge time saver!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Installing Monitoring Agent&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Setting up the monitoring agent takes less than 5 minutes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an Elasticsearch App in the &lt;a href="https://apps.sematext.com/ui/monitoring-create" rel="noopener noreferrer"&gt;Integrations / Overview&lt;/a&gt; (or &lt;a href="https://apps.eu.sematext.com/ui/monitoring-create" rel="noopener noreferrer"&gt;Sematext Cloud Europe&lt;/a&gt;). This will let you install the agent and control access to your monitoring and logs data. The short &lt;a href="https://www.youtube.com/watch?v=TR_qXdR8DVk&amp;amp;index=14&amp;amp;list=PLT_fd32OFYpfLBFZz_HiafnqjdlTth1NS" rel="noopener noreferrer"&gt;What is an App in Sematext Cloud&lt;/a&gt; video has more details.&lt;/li&gt;
&lt;li&gt;Name your Elasticsearch monitoring App and, if you want to collect Elasticsearch logs as well, create a Logs App along the way.&lt;/li&gt;
&lt;li&gt;Install the Sematext Agent according to the &lt;a href="https://apps.sematext.com/ui/howto/ClickHouse/overview" rel="noopener noreferrer"&gt;setup instructions&lt;/a&gt; displayed in the UI.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fcreate-elasticsearch-app.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F04%2Fcreate-elasticsearch-app.gif" alt="app creation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;App creation and setup instructions in Sematext Cloud&lt;/p&gt;

&lt;p&gt;For example, on Ubuntu, add Sematext Linux packages with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"deb http://pub-repo.sematext.com/ubuntu sematext main"&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/apt/sources.list.d/sematext.list &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null
wget &lt;span class="nt"&gt;-O&lt;/span&gt; - https://pub-repo.sematext.com/ubuntu/sematext.gpg.key | &lt;span class="nb"&gt;sudo &lt;/span&gt;apt-key add -
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get updatesudo apt-get &lt;span class="nb"&gt;install &lt;/span&gt;spm-client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then setup Elasticsearch monitoring by providing Elasticsearch server connection details:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;bash /opt/spm/bin/setup-sematext &lt;span class="nt"&gt;--monitoring-token&lt;/span&gt; &lt;span class="nt"&gt;--app-type&lt;/span&gt; elasticsearch &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--agent-type&lt;/span&gt; standalone &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--SPM_MONITOR_ES_NODE_HOSTPORT&lt;/span&gt; &lt;span class="s1"&gt;'localhost:9200'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--infra-token&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In case you have Elasticsearch secured with HTTPS and basic authentication, you can add the following parameters to the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;--SPM_MONITOR_ES_NODE_BASICAUTH_USERNAME&lt;/span&gt; userName
&lt;span class="nt"&gt;--SPM_MONITOR_ES_NODE_BASICAUTH_PASSWORD&lt;/span&gt; passWord
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In addition, you need to specify the HTTPS as protocol SPM_MONITOR_ES_NODE_HOSTPORT, as shown in the complete setup command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;bash /opt/spm/bin/setup-sematext &lt;span class="nt"&gt;--monitoring-token&lt;/span&gt; &amp;lt;your-token-goes-here&amp;gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--app-type&lt;/span&gt; elasticsearch &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--agent-type&lt;/span&gt; standalone &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--SPM_MONITOR_ES_NODE_HOSTPORT&lt;/span&gt; &lt;span class="s1"&gt;'https://localhost:9200'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--infra-token&lt;/span&gt; &amp;lt;your-token-goes-here&amp;gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--SPM_MONITOR_ES_NODE_BASICAUTH_USERNAME&lt;/span&gt; userName &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--SPM_MONITOR_ES_NODE_BASICAUTH_PASSWORD&lt;/span&gt; passWord
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go grab a drink, but hurry! Elasticsearch metrics will start appearing in your charts in less than a minute.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Elasticsearch Monitoring Dashboard&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When you open the Elasticsearch App you find a predefined set of dashboards that organize more than 100 Elasticsearch metrics and general &lt;a href="https://sematext.com/server-monitoring/" rel="noopener noreferrer"&gt;server monitoring&lt;/a&gt; in predefined charts grouped into an intuitively organized set of monitoring dashboards:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Overview with charts for all key Elasticsearch metrics&lt;/li&gt;
&lt;li&gt;Operating System metrics such as CPU, memory, network, disk usage, etc.&lt;/li&gt;
&lt;li&gt;Java Virtual Machine metrics for Garbage collection, JVM Memory, JVM Threads and JVM open files&lt;/li&gt;
&lt;li&gt;Elasticsearch metrics

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cluster Health&lt;/strong&gt; :  The number of Elasticsearch nodes and shard status (active, relocating, initializing, ..)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shard Stats&lt;/strong&gt; : The number of shards, shard status per index&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Index Stats&lt;/strong&gt; : The number of indexed documents, size on disk, indexing rate, merging rate, merged documents&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Search&lt;/strong&gt; : Request rate, query and fetch latency, realtime-get latency&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thread Pools&lt;/strong&gt; : Number of threads per pool, thread pool size&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Circuit Breakers&lt;/strong&gt; : Field data stats, request size stats&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connections&lt;/strong&gt; : Connected sockets, Node-Node-Transport stats, TCP socket and traffic stats&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2Felasticsearch-metrics.gif" alt="elasticsearch metrics"&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://www.sematext.com/cloud" rel="noopener noreferrer"&gt;&lt;em&gt;Elasticsearch key metrics in Sematext Cloud&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Setup Alerts for Elasticsearch Metrics&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To save you time Sematext automatically creates a set of default alert rules such as alerts for low disk space. You can create additional alerts on any metric. Watch &lt;a href="https://www.youtube.com/watch?v=WE9xAUud28o" rel="noopener noreferrer"&gt;Alerts in Sematext Cloud&lt;/a&gt; for more details.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Alerting on Elasticsearch Metrics&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;There are &lt;a href="https://sematext.com/docs/alerts/" rel="noopener noreferrer"&gt;3 types of alerts&lt;/a&gt; in Sematext:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Heartbeat alerts&lt;/strong&gt; , which notify you when a Elasticsearch DB server is down&lt;/li&gt;
&lt;li&gt;Classic &lt;strong&gt;threshold-based alerts&lt;/strong&gt;  that notify you when a metric value crosses a predefined threshold&lt;/li&gt;
&lt;li&gt;Alerts based on statistical &lt;strong&gt;anomaly detection&lt;/strong&gt;  that notify you when metric values suddenly change and deviate from the baseline&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s see how to actually create some alert rules for Elasticsearch metrics in the animation below. The request query count chart shows a spike. We normally have up to 100 requests, but we see it can jump to over 600 requests. To create an alert rule on a metric we’d go to the pulldown in the top right corner of a chart and choose “Create alert”. The alert rule applies the filters from the current view and you can choose various notification options such as email or configured &lt;a href="https://sematext.com/docs/alerts/#alert-integrations" rel="noopener noreferrer"&gt;notification hooks&lt;/a&gt; (PagerDuty, Slack, VictorOps, BigPanda, OpsGenie, Pusher, generic webhooks etc.). Alerts are triggered either by anomaly detection, watching metric changes in a given time window or through the use of classic threshold-based alerts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2Felasticsearch-create-alert.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2Felasticsearch-create-alert.gif" alt="elasticsearch create alert"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Alert creation for Elasticsearch request query count metric&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Elasticsearch Logs&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Shipping Elasticsearch Logs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Since having &lt;a href="https://sematext.com/metrics-and-logs/" rel="noopener noreferrer"&gt;logs and metrics in one platform&lt;/a&gt; makes troubleshooting simpler and faster let’s ship Elasticsearch logs too. You can use &lt;a href="https://sematext.com/docs/integration/#logging" rel="noopener noreferrer"&gt;many log shippers&lt;/a&gt;, but we’ll use &lt;a href="https://sematext.com/logagent/" rel="noopener noreferrer"&gt;Logagent&lt;/a&gt; because it’s lightweight, easy to set up, and because it can parse and structure logs out of the box. The log parser extracts timestamp, severity, and messages. For query traces, the log parser also extracts the unique query ID to group logs related to query execution.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://apps.sematext.com/ui/integrations" rel="noopener noreferrer"&gt;Create a Logs App&lt;/a&gt; to obtain an App token&lt;/li&gt;
&lt;li&gt;Install Logagent npm package
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;npm i &lt;span class="nt"&gt;-g&lt;/span&gt; @sematext/logagent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you don’t have Node.js, you can install it easily. E.g. On Debian/Ubuntu:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-sL&lt;/span&gt; https://deb.nodesource.com/setup&lt;span class="se"&gt;\_&lt;/span&gt;10.x | &lt;span class="nb"&gt;sudo&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; bash -
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; nodejs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Install the Logagent service by specifying the logs token and the path to Elasticsearch log files.  You can use &lt;code&gt;-g '/var/log/ **/elasticsearch*.log'&lt;/code&gt; to ship only logs from Elasticsearch server. If you run other services, on the same server consider shipping all logs using &lt;code&gt;-g '/var/log/** /*.log'&lt;/code&gt; The default settings ship all logs from &lt;code&gt;/var/log/**/*.log&lt;/code&gt; when the -g parameter is not specified. Logagent detects the init system and installs Systemd or Upstart service scripts. On Mac OS X it creates a launchd service. Simply run:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;logagent-setup &lt;span class="nt"&gt;-i&lt;/span&gt; YOUR_LOGS_TOKEN &lt;span class="nt"&gt;-g&lt;/span&gt; &lt;span class="s1"&gt;'/var/log/**/elasticsearch*.log'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for EU region use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;logagent-setup &lt;span class="nt"&gt;-i&lt;/span&gt; LOGS_TOKEN &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-u&lt;/span&gt; logsene-receiver.eu.sematext.com &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-g&lt;/span&gt; &lt;span class="s1"&gt;'/var/log/**/elasticsearch*.log'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The setup script generates the configuration file in /etc/sematext/logagent.conf and starts Logagent as system service.&lt;/p&gt;

&lt;p&gt;Note, if you run Elasticsearch in containers, &lt;a href="https://sematext.com/docs/logagent/installation-docker/" rel="noopener noreferrer"&gt;setup Logagent for container logs&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Log Search and Dashboards&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Once you have logs in Sematext you can search through them when troubleshooting, save queries you run frequently or &lt;a href="https://sematext.com/product-updates/#/2018/custom-reports-for-monitoring-logs-apps" rel="noopener noreferrer"&gt;create your individual logs dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2Fclickhouse-logs-search.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2Fclickhouse-logs-search.png" alt="logs search"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Search for Elasticsearch Logs&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Log Search Syntax&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you know how to search with Google, you’ll know &lt;a href="https://sematext.com/docs/logs/search-syntax/" rel="noopener noreferrer"&gt;how to search your logs&lt;/a&gt; in Sematext Cloud.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use AND, OR, NOT operators – e.g. (error OR warn) NOT exception&lt;/li&gt;
&lt;li&gt;Group AND, OR, NOT clauses – e.g. message:(exception OR error OR timeout) AND severity:(error OR warn)&lt;/li&gt;
&lt;li&gt;Don’t like Booleans? Use + and – to include and exclude – e.g. +message:error -message:timeout -host:db1.example.com&lt;/li&gt;
&lt;li&gt;Use field references explicitly – e.g. message:timeout&lt;/li&gt;
&lt;li&gt;Need a phrase search? Use quotation marks – e.g. message:”fatal error”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When digging through logs you might find yourself running the same searches again and again. To solve this annoyance, Sematext lets you save queries so you can re-execute them quickly without having to retype them. Please watch how &lt;a href="https://www.youtube.com/watch?v=glwZ8OCV0kc" rel="noopener noreferrer"&gt;using logs for troubleshooting&lt;/a&gt;simplifies your work.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Alerting on Elasticsearch Logs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To create an alert on logs we start by running a query that matches exactly those log events that we want to be alerted about. To create an alert just click to the floppy disk icon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2Fpasted-image-0-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2Fpasted-image-0-2.png" alt="alerts on elasticsearch logs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similar to the setup of metric alert rules, we can define threshold-based or anomaly detection alerts based on the number of matching log events the alert query returns.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2FScreen-Shot-2019-02-13-at-12.32.04.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2FScreen-Shot-2019-02-13-at-12.32.04.png" alt="alert screen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please watch &lt;a href="https://www.youtube.com/watch?v=WE9xAUud28o" rel="noopener noreferrer"&gt;Alerts in Sematext Cloud&lt;/a&gt; for more details.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Elasticsearch Metrics and Log Correlation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A typical troubleshooting workflow starts from detecting a spike in the metrics, then digging into logs to find the root cause of the problem. Sematext makes this really simple and fast. Your metrics and logs live under the same roof. Logs are centralized, the search is fast, and the powerful &lt;a href="https://sematext.com/docs/logs/search-syntax/" rel="noopener noreferrer"&gt;log search syntax&lt;/a&gt; is simple to use.  Correlation of metrics and logs is literally one click away.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2Fpasted-image-0-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsematext.com%2Fwp-content%2Fuploads%2F2019%2F03%2Fpasted-image-0-1.png" alt="logs and metrics correlation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Elasticsearch logs and metrics in a single view&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Monitor Elasticsearch with Sematext&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Comprehensive monitoring for Elasticsearch involves identifying key metrics for Elasticsearch, collecting metrics and logs, and then connecting everything in a meaningful way. In this post, we’ve shown you how to monitor Elasticsearch metrics and logs in one place. We used OOTB and customized dashboards, metrics correlation, log correlation, anomaly detection, and alerts. And with other &lt;a href="https://sematext.com/blog/now-open-source-sematext-monitoring-agent/" rel="noopener noreferrer"&gt;open-source integrations&lt;/a&gt;, like &lt;a href="https://sematext.com/integrations/kafka-monitoring/" rel="noopener noreferrer"&gt;Apache Kafka&lt;/a&gt;, you can easily start monitoring Elasticsearch alongside metrics, logs, and distributed request traces from all of the other technologies in your infrastructure. Get deeper visibility into Elasticsearch today with a &lt;a href="https://apps.sematext.com/ui/registration" rel="noopener noreferrer"&gt;free Sematext trial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://sematext.com/blog/monitoring-elasticsearch-with-sematext/" rel="noopener noreferrer"&gt;Monitoring Elasticsearch with Sematext&lt;/a&gt; appeared first on &lt;a href="https://sematext.com" rel="noopener noreferrer"&gt;Sematext&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>monitoring</category>
      <category>elasticsearch</category>
      <category>metrics</category>
    </item>
    <item>
      <title>Monitoring ClickHouse with Sematext</title>
      <dc:creator>Stefan Thies</dc:creator>
      <pubDate>Fri, 15 Feb 2019 09:42:58 +0000</pubDate>
      <link>https://forem.com/sematext/monitoring-clickhouse-with-sematext-2pab</link>
      <guid>https://forem.com/sematext/monitoring-clickhouse-with-sematext-2pab</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nTXFPfhB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/clickhouse-monitoring-comprehensive-monitoring-sematext-1024x560.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nTXFPfhB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/clickhouse-monitoring-comprehensive-monitoring-sematext-1024x560.jpg" alt="clickhouse monitoring comprehensive monitoring sematext"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown in Part 1 – &lt;a href="https://sematext.com/blog/clickhouse-monitoring-key-metrics/"&gt;ClickHouse Monitoring Key Metrics&lt;/a&gt; – the setup, tuning, and operations of ClickHouse require deep insights into the performance metrics such as locks, replication status, merge operations, cache usage and many more. Sematext provides an excellent alternative to other &lt;a href="https://sematext.com/blog/clickhouse-monitoring-tools/"&gt;ClickHouse monitoring tools&lt;/a&gt;, a more comprehensive – and easy to set up – monitoring solution for ClickHouse and other technologies in your infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How much hair do you have?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Open-source monitoring tools are free, but your time is not.  Relatively speaking, it’s actually rather expensive.  Thus, Sematext aims to save you time, effort….and your hair.&lt;/p&gt;

&lt;p&gt;Here are a few &lt;strong&gt;things you will&lt;/strong&gt;  &lt;strong&gt;NOT&lt;/strong&gt;**  have to do when using Sematext for ClickHouse** monitoring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;figure out which metrics to collect and which ones to ignore&lt;/li&gt;
&lt;li&gt;give metrics meaningful labels&lt;/li&gt;
&lt;li&gt;hunt for metric descriptions in the docs so that you know what each of them actually shows&lt;/li&gt;
&lt;li&gt;build charts to group metrics that you really want on the same charts, not N separate charts&lt;/li&gt;
&lt;li&gt;figure out, for each metrics, which aggregation to use (min? max? avg? something else?)&lt;/li&gt;
&lt;li&gt;build dashboards to combine charts with metrics you typically want to see together&lt;/li&gt;
&lt;li&gt;set up basic alert rules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The above is not even a complete story.  Want to collect ClickHouse logs?  Want to structure them?  Prepare to do more legwork.  Sematext does all this automatically for you!&lt;/p&gt;

&lt;p&gt;In this post, we will look at how Sematext provides more comprehensive – and easy to set up – monitoring for ClickHouse and other technologies in your infrastructure by combining events, logs, and metrics together in one integrated &lt;a href="https://sematext.com/cloud"&gt;full stack observability platform&lt;/a&gt;. By using the Sematext &lt;a href="https://sematext.com/blog/now-open-source-sematext-monitoring-agent/"&gt;open-source monitoring agent&lt;/a&gt; and its integrations, which are also open-source, you can monitor your whole infrastructure and apps, not just your ClickHouse DB. You can also get deeper visibility into your full stack by collecting, processing, and analyzing your logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;ClickHouse Monitoring&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Collecting ClickHouse Metrics&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Sematext ClickHouse integration collects &lt;a href="https://sematext.com/docs/integration/clickhouse/"&gt;over 70 different ClickHouse metrics&lt;/a&gt; for system, queries, merge tree, replication, replicas, mark cache, R/W buffers, dictionaries, locks, distributed engine, as well as Zookeeper errors &amp;amp; wait times. Sematext maintains and supports &lt;a href="https://github.com/sematext/sematext-agent-integrations/tree/master/clickhouse"&gt;official ClickHouse monitoring integration&lt;/a&gt;. Moreover, the Sematext ClickHouse integration is customizable and open source.&lt;/p&gt;

&lt;p&gt;Bottom line: you don’t need to deal with configuring the agent for metrics collection, which is the first huge time saver!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Installing Monitoring Agent&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Setting up the monitoring agent takes less than 5 minutes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;

&lt;ol&gt;
&lt;li&gt;Create a ClickHouse App in the &lt;a href="https://apps.sematext.com/ui/monitoring-create"&gt;Integrations / Overview&lt;/a&gt; (or &lt;a href="https://apps.eu.sematext.com/ui/monitoring-create"&gt;Sematext Cloud Europe&lt;/a&gt;). This will let you install the agent and control access to your monitoring and logs data. The short &lt;a href="https://www.youtube.com/watch?v=TR_qXdR8DVk&amp;amp;index=14&amp;amp;list=PLT_fd32OFYpfLBFZz_HiafnqjdlTth1NS"&gt;What is an App in Sematext Cloud&lt;/a&gt; video has more details.&lt;/li&gt;
&lt;li&gt;Name your ClickHouse monitoring App and, if you want to collect ClickHouse logs as well, create a Logs App along the way.&lt;/li&gt;
&lt;li&gt;Install the Sematext Agent according to the &lt;a href="https://apps.sematext.com/ui/howto/ClickHouse/overview"&gt;setup instructions&lt;/a&gt; displayed in the UI.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--di7y-cFi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/create-clickhouse.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--di7y-cFi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/create-clickhouse.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, on Ubuntu, add Sematext Linux packages with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "deb http://pub-repo.sematext.com/ubuntu sematext main" | sudo tee /etc/apt/sources.list.d/sematext.list \&amp;gt; /dev/null wget -O - https://pub-repo.sematext.com/ubuntu/sematext.gpg.key | sudo apt-key add - sudo apt-get update sudo apt-get install spm-client
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then setup ClickHouse monitoring by providing ClickHouse server connection details:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo bash /opt/spm/bin/setup-sematext --monitoring-token --app-type clickhouse --agent-type standalone --SPM\_MONITOR\_CLICKHOUSE\_DB\_USER '' --SPM\_MONITOR\_CLICKHOUSE\_DB\_PASSWORD '' --SPM\_MONITOR\_CLICKHOUSE\_DB\_HOST\_PORT 'localhost:8123'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The last step, &lt;strong&gt;go grab a drink.. but hurry&lt;/strong&gt; – ClickHouse metrics will start appearing in your charts in less than a minute.&lt;/p&gt;

&lt;h3&gt;
  
  
  ClickHouse Monitoring Dashboard
&lt;/h3&gt;

&lt;p&gt;When you open the ClickHouse App you find a predefined set of dashboards that organize more than 70 ClickHouse metrics and general &lt;a href="https://sematext.com/server-monitoring/"&gt;server&lt;/a&gt;&lt;a href="https://sematext.com/server-monitoring/"&gt;monitoring&lt;/a&gt; in predefined charts grouped into an intuitively organized set of monitoring dashboards:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Overview with charts for all key ClickHouse metrics &lt;/li&gt;
&lt;li&gt;Operating System metrics such as CPU, memory, network, disk usage, etc.&lt;/li&gt;
&lt;li&gt;ClickHouse metrics

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Query&lt;/strong&gt; :  query time, query count, query memory &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Merge&lt;/strong&gt; : merged bytes, merge count, merged rows &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MergeTree stats&lt;/strong&gt; : table size on disk, row count and active part count&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replication&lt;/strong&gt; : replication part checks, failed replication part checks, lost replicated parts, distributed connection retires and distributed connection fails&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zookeeper&lt;/strong&gt; : A breakdown of various zookeeper errors, zookeeper wait times and leader elections&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replicas&lt;/strong&gt; : Replication status, Replica parts, replica queue size, replica queue inserts, replica queue merges &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;System&lt;/strong&gt; : Memory allocator stats, active HTTP and TCP connections, network errors and cache dictionary stats&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;R/W Buffer&lt;/strong&gt; : Reads/Writes, open files and file descriptor failures&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mark Cache&lt;/strong&gt; : Mark cache hits and misses and mark cache size&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Locks&lt;/strong&gt; : Lock acquired read blocks, RW Lock reader wait time, Lock write wait times, Lock read wait times&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ejkvha9V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/clickhouse-metrics-overview-2-1.gif" alt="clickhouse metrics overview 2 1"&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;ClickHouse key metrics in Sematext Cloud&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup ClickHouse Alerts
&lt;/h3&gt;

&lt;p&gt;To save you time Sematext automatically creates a set of default alert rules such as alerts for low disk space. You can create additional alerts on any metric. Watch &lt;a href="https://www.youtube.com/watch?v=WE9xAUud28o"&gt;Alerts in Sematext Cloud&lt;/a&gt; for more details.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Alerting on ClickHouse Metrics&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;There are &lt;a href="https://sematext.com/docs/alerts/"&gt;3 types of alerts&lt;/a&gt; in Sematext:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Heartbeat alerts&lt;/strong&gt; , which notify you when a ClickHouse DB server is down&lt;/li&gt;
&lt;li&gt;Classic &lt;strong&gt;threshold-based alerts&lt;/strong&gt; that notify you when a metric value crosses a pre-defined threshold&lt;/li&gt;
&lt;li&gt;Alerts based on statistical &lt;strong&gt;anomaly detection&lt;/strong&gt; that notify you when metric values suddenly change and deviate from the baseline&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s see how to actually create some alert rules for ClickHouse metrics in the animation below. The Query Processing Memory chart shows a spike. We normally have a really low query memory close to 3 MB, but we see it can jump to over 80 MB. To create an alert rule on a metric we’d go to the pulldown in the top right corner of a chart and choose “Create alert”. The alert rule applies the filters from the current view and you can choose various notification options such as email or configured &lt;a href="https://sematext.com/docs/alerts/#alert-integrations"&gt;notification hooks&lt;/a&gt; (PagerDuty, Slack, VictorOps, BigPanda, OpsGenie, Pusher, generic webhooks etc.). Alerts are triggered either by anomaly detection, watching metric changes in a given time window or through the use of classic threshold-based alerts.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9znrjIln--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/clickhouse-query-memory-alert.gif" alt="clickhouse query memory alert"&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Alert creation for ClickHouse query memory&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;ClickHouse Logs&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Shipping ClickHouse Logs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Since having &lt;a href="https://sematext.com/metrics-and-logs/"&gt;logs and metrics in one platform&lt;/a&gt; makes troubleshooting simpler and faster let’s ship ClickHouse logs, too. You can use &lt;a href="https://sematext.com/docs/integration/#logging"&gt;many log shippers&lt;/a&gt;, but we’ll use &lt;a href="https://sematext.com/logagent/"&gt;Logagent&lt;/a&gt; because it’s lightweight, easy to set up and because it can parse and structure logs out of the box. The log parser extracts timestamp, severity, and messages. For query traces, the log parser also extracts the unique query ID to group logs related to query execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1.&lt;/strong&gt;  &lt;a href="https://apps.sematext.com/ui/integrations"&gt;Create a Logs App&lt;/a&gt; to obtain an App token&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2.&lt;/strong&gt; Install Logagent npm package&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo npm i -g @sematext/logagent
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you don’t have Node, you can install it easily. E.g. On Debian/Ubuntu:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -sL https://deb.nodesource.com/setup\_10.x | sudo -E bash -sudo apt-get install -y nodejs
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3.&lt;/strong&gt; Install Logagent service by specifying the logs token and the path to ClickHouse log files.  You can use &lt;em&gt;-g ‘var/log/ &lt;strong&gt;/clickhouse*.log`&lt;/strong&gt; _ to ship only logs from ClickHouse server. If you run other services, such as ZooKeeper or MySQL on the same server consider shipping all logs using _-g ‘var/log//*.log’&lt;/em&gt;. The default settings ship all logs from &lt;em&gt;/var/log/**/*.log&lt;/em&gt; when the &lt;em&gt;-g&lt;/em&gt; parameter is not specified.&lt;/p&gt;

&lt;p&gt;Logagent detects the init system and installs Systemd or Upstart service scripts. On Mac OS X it creates a Launchd service. Simply run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
sudo logagent-setup -i YOUR\_LOGS\_TOKEN -g ‘var/log/\*\*/clickhouse\*.log&lt;/code&gt; #for EU region: #sudo logagent-setup -i LOGS_TOKEN #-u logsene-receiver.eu.sematext.com #-g ‘var/log/*&lt;em&gt;/clickhouse&lt;/em&gt;.log&lt;code&gt;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The setup script generates the configuration file in /etc/sematext/logagent.conf and starts Logagent as system service.&lt;/p&gt;

&lt;p&gt;Note, if you run ClickHouse in containers, &lt;a href="https://sematext.com/docs/logagent/installation-docker/"&gt;setup Logagent for container logs&lt;/a&gt;. Note that &lt;a href="https://github.com/yandex/ClickHouse/issues/2241"&gt;ClickHouse server does not log to console when running in containers&lt;/a&gt;. You need to mount a modified ClickHouse server config file  to /etc/clickhouse-server/config.xml in the container to enable logging to console:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
\&amp;lt;logger\&amp;gt;  \&amp;lt;console\&amp;gt;1\&amp;lt;/console\&amp;gt;\&amp;lt;/logger\&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Log Search and Dashboards
&lt;/h3&gt;

&lt;p&gt;Once you have logs in Sematext you can search them when troubleshooting, save queries you run frequently or &lt;a href="https://sematext.com/product-updates/#/2018/custom-reports-for-monitoring-logs-apps"&gt;create your individual logs dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7btJwCCL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/clickhouse-logs-search.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7btJwCCL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/clickhouse-logs-search.png" alt="clickhouse logs search"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Search for ClickHouse Logs&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Log Search Syntax&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you know how to search with Google, you’ll know &lt;a href="https://sematext.com/docs/logs/search-syntax/"&gt;how to search your logs&lt;/a&gt; in Sematext Cloud.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;em&gt;AND, OR, NOT&lt;/em&gt; operators – e.g. &lt;em&gt;(error OR warn) NOT exception&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Group your &lt;em&gt;AND, OR, NOT&lt;/em&gt; clauses – e.g. &lt;em&gt;message:(exception OR error OR timeout) AND severity:(error OR warn)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Don’t like Booleans? Use + and – to include and exclude – e.g. &lt;em&gt;+message:error -message:timeout -host:db1.example.com&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Use explicitly field references – e.g. &lt;em&gt;message&lt;/em&gt;:timeout&lt;/li&gt;
&lt;li&gt;Need a phrase search? Use quotation marks – e.g. &lt;em&gt;message&lt;/em&gt;:”&lt;em&gt;fatal error”&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When digging through logs you might find yourself running the same searches again and again.  To solve this annoyance, Sematext lets you save queries so you can re-execute them quickly without having to retype them. Please watch how &lt;a href="https://www.youtube.com/watch?v=glwZ8OCV0kc"&gt;using logs for troubleshooting&lt;/a&gt;simplifies your work.&lt;/p&gt;

&lt;h3&gt;
  
  
  Alerting on ClickHouse Logs
&lt;/h3&gt;

&lt;p&gt;To create an alert on logs we start by running a query that matches exactly those log events that we want to be alerted about. To create an alert just click to the floppy disk icon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s5oUomj4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/pasted-image-0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s5oUomj4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/pasted-image-0.png" alt="pasted image 0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similar to the setup of metric alert rules, we can define threshold-based or anomaly detection alerts based on the number of matching log events the alert query returns.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nFQ5y0ob--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-13-at-12.32.04.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nFQ5y0ob--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-13-at-12.32.04.png" alt="Screen Shot 2019 02 13 at 12.32.04"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please watch &lt;a href="https://www.youtube.com/watch?v=WE9xAUud28o"&gt;Alerts in Sematext Cloud&lt;/a&gt; for more details.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;ClickHouse Metrics and Log Correlation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A typical troubleshooting workflow starts from detecting a slowness in metrics, then digging into logs to find the root cause of the problem. Sematext makes this really simple and fast.  Your metrics and logs live under one roof.  Logs are centralized, the search is fast, and powerful &lt;a href="https://sematext.com/docs/logs/search-syntax/"&gt;log search syntax&lt;/a&gt; is simple to use.  Correlation of metrics and logs is literally a click away.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bf_Nkh2I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/image3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bf_Nkh2I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/image3.png" alt="image3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;ClickHouse logs and metrics in a single view&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Full Stack Observability for &lt;strong&gt;ClickHouse &amp;amp; Friends&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;ClickHouse’s best friends are ZooKeeper, MySQL and Kafka. While ZooKeeper is essential for ClickHouse cluster operations other integrations are optionally used to access data from external storages.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ZooKeeper&lt;/strong&gt; : ClickHouse relies on ZooKeeper to synchronize distributed workloads in ClickHouse clusters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MySQL&lt;/strong&gt; : ClickHouse supports &lt;a href="https://clickhouse.yandex/docs/en/operations/table_engines/mysql/"&gt;MySQL as an external storage engine for ClickHouse&lt;/a&gt; tables. In addition, MySQL can serve as an external ClickHouse dictionary for key/value lookups.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kafka&lt;/strong&gt; : Apache &lt;a href="https://clickhouse.yandex/docs/en/operations/table_engines/kafka/"&gt;Kafka&lt;/a&gt; can be used as an external storage engine for ClickHouse tables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Others&lt;/strong&gt; : Several other integrations exist for &lt;a href="https://clickhouse.yandex/docs/en/query_language/dicts/external_dicts_dict_sources/"&gt;external dictionaries&lt;/a&gt; (data lookups), such as generic ODBC interfaces or MongoDB or PostgreSQL (3rd party) integrations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ClickHouse and Zookeeper
&lt;/h3&gt;

&lt;p&gt;Because ClickHouse cluster stability depends on ZooKeeper performing well, we recommend setting up &lt;a href="https://sematext.com/docs/integration/zookeeper/"&gt;ZooKeeper monitoring&lt;/a&gt; and log collection for related logs. As shown in the dashboard below, this allows us to, for example, correlate high ZooKeeper wait times in ClickHouse metrics, with JVM garbage collection metrics in ZooKeeper.&lt;/p&gt;

&lt;p&gt;Distributed system require ZooKeeper responses to be quick, so any delays caused by slow JVM garbage collection can cause performance and cluster stability issues. Having the ability to easily correlate ZooKeeper and ClickHouse metrics, like in the &lt;a href="https://www.youtube.com/watch?v=BuMtZCLN_Mk&amp;amp;list=PLT_fd32OFYpfLBFZz_HiafnqjdlTth1NS&amp;amp;index=13"&gt;custom ClickHouse monitoring dashboard&lt;/a&gt; below, makes it easier to fix the root cause of bad performance faster.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--49LMXThR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-08-at-16.06.22.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--49LMXThR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-08-at-16.06.22.png" alt="Screen Shot 2019 02 08 at 16.06.22"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Correlation between ZooKeeper/JVM Garbage Collection and ClickHouse ZooKeeper wait time&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In many cases, a performance issue can be solved by analyzing “related” metrics as well as the metric that was suspicious at the beginning of the investigation.  For ad-hoc metric correlation analysis use the &lt;a href="https://sematext.com/product-updates/#/2018/automatic-metrics-correlation"&gt;automatic metrics correlation&lt;/a&gt; to find all metrics whose patterns correlate to any base metric of your choice.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F-1v-D5L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-12-at-21.57.23.png" alt="Screen Shot 2019 02 12 at 21.57.23"&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Metric correlation of garbage collection time and request latency in ZooKeeper&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Integration with MySQL ** or Kafka**
&lt;/h3&gt;

&lt;p&gt;ClickHouse integrates with MySQL. MySQL can be used as an external storage engine to query data from MySQL tables in ClickHouse queries. In addition, ClickHouse supports MySQL for data lookups as an external dictionary. A dictionary is a mapping (key -&amp;gt; attributes) that is convenient for various types of reference lists. ClickHouse supports special functions for working with dictionaries that can be used in queries. It is easier and more efficient to use dictionaries with functions than a JOIN with reference tables.  If you run MySQL, see &lt;a href="https://sematext.com/blog/announcement-mysql-performance-monitoring-in-spm/"&gt;MySQL Monitoring&lt;/a&gt; for more info.&lt;/p&gt;

&lt;p&gt;Apache Kafka is only integrated as an external storage engine. Once ClickHouse faces a high latency while requesting data from external data sources such as MySQL or Kafka we have to figure out what slows down external data sources. By setting up MySQL and &lt;a href="https://sematext.com/integrations/kafka-monitoring/"&gt;Kafka monitoring&lt;/a&gt; you can benefit from great observability having your favorite ZooKeeper, MySQL, Kafka, and ClickHouse metrics together with related logs for faster troubleshooting. See &lt;a href="https://sematext.com/blog/kafka-consumer-lag-offsets-monitoring/"&gt;Monitoring Kafka and Consumer Lag&lt;/a&gt; to learn more.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Monitor ClickHouse with Sematext&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Comprehensive monitoring for ClickHouse involves identifying key metrics for both the ClickHouse cluster and ZooKeeper, collecting metrics and logs, and connecting everything in a meaningful way. In this post, we’ve shown you how to monitor ClickHouse metrics and logs in one place. We used OOTB  and customized dashboards, metrics correlation, log correlation, anomaly detection, and alerts. And with other &lt;a href="https://sematext.com/blog/now-open-source-sematext-monitoring-agent/"&gt;open-source integrations&lt;/a&gt;, like MySQL or Kafka, you can easily start monitoring ClickHouse alongside metrics, logs, and distributed request traces from all of the other technologies in your infrastructure. Get deeper visibility into ClickHouse today with a &lt;a href="https://apps.sematext.com/ui/registration"&gt;free Sematext trial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://sematext.com/blog/clickhouse-monitoring-sematext/"&gt;Monitoring ClickHouse with Sematext&lt;/a&gt; appeared first on &lt;a href="https://sematext.com"&gt;Sematext&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>clickhouse</category>
      <category>monitoring</category>
      <category>logging</category>
    </item>
    <item>
      <title>IoT: Air Pollution Tracking with Node.js, Elastic Stack, and MQTT</title>
      <dc:creator>Stefan Thies</dc:creator>
      <pubDate>Mon, 05 Mar 2018 15:34:39 +0000</pubDate>
      <link>https://forem.com/sematext/iot-air-pollution-tracking-with-nodejs-elastic-stack-and-mqtt-3lmi</link>
      <guid>https://forem.com/sematext/iot-air-pollution-tracking-with-nodejs-elastic-stack-and-mqtt-3lmi</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe28uva9n6epllxfghv6r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe28uva9n6epllxfghv6r.png" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What can you do with a couple of IoT devices, Node.js, Elasticsearch, and MQTT?  You can put together your own Internet of Things setup for measuring air pollution, like I have.  In this blog post, I’ll share all the details about the hardware setup, software configuration, data analytics, an IoT dashboard, and MQTT broker-based integration with other tools from the IoT ecosystem, like Node-Red and Octoblu.  Of course, I’ll also share a few interesting findings about air pollution IoT sensor measurements taken at a few locations in Germany. Take a look – doing this is &lt;em&gt;much&lt;/em&gt; easier than you might think when you use the right tools!&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Motivation&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Recently, the&lt;a href="https://en.wikipedia.org/wiki/Volkswagen_emissions_scanda" rel="noopener noreferrer"&gt;Volkswagen Emission Scandal&lt;/a&gt; (Wikipedia) escalated again. Reasons were controversial animal experiments as&lt;a href="https://www.nytimes.com/2018/01/30/opinion/animal-experiment-volkswagen.html" rel="noopener noreferrer"&gt;reported by New York Times&lt;/a&gt;. This sparked numerous debates about &lt;a href="http://abcnews.go.com/Health/wireStory/german-court-issue-verdict-diesel-ban-case-53381726" rel="noopener noreferrer"&gt;banning Diesel cars from city centers in Germany&lt;/a&gt;, where I live.  People talk about global car bans, but I’m amazed nobody is really talking about smart-city concepts yet. Besides the discussion around the cheating on nitrogen oxide emissions, the EU wants to enforce lower limits of &lt;a href="https://en.wikipedia.org/wiki/Particulates" rel="noopener noreferrer"&gt;particulates&lt;/a&gt; (measured in &lt;a href="https://www.epa.gov/pm-pollution/particulate-matter-pm-basics" rel="noopener noreferrer"&gt;PM10 and PM2.5&lt;/a&gt;) in Germany. The impact on the health of high PM10 concentration is described in “&lt;a href="https://www.sciencedirect.com/science/article/pii/S143846390470303X" rel="noopener noreferrer"&gt;Health effects of particles in ambient air&lt;/a&gt;”.&lt;/p&gt;

&lt;p&gt;Well, that is politics and medicine and we are computer scientists, data engineers or DevOps specialists, so I asked myself&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;“&lt;em&gt;What can we do for environmental protection&lt;/em&gt;”? Living in a world where data-driven decisions are becoming more common, collecting data and visualizing facts is one way to contribute.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tweet to @sematext&lt;/p&gt;

&lt;p&gt;As the recent scandal shows, large companies might influence scientific studies, lobbyists are influencing governments, so why not collect open source data and create independent analytics and &lt;em&gt;independent opinions&lt;/em&gt; based on open data – or your own data! We can help with recipes for device setups, software configuration or sharing data in a platform or analyzing data, help with the interpretation and we could speak about it in public, in meetups, conferences, etc.&lt;/p&gt;

&lt;p&gt;As for me, I just wanted to see measurements in my environment because public government data lists only major cities and reports they provide typically have maps with low resolution. So I decided to start a little IoT DIY project with off-the-shelf components to measure the air pollution with a particular matter/dust sensor, tracking the PM10, PM2.5, as well as the PM2.5/PM10 ratio values.  I wanted to be able to do this with a mobile device and measure in various locations where I work and live. My office is close to the main street and close to an industrial area, but I recently moved into a new house in a rural town that feels like a  “climatic spa” and actually has a health resort. To make it easy for others to put together Internet of Things systems like the one described here I created &lt;a href="https://github.com/megastef/AirPollutionTracker" rel="noopener noreferrer"&gt;“Air Pollution Tracker”&lt;/a&gt;, so anyone can collect data at their locations,  experiment with the setup, and share their data.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;The Hardware&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Ok, let’s get technical and first see the hardware setup of the IoT sensor device I put together:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6m3i7ukvqbtg0rvvt17e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6m3i7ukvqbtg0rvvt17e.png" width="635" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So that’s what our setup looks like. Let’s see what each part of this IoT sensor device is and does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Measuring Particulate Matter with a Nova SDS011 dust sensor&lt;/li&gt;
&lt;li&gt;Logging the location of the measurement with a GPS sensor&lt;/li&gt;
&lt;li&gt;Wi-Fi connection to my mobile phone to transmit measurement results via MQTT&lt;/li&gt;
&lt;li&gt;A power bank provides the power for the Banana-Pi device &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/Banana_Pi" rel="noopener noreferrer"&gt;Banana-Pi&lt;/a&gt; (more powerful than &lt;a href="https://www.raspberrypi.org/" rel="noopener noreferrer"&gt;Raspberry Pi&lt;/a&gt;) with Debian Linux and &lt;a href="https://nodejs.org" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; for data collection and shipping of the sensor data &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that the USB power might not be sufficient for GPS, Wi-Fi, PM sensor, and an internal Ethernet interface.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;The Software&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;The software architecture is based on &lt;a href="https://en.wikipedia.org/wiki/MQTT" rel="noopener noreferrer"&gt;MQTT&lt;/a&gt; messages, which is designed to scale to thousands of devices and supports an easy way of sharing data in real-time for any kind of processing. We created &lt;a href="https://sematext.com/docs/logagent/plugins/" rel="noopener noreferrer"&gt;open source plugins&lt;/a&gt; for &lt;a href="https://github.com/sematext/logagent-js" rel="noopener noreferrer"&gt;@sematext/logagent&lt;/a&gt; in Node.js to collect and correlate data from &lt;em&gt;Nova SDS011&lt;/em&gt; sensor and the GPS device. The measurements are shipped in JSON format to an MQTT broker, which can store data in Elasticsearch or, as we did, in &lt;a href="https://sematext.com/cloud/" rel="noopener noreferrer"&gt;Sematext Cloud&lt;/a&gt;. The MQTT-based architecture allows other clients to listen to the event stream and create e.g. alerts or public tweets or control traffic lights when PM10 limits are reached. In addition, the MQTT messages are recorded for historical analysis and visualisation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsm8o7gnmxxdv0lbfp2mc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsm8o7gnmxxdv0lbfp2mc.png" width="800" height="450"&gt;&lt;/a&gt;&lt;em&gt;Architecture&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Sniffing fresh air and collecting data from PM sensor&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The project started with a Google search for particulate matter sensors and availability of the device and Node.js drivers because Node.js is my favourite programming language. After some research I ordered the &lt;em&gt;Nova SDS011&lt;/em&gt; with USB to serial converter. Reading values from serial port looked easy to implement, and the USB interface works on my MacBook and the Banana-Pi device. The next step was creating an input plugin for &lt;a href="https://sematext.com/logagent/" rel="noopener noreferrer"&gt;@sematext/logagent&lt;/a&gt; to inject the sensor data in the Logagent processing pipeline. Logagent can ship data to MQTT, Elasticsearch, Apache Kafka, or simple file output.  &lt;/p&gt;

&lt;p&gt;I wanted to measure air quality in multiple locations, so I needed to collect the location of measurements. This would let me visualize air pollution on a map. The initial approach was to add a static location information to the plugin configuration, but then I  changed things to get the location information from other sources, like GPS or by tracking my iPhone. The &lt;a href="https://www.npmjs.com/package/logagent-novasds" rel="noopener noreferrer"&gt;Logagent plugin for the Nova SDS011 sensor&lt;/a&gt; is open source and published in the NPM registry. The Logagent configuration for the Nova SDS011 plugin requires the module name and the name of the serial port. Optionally, you can specify the measurement collection frequency using the workingPeriod setting in minutes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;input: 
  novaSDS011: 
    module: input-nova-sda011 
    comPort: /dev/ttyUSB0 
    # persistent setting for measurement interval in minutes 
    workingPeriod: 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Getting accurate GPS position&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;After the setup of the serial port driver and Logagent, the first experiments started on my MacBook. To get accurate GPS position when changing places I wanted to track my location automatically. At first I used the Logagent plugin &lt;a href="https://www.npmjs.com/package/logagent-apple-location" rel="noopener noreferrer"&gt;logagent-apple-location&lt;/a&gt; to track the position of my iPhone. To do that I had to extend the PM sensor plugin to listen to the “&lt;em&gt;location&lt;/em&gt;” events to enrich the sensor data with GPS coordinates and retrieved address. That was a good start for experiments until my new GPS device finally arrived and I switched to using &lt;a href="https://www.npmjs.com/package/logagent-gps" rel="noopener noreferrer"&gt;logagent-gps&lt;/a&gt; plugin to get accurate GPS positions independently from internet connectivity. When the internet connection is present, the plugin queries Google Maps API to find the address of the current location and uses a cache to avoid hitting the Google API limit quickly. The downside of the cache is the loss of accuracy. With the cache in place the street numbers and addresses don’t change within a few hundred meters distance. The configuration for the Logagent GPS plugin is very simple. It needs only the COM port for the serial interface and the npm module name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;input: 
  gps: 
    module: logagent-gps
    comPort: /dev/ttyACM0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Calculating values from sensor measurements&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Smaller particles are considered more dangerous and therefore it might be interesting to see the ratio of PM10 and PM2.5 values. The Nova SDS011 provides only PM10 and PM2.5 measurements, and the ratio of PM2.5/PM10 needs to be calculated. Please note that the mass of PM2.5 particles is a subset of PM10 particles. Therefore the PM2.5 value is always smaller than the PM10 value.  &lt;a href="https://sematext.com/docs/logagent/filters/#output-filter" rel="noopener noreferrer"&gt;Logagent supports JavaScript functions&lt;/a&gt; for input and output filters in the configuration file, so that is what we used here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# calculate PM2.5/PM10 ratio in percent 
outputFilter:
  - module: !!js/function &amp;gt;
      function (context, config, eventEmitter, data, callback)  {
        if (data.PM10 &amp;amp;&amp;amp; data.PM10 &amp;gt; 0) {
            data.PM25ratio = (data['PM2.5']/data.PM10) * 100
        }
        callback(null, data)
      }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The “data” variable holds the current measurement values and the callback function needs to be called to return the modified data object after the calculation. The new data object contains now PM10, PM2.5 and the calculated PM25ratio values!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Shipping and consuming sensor data with MQTT&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The standardized MQTT protocol has a very small overhead and most IoT tools support MQTT. MQTT works with pub/sub mechanisms to distribute messages to multiple clients. In our case, the sensor device sends JSON messages to the MQTT broker using the topic called “sensor-data”. We use the &lt;a href="https://sematext.com/docs/logagent/output-plugin-mqtt/" rel="noopener noreferrer"&gt;Logagent MQTT output plugin&lt;/a&gt; and the public service mqtt://test.mosquitto.org. Please note that you should use the test.mosquitto.org server only for short tests. For a production setup you should run your own MQTT broker. For example, you could run &lt;a href="https://hub.docker.com/_/eclipse-mosquitto/" rel="noopener noreferrer"&gt;Mosquito MQTT broker in a Docker container&lt;/a&gt; or you could use the &lt;a href="https://sematext.com/docs/logagent/input-plugin-mqtt-broker/" rel="noopener noreferrer"&gt;Logagent MQTT-broker plugin&lt;/a&gt; and run another instance of Logagent as a MQTT broker.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;output:  
  mqtt:    
    module: output-mqtt    
    url: mqtt://test.mosquitto.org
    topic: sensor-data
    debug: false
    # optional filter settings matching data field with regular expressions
    filter:
      field: logSource
      match: Nova
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we could use any MQTT client on another machine, connected to the same MQTT broker and subscribe to messages arriving in the “sensor-data” topic.&lt;/p&gt;

&lt;p&gt;If you want to process measurements in some way or act on them you can use tools like&lt;a href="https://nodered.org/" rel="noopener noreferrer"&gt;Node-Red&lt;/a&gt; or&lt;a href="https://octoblu.github.io/" rel="noopener noreferrer"&gt;Octoblu&lt;/a&gt; and create IoT workflows.  For example, the MQTT plugin in Node-Red takes MQTT broker address and topic as parameters, so you can use that to subscribe to that “sensor-data” topic and get measurements that were sent to the MQTT broker As soon you start Node-Red pointed to the MQTT broker you will get the air pollution data into your Node-Red workflow. Then you perform various actions on or based on received measurements.  For example, you could tweet messages when conditions match or change the color of LED lights according to the sensor values, or you could control air conditioning … the possibilities are endless here!  Thinking a little bigger, a smart-city might choose to control the traffic and use air pollution as one of the criteria for traffic routing decisions. The Node-Red architecture can plug devices, logic elements, or &lt;a href="https://flows.nodered.org/node/node-red-contrib-neuralnet" rel="noopener noreferrer"&gt;neural network&lt;/a&gt; components. Node-Red is a great playground to prototype any logic based on the air pollution measurements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fegafts1mtgifsp3gd2gz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fegafts1mtgifsp3gd2gz.png" width="800" height="321"&gt;&lt;/a&gt;Node-Red IoT workflows&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Storing data in Elasticsearch or Sematext Cloud&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We stored what is effectively IoT time-series sensor data via &lt;a href="https://sematext.com/docs/logagent/output-elasticsearch/" rel="noopener noreferrer"&gt;Logagent Elasticsearch plugin&lt;/a&gt; directly in Sematext Cloud. Sematext Cloud provides Elasticsearch API compatible endpoints for data, dashboards and alerts. The Elasticsearch plugin needs the Elasticsearch URL and index name. For Sematext Cloud we use the write token provided by Sematext UI as index name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sematext-cloud:
    module: elasticsearch
    url: https://logsene-receiver.sematext.com
    index: 9eed3c42-1e14-44d2-b319-XXXXXXX  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;The complete device setup for Banana-PI&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The setup for the Banana-PI device in a few steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create Bananian (Debian) SD card&lt;/li&gt;
&lt;li&gt;Configure Wi-Fi card for your mobile phone by setting the wpa_–&lt;em&gt;essid and the wpa&lt;/em&gt;-password_ in &lt;em&gt;/etc/network/interfaces&lt;/em&gt; for the wlan0 interface. Enable the Internet tethering on your mobile phone  (“Hotspot” on iPhone). &lt;/li&gt;
&lt;li&gt;Install Node.js
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   curl -sL https://deb.nodesource.com/setup\_8.x | bash - &amp;amp;&amp;amp; apt-get install -y nodejs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Install @sematext/logagent and relevant plugins
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     npm i -g --unsafe-perm @sematext/logagent logagent-gps logagent-novasds      npm i -g --unsafe-perm @sematext/logagent-nodejs-monitor      logagent-setup -t YOUR-TOKEN -e [https://logsene-receiver.sematext.com](https://logsene-receiver.sematext.com)        service logagent stop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create the Logagent configuration (see below). Test the configuration with
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;logagent --config logagent.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy the working configuration to &lt;em&gt;/etc/sematext/logagent.conf&lt;/em&gt; and start the service with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Example for Logagent configuration
# Plase adjust following settings: 
#   input.novaSDS011.comPort
#   input.gps.comPort
#   input.nodejsMonitor.SPM_TOKEN
#   output.mqtt.url
#   output.elasticsearch.url
#   output.elasticsearch.indices

options: 
  # suppress log event output to console
  suppress: true
  # Write Logagent stats in the Logagent log file /var/log/logagent.log
  # The stats show how many events have been processed and shipped
  # Log interval in seconds
  printStats: 60

input:
  novaSDS011:
    module: input-nova-sda011
    # Find TTY name: ls -l /dev/tty* | grep 'dialout'
    comPort: /dev/ttyUSB0
    # Working period in minutes. The setting is persistent 
    # for the connected Nova SDS011 sensor
    # 1 minute measurement interval
    workingPeriod: 1

  gps: 
    module: logagent-gps
    # Find TTY name: ls -l /dev/tty* | grep 'dialout'
    comPort: /dev/ttyACM0
    # Emit only location event, to share the location with nova sensor
    emitOnlyLocationEvent: true
    # disable debug output
    debug: false

  # Optional, monitor logagent and device performance
  # Create in Sematext Cloud a Node.js monitoring app
  # to obtain the SPM_TOKEN
  nodejsMonitor: 
    module: @sematext/logagent-nodejs-monitor
    SPM_TOKEN: YOUR_SEMATEXT_NODEJS_MONITORING_TOKEN

  # collect all system logs for troubleshooting
  files: 
    - /var/log/**/*.log

# calculate PM2.5/PM10 ratio in percent 
outputFilter:
  - module: !!js/function &amp;gt;
      function (context, config, eventEmitter, data, callback)  {
        if (data.PM10 &amp;amp;&amp;amp; data.PM10 &amp;gt; 0) {
            data.PM25ratio = (data['PM2.5']/data.PM10) * 100
        }
        callback(null, data)
      }

output: 
  # print log events in yaml format
  # when options.suppress=false
  stdout: yaml
  # Forward sensor logs to MQTT broker
  mqtt:
    module: output-mqtt
    url: mqtt://test.mosquitto.org
    topic: sensor-data
    debug: false
    # optional filter settings matching data field with regular expressions
    # we use the filter to exclude the system log files
    filter: 
      field: logSource
      match: Nova

  # Store log events &amp;amp; sensor data in Sematext Cloud or Elasticsearch
  # Create a log application in Sematext Cloud to obtain a token
  elasticsearch:
    module: elasticsearch
    url: https://logsene-receiver.sematext.com
    # url: https://logsene-receiver.eu.sematext.com
    # url: http://127.0.0.1:9200 
    # We route system logs and sensor data to different indices
    # each index has a list of regular expressions matching the logSource field
    indices:
      # sensor data index
      YOUR_SEMATEXT_LOGS_TOKEN: 
        - Nova
      # system logs index
      ANOTHER__SEMATEXT_LOGS_TOKEN:
        - var.log.*



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;CPU and memory footprint&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A lot of what I do at Sematext has to do with &lt;a href="https://sematext.com/spm/" rel="noopener noreferrer"&gt;performance monitoring&lt;/a&gt;, so I couldn’t help myself and had to look at the telemetry of this DIY IoT setup of mine. The low resource usage of the Node.js based Logagent with less than 1% CPU and less than 34 MB memory is impressive!  Other logging tools like Logstash require 20 times more memory (600 MB+) and would use most of the resources on microcomputers like Banana-Pi or Raspberry-Pi and exhaust the battery in no time!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8568m1atagnyept90mbk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8568m1atagnyept90mbk.png" width="800" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re curious about performance like I am, but also if you want to be notified when there are performance or stability issues with your setup you may want to add the &lt;a href="https://github.com/megastef/logagent-nodejs-monitor" rel="noopener noreferrer"&gt;logagent-nodejs-monitor&lt;/a&gt; plugin as shown below. Finally, we complete the configuration with the collection of all device logs with the file input plugin. The log files in /var/log contain valuable information like Wi-Fi status or USB device information.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;input:
  nodejs-monitor:
    module: '@sematext/logagent-nodejs-monitor'
    SPM_TOKEN: 2f3e0e1f-94b5-47ad-8c72-6a09721515d8
  files: 
    - /var/log/**/*.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We restart Logagent to apply configuration changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_service restart logagent_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After a few seconds, we will see logs and metrics in the Sematext UI.  Having performance metrics and logs in one view is really valuable for any kind of troubleshooting. In my case, the USB wire had a bad contact and the lost USB connection was logged in /var/kern.log (see screenshot).   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2p0m3gyd5hxphnbf14rc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2p0m3gyd5hxphnbf14rc.png" width="800" height="346"&gt;&lt;/a&gt;Node.js performance metrics and Banana-Pi logs in Sematext Cloud&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Visualizing the air pollution&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before we create visualisations, we need to know the data structure of messages produced by the sensor/logagent. We could easily draw numeric values as a date histogram such as &lt;em&gt;PM10, PM2_5&lt;/em&gt; and &lt;em&gt;PM25ratio&lt;/em&gt;. Maps can be created with the geo-coordinates. Having the address of each measurement makes it easy to find measurements in a specific city and the hostname might help us identify the sensor device.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "@timestamp": "2018-02-05T20:59:38.230Z",
  "severity": "info",
  "host": "bananapi",
  "ip": "172.20.10.9",
  "PM2_5": 7.6,
  "PM10": 18,
  "geoip": {
    "location": [
      6.83125466218682,
      49.53914001560465
    ]
  }
  "address": "Weiskirchen, Germany",
  "city": "Weiskirchen",
  "country": "Germany",
  "logSource": "NovaSDS011",
  "PM25ratio": 42.22222222222222,
  "@timestamp_received": "2018-02-05T20:59:58.569Z",
  "logsene_original_type": "logs"
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Example JSON message stored in Elasticsearch / Sematext Cloud&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To visualize all data I’ve used Kibana, which is integrated in Sematext Cloud.  Once the visualisations are created in Kibana, we can create a dashboard showing map and sensor values. At a first glance we can immediately see that air pollution is 50% lower in the north (where I live), than in the office that is close to the main street.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmm0w00xsrcneen1q19kz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmm0w00xsrcneen1q19kz.png" width="800" height="498"&gt;&lt;/a&gt;Kibana Dashboard in Sematext Cloud&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Observation of Particulate Matter concentrations in various scenarios&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The following graph was recorded while traveling from my office location to my home. The spike in the graph happened when I stopped my car and took the measurement device out of the car. You can see that the PM10 value jumped for a short time up to &lt;strong&gt;80&lt;/strong&gt;  &lt;strong&gt;µg/m³&lt;/strong&gt; , which is double the EU limit of 40 µg/m³ average per year, though just for a minute. Good to know that the air in my hometown has only half of the particulate matter compared to the office location – at least as long I don’t start my diesel engine … anyhow a good reason to stay in the home office. &lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg51k36wfckepd3286mmn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg51k36wfckepd3286mmn.png" alt="🙂" width="72" height="72"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6513lditxl4szcwv3yd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6513lditxl4szcwv3yd.png" width="286" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbrwlgrwmdzg9wpus0kx9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbrwlgrwmdzg9wpus0kx9.png" width="422" height="417"&gt;&lt;/a&gt;PM10 levels in Weiskirchen (orange) and Nalbach (red)&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Environment.on(”smog”, alert)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Having dashboards is cool, but you can’t really watch a dashboard all day long.  So let’s use alerts. The open source ELK stack has its limits – no built-in alerting – but we can use alerts in Sematext Cloud. Here a saved query, filtering only PM10 values greater than 40 (EU limit) or 50 (DE limit) is used to trigger alerts:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvuf8s4kcpfoleohoi8tg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvuf8s4kcpfoleohoi8tg.png" width="800" height="753"&gt;&lt;/a&gt;Setup Alert for PM10 values above 50.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs721l211s12095modx1b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs721l211s12095modx1b.png" width="800" height="306"&gt;&lt;/a&gt;Alert notification in Sematext UI&lt;/p&gt;

&lt;p&gt;With such an alert in place, we can add the Event stream (screenshot above) with alerts to a dashboard(screenshot below)  and receive alerts via Slack channel on the mobile phone, for example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd6dd0qbxxaf1l5vaudc1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd6dd0qbxxaf1l5vaudc1.png" width="800" height="500"&gt;&lt;/a&gt;Dashboard in Sematext UI, including Alert notifications&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqqbnezevtnclzqcxsrn6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqqbnezevtnclzqcxsrn6.png" width="615" height="192"&gt;&lt;/a&gt;Slack notification when PM10 reaches the configured threshold of PM10&amp;gt;40 or PM10&amp;gt;50&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;The costs of various sensor devices are low and assembling the gadgets and setting up the software could be done in literally a few hours. It took me much longer to find good solutions for various tiny problems and to code a few &lt;a href="https://sematext.com/docs/logagent/plugins/" rel="noopener noreferrer"&gt;Logagent plugins&lt;/a&gt;, but even scripting a plugin module takes only a few hours. Using &lt;a href="https://sematext.com/cloud" rel="noopener noreferrer"&gt;Sematext Cloud&lt;/a&gt; instead of a local ELK stack is a big time saver for the server setup (I don’t need any physical or cloud servers, just devices and Sematext SaaS). The alerting for Elasticsearch queries and forwarding of alerts to Slack made the solution complete.&lt;/p&gt;

&lt;p&gt;The biggest source of satisfaction in this project was to make the invisible visible with the “electronic nose” – you feel like a Ghostbuster! You see PM10 values increasing when a window gets opened, or when you start to vacuum the living room or when you forget your spaghetti on the stove while programming … &lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg51k36wfckepd3286mmn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg51k36wfckepd3286mmn.png" alt="🙂" width="72" height="72"&gt;&lt;/a&gt; Outside sensors “smell” when a neighbor starts his car engine, a visitor parks his car in front of your house, a guest starts smoking a cigarette on the terrace…&lt;/p&gt;

&lt;p&gt;An interesting fact is that PM10 values are higher close to the main street and actually reached the EU limit (PM10&amp;gt;40) and the German limit (PM10&amp;gt;50) during rush hour in front of my office! The maximum value measured was PM10=69 at my office window. The PM10 values decrease as close as a few hundred meters away from the main street.  Think about how being aware of this could impact your life decisions – a move to a new flat or office could really impact your health. Knowing the time of the highest air pollution could also help to keep particles out of your flat. My measurement showed that airing the office room before 2pm and after 9pm would be best to keep the PM concentration low.  Luckily, I recently moved to a small village and the good thing I can find here is fresh air and, as you can see, inspiration and time for fresh ideas!&lt;/p&gt;

&lt;p&gt;The real surprise to me was that I ended up in politics by calling the city administration for an appointment with the mayor to discuss with him a traffic light, which switches to red once the PM10 limit is reached. Cars could be kept out of the town because a bypass road already exists, but is currently underutilized and should be used much more. I hope I get my appointment with the mayor scheduled soon and when I speak with him I will have data to back up my suggestions. The administration first asked for a written letter to give me an official statement – let’s see if we get one more Smart-City on this planet finally making data-driven decisions applied in real-life, and not only in business&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg51k36wfckepd3286mmn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg51k36wfckepd3286mmn.png" alt="🙂" width="72" height="72"&gt;&lt;/a&gt; Stay tuned!&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://sematext.com/blog/iot-air-pollution-tracking-with-node-js-elastic-stack-and-mqtt/" rel="noopener noreferrer"&gt;IoT: Air Pollution Tracking with Node.js, Elastic Stack, and MQTT&lt;/a&gt; appeared first on &lt;a href="https://sematext.com" rel="noopener noreferrer"&gt;Sematext&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>node</category>
      <category>devops</category>
      <category>monitoring</category>
      <category>iot</category>
    </item>
    <item>
      <title>Top 10 Docker Logging Gotchas</title>
      <dc:creator>Stefan Thies</dc:creator>
      <pubDate>Wed, 10 Jan 2018 08:17:01 +0000</pubDate>
      <link>https://forem.com/sematext/top-10-docker-logging-gotchas-1mlk</link>
      <guid>https://forem.com/sematext/top-10-docker-logging-gotchas-1mlk</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OxNZdF8Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2018/01/top-10-docker-logging-gotchas.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OxNZdF8Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2018/01/top-10-docker-logging-gotchas.jpg" alt="top 10 docker logging gotchas"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Docker changed not only how applications are deployed, it also changed the workflow for log management. Instead of writing logs to files, containers write logs to the console (stdout/stderr) and &lt;a href="https://docs.docker.com/engine/admin/logging/overview/"&gt;Docker Logging Drivers&lt;/a&gt; forward logs to their destination. A check against Docker &lt;a href="https://github.com/moby/moby/labels/area%2Flogging"&gt;Github issues&lt;/a&gt; quickly shows that users have various problems when dealing with Docker logs. Managing logs with Docker seems to be tricky and needs a deeper knowledge of Docker Logging Driver implementations and alternatives to overcome issues that people report.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QkpkIsGv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2018/06/docker.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QkpkIsGv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2018/06/docker.svg" alt=""&gt;&lt;/a&gt; Execute commands in containers, Docker networks, Data cleanup and more…  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://sematext.com/docker-commands-cheat-sheet/?utm_medium=blogpost&amp;amp;utm_source=devto&amp;amp;utm_campaign=top-10-docker-logging-gotchas&amp;amp;utm_content=blog-docker-commands-cheatsheet"&gt;Docker Commands Cheat Sheet Download&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;So what are the top 10 Docker logging gotchas, every Docker user should know?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;First, let’s start with an overview of Docker Logging Drivers and options to ship logs to centralized Log Management solutions such as Elastic Stack (former ELK Stack) or &lt;a href="https://sematext.com/cloud/"&gt;Sematext Cloud&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8AwvesWp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2018/01/top-10-docker-logging-gatchas-sematext.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8AwvesWp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2018/01/top-10-docker-logging-gatchas-sematext.png" alt="top 10 docker logging gatchas sematext"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the early days of Docker, container logs were only available via Docker remote API, i.e. via “docker logs” command and a few advanced log shippers. Later on, Docker introduced logging drivers as plugins, to open Docker for integrations with various log management tools. These logging drivers are implemented as binary plugins in the docker daemon. Recently, the plugin architecture got extended to run logging drivers as external processes, which could register as plugins and retrieve logs via Unix socket. Currently, logging drivers shipped with docker binaries are binary plugins, but this might change in the near future.&lt;/p&gt;

&lt;p&gt;Docker Logging Drivers receive container logs and forward them to remote destinations or files. The default logging driver is “json-file”. It stores container logs in JSON format on local disk. Docker has a plugin architecture for logging drivers, so there are plugins for open source tools and commercial tools available:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Journald – storing container logs in the system journal&lt;/li&gt;
&lt;li&gt;Syslog Driver – supporting UDP, TCP, TLS&lt;/li&gt;
&lt;li&gt;Fluentd – supporting TCP or Unix socket connections to fluentd &lt;/li&gt;
&lt;li&gt;Splunk – HTTP/HTTPS forwarding to Splunk server&lt;/li&gt;
&lt;li&gt;Gelf – UDP log forwarding to Graylog2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a complete log management solution additional tools need to be involved:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log parser to structure logs, typically part of log shippers (fluentd, rsyslog, logstash, logagent, …)&lt;/li&gt;
&lt;li&gt;Log indexing, visualisation and alerting: 

&lt;ul&gt;
&lt;li&gt;Elasticsearch and Kibana (Elastic Stack, also known as ELK stack)&lt;/li&gt;
&lt;li&gt;Splunk&lt;/li&gt;
&lt;li&gt;Logentries&lt;/li&gt;
&lt;li&gt;Loggl&lt;/li&gt;
&lt;li&gt;Sumologic&lt;/li&gt;
&lt;li&gt;Graylog  OSS / Enterprise&lt;/li&gt;
&lt;li&gt;Sematext Cloud / Enterprise&lt;/li&gt;
&lt;li&gt;and many more…&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To ship logs to one of the backends you might need to select a logging driver or logging tool that supports your Log Management solution of choice. If your tool needs Syslog input, you might choose the Syslog driver.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s look into Top 10 Docker logging gotchas every Docker user should know.
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. Docker logs command works only with json-file Logging driver&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The default Logging driver “json-file” writes logs to the local disk, and the json-file driver is the only one that works in parallel to “docker logs” command. As soon one uses alternative logging drivers, such as Syslog, Gelf or Splunk,  the Docker logs API calls start failing, and the “docker logs” command shows an error reporting the limitations instead of displaying the logs on the console. Not only does the docker log command fail, but many other tools using the Docker API for logs, such as Docker user interfaces like Portainer or log collection containers like Logspout are not able to show the container logs in this situation.&lt;/p&gt;

&lt;p&gt;See &lt;a href="https://github.com/moby/moby/issues/30887"&gt;https://github.com/moby/moby/issues/30887&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;2. Docker Syslog driver can block container deployment&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Using Docker Syslog driver with TCP or TLS is a reliable way to deliver logs. However, the Syslog logging driver requires an established TCP connection to the Syslog server when a container starts up.  If this connection can’t be established at container start time, the container start fails with an error message like&lt;/p&gt;

&lt;p&gt;docker: Error response from daemon: Failed to initialize logging driver: dial tcp&lt;/p&gt;

&lt;p&gt;This means a temporary network problem or high network latency could block the deployment of containers. In addition, a restart of the Syslog server could tear down all containers logging via TCP/TS to a central Syslog server, which is definitely the situation to avoid.&lt;/p&gt;

&lt;p&gt;See: &lt;a href="https://github.com/docker/docker/issues/21966"&gt;https://github.com/docker/docker/issues/21966&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;3. Docker syslog driver loses logs when destination is down&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Similar to the issue #2 above, causing a loss of logs is the missing ability of Docker logging drivers to buffer logs on disk when they can’t be delivered to remote destinations.&lt;/p&gt;

&lt;p&gt;An interesting issue to watch: &lt;a href="https://github.com/moby/moby/issues/30979"&gt;https://github.com/moby/moby/issues/30979&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;4. Docker logging drivers don’t support multi-line logs like error stack traces&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;When we think about logs, most people think of simple single-line logs, say like Nginx or Apache logs.  However, logs can also span multiple lines.  For example, exception traces typically span multiple lines, so to help Logstash users we’ve shared how to &lt;a href="https://sematext.com/blog/handling-stack-traces-with-logstash/"&gt;handle stack traces with Logstash&lt;/a&gt;.  Things are no better in the world of containers, where things get even more complicated because logs from all apps running in containers get emitted to the same output – stdout. No wonder seeing &lt;a href="https://github.com/moby/moby/issues/22920"&gt;issue #22920&lt;/a&gt;closed with “Closed. Don’t care.” disappointed so many people.  Luckily, there are tools like Sematext&lt;a href="https://github.com/sematext/sematext-agent-docker"&gt;Docker Agent&lt;/a&gt; that can parse multi-line logs out of the box, as well as apply custom multi-line patterns.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;5. Docker service logs command hangs with non-json logging driver&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;While the json-files driver seems robust, other log drivers could unfortunately still cause trouble with Docker Swarm mode.&lt;/p&gt;

&lt;p&gt;See Github Issue: &lt;a href="https://github.com/docker/docker/issues/28793"&gt;https://github.com/docker/docker/issues/28793&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;6. Docker daemon crashes if fluentd daemon is gone and buffer is full&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Another scenario where a logging driver causes trouble when the remote destination is not reachable – in this &lt;a href="https://github.com/moby/moby/issues/32567"&gt;particular case&lt;/a&gt; the logging drivers throws exceptions that cause Docker daemon to crash.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;7. Docker container gets stuck in Created state on Splunk driver failure&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;If the Splunk server returns a 504 on container start, the container is actually started, but docker reports the container as failed to start. Once in this state, the container no longer appears under docker ps, and the container process cannot be stopped with docker kill. The only way to stop the process is to manually kill it.&lt;/p&gt;

&lt;p&gt;Github: &lt;a href="https://github.com/moby/moby/issues/24376"&gt;https://github.com/moby/moby/issues/24376&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;8. Docker logs skipping/missing application logs (journald driver)&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;It turns out that this issue is caused by journald rate limits, which needs to be increased as Docker creates logs for all running applications and journald might skip some logs due to its rate limitation settings. So be aware of your journald settings when you connect Docker to it.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;9. Gelf driver issues&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The Gelf logging driver is missing a TCP or TLS option and supports only UDP, which could be risky to lose log messages when UDP packets get dropped. Some issues report a problem of DNS resolution/caching with GELF drivers so your logs might be sent to “Nirvana” when your Graylog server IP changes – and this could happen quickly using container deployments.  &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;10. Docker does not support multiple log drivers&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;It would be nice to have logs stored locally on the server and the possibility to ship them to remote servers. Currently, Docker does not support multiple log drivers, so users are forced to pick a single log driver. Not an easy decision knowing various issues listed in this post.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;That’s it! My Top 10 Docker Logging Gotchas!&lt;/strong&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  What’s next?
&lt;/h3&gt;

&lt;p&gt;You should think about &lt;a href="https://sematext.com/docker"&gt;not only collecting logs but also host and container metrics, and events&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://sematext.com/blog/top-10-docker-logging-gotchas/"&gt;Top 10 Docker Logging Gotchas&lt;/a&gt; appeared first on &lt;a href="https://sematext.com"&gt;Sematext&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://sematext.com/kubernetes/cheatsheet/"&gt;&lt;br&gt;&lt;br&gt;
 &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tbbzyn9c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sematext.com/wp-content/uploads/2017/04/kubernetes-cheatsheet-pick.jpg" alt="Kubernetes Cheat Sheet" title="The Essential Kubernetes Cheat Sheet"&gt;&lt;br&gt;&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://sematext.com/kubernetes-cheat-sheet/"&gt;Have you started using Kubernetes?&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;We’ve prepared &lt;a href="https://sematext.com/kubernetes-cheat-sheet/"&gt;a Kubernetes Cheat Sheet&lt;/a&gt; which puts all key Kubernetes commands (think kubectl) at your fingertips. Organized in logical groups from resource management (e.g. creating or listing pods, services, daemons), viewing and finding resources, to monitoring and logging. &lt;a href="https://sematext.com/kubernetes-cheat-sheet/"&gt;&lt;strong&gt;Download yours&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;




</description>
      <category>logging</category>
      <category>docker</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
