<?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>DEV Community: Varun Subramanian</title>
    <description>The latest articles on DEV Community by Varun Subramanian (@varunpappu).</description>
    <link>https://dev.to/varunpappu</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%2F496540%2F65e53736-d90a-4329-a6d6-eed78e00817b.jpeg</url>
      <title>DEV Community: Varun Subramanian</title>
      <link>https://dev.to/varunpappu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/varunpappu"/>
    <language>en</language>
    <item>
      <title>Capacity Planning for Elasticsearch</title>
      <dc:creator>Varun Subramanian</dc:creator>
      <pubDate>Thu, 22 Jul 2021 14:05:49 +0000</pubDate>
      <link>https://dev.to/varunpappu/capacity-planning-117l</link>
      <guid>https://dev.to/varunpappu/capacity-planning-117l</guid>
      <description>&lt;p&gt;Elasticsearch (ES) is a scalable distributed system that can be used for searching, logging, metrics and much more. To run production ES either self-hosted or in the cloud, one needs to plan the infrastructure and cluster configuration to ensure a healthy and highly reliable performance deployment.&lt;br&gt;
In this article, we will focus on how to estimate and create a plan based on the usage metrics before deploying a production-grade cluster.&lt;/p&gt;
&lt;h1&gt;
  
  
  Capacity Planning:
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Identifying the minimum number of master nodes&lt;/li&gt;
&lt;li&gt;Sizing of the Elasticsearch Service&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Identifying the minimum number of master nodes:
&lt;/h2&gt;

&lt;p&gt;The most important node in the cluster is the Master node.  Master node is responsible for wide range of cluster wide activities such as creation, deletion, shard allocation etc. A stable cluster is dependent on the health of the master node.&lt;/p&gt;

&lt;p&gt;It is advisable to have dedicated master nodes because an overloaded master node with other responsibilities will not function properly. The most reliable way to avoid overloading the master with other tasks is to configure all the master-eligible nodes to be dedicated master-eligible nodes which only have the master role, allowing them to focus on managing the cluster.&lt;/p&gt;

&lt;p&gt;A lightweight cluster may not require master-eligible nodes but once the cluster has more than &lt;strong&gt;6&lt;/strong&gt; nodes, it is advisable to use dedicated master-eligible nodes.&lt;/p&gt;

&lt;p&gt;The quorum for decision making when selecting the minimum master nodes is calculated using the below formulae:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Minimum Master Nodes = (N / 2) + 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;N&lt;/strong&gt; is the total number of “master-eligible” nodes in your cluster (rounded off to the nearest integer)&lt;/p&gt;

&lt;p&gt;In an ideal environment, the minimum number of master nodes will be &lt;strong&gt;3&lt;/strong&gt; and if not maintained, it can result in a “split-brain” that can lead to an unhealthy cluster and loss of data.&lt;/p&gt;

&lt;p&gt;Let us consider the below examples for better understanding:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VOvbYlrY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bpvczfab55e6zbrw8tyv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VOvbYlrY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bpvczfab55e6zbrw8tyv.png" alt="Scenario A"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Scenario &lt;strong&gt;A&lt;/strong&gt;, you have ten regular nodes (ones that can either hold data and become master), the quorum is 6. Even though if we lose the master node due to network connection, the cluster will elect a new master and will still be healthy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k5qIaHsc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4cdeztiny21gd2pk32iy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k5qIaHsc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4cdeztiny21gd2pk32iy.png" alt="Scenario B"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Scenario &lt;strong&gt;B&lt;/strong&gt;, you have three dedicated master nodes and a hundred data nodes, the quorum is 2. Even though if we lose the master node due to failure, the cluster will elect a new master and will still be healthy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x0HuHn-R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zelaf1709tzwt3mv8bpg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x0HuHn-R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zelaf1709tzwt3mv8bpg.png" alt="Scenario C"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Scenario &lt;strong&gt;C&lt;/strong&gt;, you have two regular nodes, with quorum as 2. If there is a network failure between the nodes, then each node will try to elect itself as the Master and will make the cluster inoperable.&lt;/p&gt;

&lt;p&gt;Setting the value to &lt;strong&gt;1&lt;/strong&gt; is permissible but it doesn't guarantee protection against loss of data when the master node goes down.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Avoid repeated changes to the master node setting as it may lead to cluster instability when the service attempts to change the number of dedicated master nodes.&lt;/p&gt;
&lt;h2&gt;
  
  
  Sizing of the Elasticsearch Service:
&lt;/h2&gt;

&lt;p&gt;The sizing of Elasticsearch service is more of making an educated estimate rather than having a surefire methodology. The estimate is more about taking into consideration the storage, services to be used and the Elasticsearch itself. The estimate acts as a useful starting point for most critical aspects of sizing the domains; testing them with representative workloads and monitoring their performance.&lt;/p&gt;

&lt;p&gt;The following are the key components to remember before sizing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use case&lt;/strong&gt;, (i.e) for real-time search or monitoring of security, log analytics, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Growth planning&lt;/strong&gt;, for the long-term and the short-term.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since Elasticsearch is horizontally scalable, if proper indexing and sharding are not done appropriately at the initial stages, one will have to go through painful approvals to add hardware and will end up underutilising the infrastructure.&lt;/p&gt;

&lt;p&gt;The three key components to remember before choosing the appropriate cluster settings are as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Calculating the storage requirements&lt;/li&gt;
&lt;li&gt;Choosing the number of shards&lt;/li&gt;
&lt;li&gt;Choosing the instance types and testing&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Calculating storage requirements:
&lt;/h2&gt;

&lt;p&gt;In Elasticsearch, every document is stored in the form of an index. &lt;br&gt;
The storage of documents can be classified as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Growing Index:&lt;/strong&gt; A single index that keeps growing over periods of time with periodic updates or insertion. For the Growing index, the data is stored on the disk and based on the available sources one can determine how much storage space it consumes. Some common examples are documents and e-commerce search etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rollover Index:&lt;/strong&gt; Data is being continuously written to a temporary index, with an indexing period and retention time. For rolling over indices, the amount of data generated will be calculated based on the amount of data generated during the retention period of the index.  For example, if you generate &lt;strong&gt;100 MiB&lt;/strong&gt; of logs per hour, that’s &lt;strong&gt;2.4 GiB&lt;/strong&gt; per day, which will amount to &lt;strong&gt;72 GiB&lt;/strong&gt; of data for a retention period of &lt;strong&gt;30 days&lt;/strong&gt;. Some common examples are log analytics, time-series processing etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other aspects need to be taken into consideration in addition to the storage space are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Number of replicas:&lt;/strong&gt; A replica is a complete copy of an index and ends up eating the same amount of disk space. By default, every index in an ES has a replica count of 1. It is recommended to have a replica count as &lt;strong&gt;1&lt;/strong&gt;, as it will prevent data loss. Replicas also help in improving search performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ES overhead:&lt;/strong&gt; ES reserves 5% or 10% for margin of error and 15% to stay under the disk watermarks for segment merges, logs, and other internal operations. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Insufficient storage space is one of the most common causes of cluster instability, so you should cross-check the numbers when you choose instance types, instance counts, and storage volumes.&lt;/p&gt;
&lt;h2&gt;
  
  
  Choosing the number of shards:
&lt;/h2&gt;

&lt;p&gt;The second component to consider is choosing the right indexing strategy for the indices. In ES, by default, every index is divided into n numbers of primary and replicas. (For example, if there are &lt;strong&gt;2&lt;/strong&gt; primary and &lt;strong&gt;1&lt;/strong&gt; replica shard then the total count of shards is &lt;strong&gt;4&lt;/strong&gt;). The primary shard count for an existing index cannot be changed once created.&lt;br&gt;
Every shard uses some amount of CPU and memory and having too many small shards can cause performance issues and out-of-memory errors. But that doesn't entitle one to create shards that are too large either.&lt;/p&gt;

&lt;p&gt;The rule of thumb is to ensure that the shard size is always between &lt;strong&gt;10-50 GiB&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The formula for calculating the approximate number of shards is as follows:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;App. Number of Primary Shards = (Source Data + Room to Grow) * (1 + Indexing Overhead) / Desired Shard Size&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;In simple terms, shards size should be small but not small enough so that the underlying ES instance does not have a needless strain on the hardware. &lt;br&gt;
Let us consider the below example for better understanding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scenario 1:&lt;/strong&gt;
Suppose you have &lt;strong&gt;50 GiB&lt;/strong&gt; of data and you don't expect it to grow over time. Based on the formula above, the number of shards should be (50 * 1.1 / 30) = &lt;strong&gt;2&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The chosen desired shard size is &lt;em&gt;30 GiB&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Scenario 2:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Suppose the same &lt;strong&gt;50 GiB&lt;/strong&gt; is expected to quadruple by next year, then the approximate shards count would be ((50 + 150) * 1.1 / 30) = &lt;strong&gt;8&lt;/strong&gt;.&lt;br&gt;
Even though we are not going to be having the extra &lt;strong&gt;150 GiB&lt;/strong&gt; of data immediately, it is important to note that the preparation does not end up creating multiple unnecessary shards. If you remember from earlier, shards consume huge amounts of CPU and memory and in this scenario, if we end up creating tiny shards this can lead to performance degradation in the present.&lt;br&gt;
With the above shard size as &lt;strong&gt;8&lt;/strong&gt;, let us make the calculation: (50 * 1.1) / 8 = &lt;strong&gt;6.86 GiB&lt;/strong&gt; per shard.&lt;br&gt;
The shard size is way below the recommended size range &lt;strong&gt;(10-50 GiB)&lt;/strong&gt; and this will end up consuming extra resources. To solve this problem, our consideration should be more of a middle ground approach of &lt;strong&gt;5&lt;/strong&gt; shards, which leaves you with 11 GiB (50 * 1.1 / 5) shards at present and 44 GiB ((50 + 150) * 1.1 / 5) in the future.&lt;/p&gt;

&lt;p&gt;In both the above approaches the shards sizing is more of &lt;strong&gt;approximation&lt;/strong&gt; rather than &lt;strong&gt;appropriate&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It is very important to note that, never appropriate sizing as you have the risk of running out of disk space before even reaching the threshold limit we set. For example, let us consider an instance that has a disk space of &lt;strong&gt;128 GiB&lt;/strong&gt;. If you stay below &lt;strong&gt;80% (103 GiB)&lt;/strong&gt; disk usage and the size of the shards is &lt;strong&gt;10 GiB&lt;/strong&gt;, then we can accommodate &lt;strong&gt;10&lt;/strong&gt; shards approximately. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; On a given node, it is advisable to have no more than 20 shards per GiB of Java heap.&lt;/p&gt;
&lt;h2&gt;
  
  
  Choosing instance types and testing:
&lt;/h2&gt;

&lt;p&gt;After calculating the storage requirements and choosing the number of shards that you need, the next step is to make the hardware decisions. Hardware requirements will vary between workloads, but we can make a guesstimate. In general, the storage limits for each instance type map to the amount of CPU and memory that you might need for your workloads. &lt;br&gt;
The following formulae help with better understanding when it comes to choosing the right instance type&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0DWxtnRb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bm0c4m4phxd49n1j00wl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0DWxtnRb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bm0c4m4phxd49n1j00wl.png" alt="Choosing the right instance type"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Total Data (GB) = Raw data (GB) per day * Number of days retained * (Number of replicas + 1)
Total Storage (GB) = Total data (GB) * (1 + 0.15 disk Watermark threshold + 0.1 Margin of error)
Total Data Nodes = ROUNDUP(Total storage (GB) / Memory per data node / Memory:Data ratio)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a better understanding of the formulae, let us consider the below example:&lt;/p&gt;

&lt;p&gt;A logging application pushes close to &lt;strong&gt;3 GiB&lt;/strong&gt; data per day and the retention period of data is &lt;strong&gt;90&lt;/strong&gt; days&lt;br&gt;
You can use &lt;strong&gt;8GB&lt;/strong&gt; memory per node for this small deployment. Let’s do the math:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Total Data (GB) = 3GB x (3 x 30 days) x 2 = 540GB&lt;br&gt;
Total Storage (GB) = 540GB x (1+0.15+0.1) = 675GB&lt;br&gt;
Total Data Nodes = 675GB disk / 8GB RAM /30 ratio = 3 nodes&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To summarise everything we have seen so far:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lzl_eBcx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ap4r42jffq11utpjnmh5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lzl_eBcx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ap4r42jffq11utpjnmh5.png" alt="Capacity Planner"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  References:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.elastic.co/blog/found-sizing-elasticsearch"&gt;Sizing of ES&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.cncf.io/blog/2021/03/25/how-to-build-an-elastic-search-cluster-for-production/"&gt;ES Cluster for Production&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/what-is-amazon-elasticsearch-service.html"&gt;AWS ES&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.elastic.co/blog/benchmarking-and-sizing-your-elasticsearch-cluster-for-logs-and-metrics"&gt;Sizing and Benchmarking&lt;/a&gt;&lt;/p&gt;

</description>
      <category>elasticsearch</category>
      <category>capacityplanning</category>
      <category>productivity</category>
      <category>management</category>
    </item>
    <item>
      <title>Monitoring AWS Managed Services using Elastic</title>
      <dc:creator>Varun Subramanian</dc:creator>
      <pubDate>Wed, 24 Mar 2021 11:08:18 +0000</pubDate>
      <link>https://dev.to/varunpappu/monitoring-aws-managed-services-using-elastic-46f4</link>
      <guid>https://dev.to/varunpappu/monitoring-aws-managed-services-using-elastic-46f4</guid>
      <description>&lt;p&gt;Over the course of years the number of cloud native services provided by the cloud platforms have been ever increasing. The platforms do come in with their inbuilt monitoring services but from an administrative standpoint of view it is not that helpful as it does not come with a consolidated view for the end users. To overcome this and to provide a common platform for various service logs and its corresponding visualisation many third party providers have come into the play such as Elastic, Datadog, Splunk etc. &lt;/p&gt;

&lt;p&gt;In this article we will be seeing the use of one such service provider: Elastic.  Elastic provides  out of the box dashboards to visualise AWS managed services such as Loadbalancers, VPC, S3, CloudTrail and Billing. We will be using a sample Web application hosted on AWS cloud to provide how consolidated dashboards can be viewed in Kibana.&lt;/p&gt;

&lt;h2&gt;
  
  
  Monitoring Dashboards for AWS Services
&lt;/h2&gt;

&lt;p&gt;Once we complete the exercise, below are the set of Dashboards that would be available for the Infrastructure Monitoring team to visualise how AWS services are functioning, identify and troubleshoot problems pertaining to any of the services.&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%2Fs4o9emf39t1cn1ift45y.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%2Fs4o9emf39t1cn1ift45y.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&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%2Ffhtpdz1u9xa81lxyi6uv.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%2Ffhtpdz1u9xa81lxyi6uv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Deployment Architecture
&lt;/h2&gt;

&lt;p&gt;Below is a typical web application deployed on AWS cloud that uses a combination of cloud native services and web application server to serve APIs. We also have a static site hosted on Cloudfront to serve static html/css content.  &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%2Fzwfm2civa92knqllodt0.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%2Fzwfm2civa92knqllodt0.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Metricbeat
&lt;/h2&gt;

&lt;p&gt;Metricbeat is a lightweight shipper that you can install on your servers to periodically collect metrics (cpu usage, Disk I/O, network bytes in/out ) from the operating system and from services running on the server. Metricbeat takes the metrics and statistics that it collects and ships them to the output that you specify, such as Elasticsearch or Logstash. Metricbeat by default supports various pre-built modules but in this article we will be focusing on the AWS module. &lt;/p&gt;

&lt;p&gt;Metricbeat collects two broad categories of metrics i.e. host metrics and managed services metrics. We will be dedicating one EC2 machine to run metricbeat for AWS managed services metrics collection and another metricbeat on EC2 machine to demonstrate metrics collected from the host server.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE: We will be focusing on metricbeat agent from 7.4 and later&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  AWS Module of Metricbeat
&lt;/h3&gt;

&lt;p&gt;The AWS module for metricbeat currently supports out of the box collection of metrics for the following AWS Services:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EC2&lt;/li&gt;
&lt;li&gt;Elastic Loadbalancer&lt;/li&gt;
&lt;li&gt;Lambda functions &lt;/li&gt;
&lt;li&gt;NAT Gateway&lt;/li&gt;
&lt;li&gt;RDS&lt;/li&gt;
&lt;li&gt;S3 Storage&lt;/li&gt;
&lt;li&gt;SNS&lt;/li&gt;
&lt;li&gt;SQS&lt;/li&gt;
&lt;li&gt;Transit Gateway&lt;/li&gt;
&lt;li&gt;VPN&lt;/li&gt;
&lt;li&gt;Billing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before we dive into installing and configuring metricbeat, let's understand how metricbeat collects, stores and sends metrics to Elastic.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enable Cloudwatch metrics for each of the AWS Managed services. This will start sending AWS services to CloudWatch, from where Metricbeat will be reading. This &lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-services-cloudwatch-metrics.html" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; gives step by step instructions on how to enable Cloudwatch for a specific AWS service.&lt;/li&gt;
&lt;li&gt;Metricbeat will be running on a EC2 machines and configured to collect AWS managed services metrics. This is as simple as enabling the AWS module in metricbeat config file.&lt;/li&gt;
&lt;li&gt;Hands-off, Metricbeat periodically queries AWS Cloudwatch to read metrics and sends it to Elasticsearch server, where it is indexed and visualised in Kibana.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Prerequisites:
&lt;/h3&gt;

&lt;p&gt;Running a Metricbeat requires the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;AWS account with credentials. Below section covers the Roles required for Metricbeat to read metrics.&lt;/li&gt;
&lt;li&gt;Running Elastic Stack (use you self hosted Elastic or &lt;a href="https://www.elastic.co/observability" rel="noopener noreferrer"&gt;create a free 14-day trial on Elastic Cloud&lt;/a&gt;). &lt;em&gt;This article doesn’t work with AWS managed elasticsearch.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;EC2 machine to run Metricbeat agent &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  IAM policy:
&lt;/h3&gt;

&lt;p&gt;Metricbeat requires certain IAM Policy permissions for it to fetch data from the required resources. An &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html" rel="noopener noreferrer"&gt;IAM policy&lt;/a&gt; is an entity that defines permissions to an object within your AWS environment. Create a customized IAM policy for Metricbeat with specific permissions is needed. Please see &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html" rel="noopener noreferrer"&gt;Creating IAM Policies&lt;/a&gt; for more details. After Metricbeat IAM policy is created, you need to add this policy to the IAM user which provided the credentials in the previous step.&lt;/p&gt;

&lt;p&gt;The following table shows the IAM Policies that needs to be added to each Metricbeat&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%2F9ory7yldwab8pg51ijwj.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%2F9ory7yldwab8pg51ijwj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Consolidated IAM Policy:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeRegions",
                "ec2:DescribeInstances"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "cloudwatch:GetMetricData",
                "cloudwatch:ListMetrics"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "sts:GetCallerIdentity"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "iam:ListAccountAliases"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "tag:getResources"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "rds:DescribeDBInstances",
                "rds:ListTagsForResource"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "sns:ListTopics"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "sqs:ListQueues"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "ce:GetCostAndUsage"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Metricbeat Agent:
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Installing the Metricbeat Agent on EC2 machine:
&lt;/h4&gt;

&lt;p&gt;Launch a EC2 machine that runs Ubuntu and login to that machine and run below command to download and install metricbeat.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.11.1-amd64.deb&lt;br&gt;
sudo dpkg -i metricbeat-7.11.1-amd64.deb&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Edit the configuration:
&lt;/h5&gt;
&lt;h6&gt;
  
  
  Elastic Cloud:
&lt;/h6&gt;

&lt;p&gt;Modify &lt;em&gt;/etc/metricbeat/metricbeat.yml&lt;/em&gt; to set the connection information for Elastic Cloud:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cloud.id: &amp;lt;Get your cloud_id from the Elastic Cloud&amp;gt;&lt;br&gt;
cloud.auth: "elastic:&amp;lt;password&amp;gt;"&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Enable the AWS module:
&lt;/h5&gt;

&lt;p&gt;In the out-of-box configuration of Metricbeat, only the system module is enabled by default, so you will need to explicitly enable the AWS module. The following command enables the AWS configuration in the &lt;em&gt;modules.d&lt;/em&gt; directory on MacOS and Linux systems:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;metricbeat modules enable aws&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Set AWS credentials in the config file:
&lt;/h5&gt;

&lt;p&gt;To configure AWS credentials, users can put the credentials into the Metricbeat module configuration or use environment variables to pass them. The ability to load AWS credentials from a shared credentials file is added into aws module. &lt;a href="https://docs.aws.amazon.com/ses/latest/DeveloperGuide/create-shared-credentials-file.html" rel="noopener noreferrer"&gt;Create a shared credential&lt;/a&gt; by following these steps. File will be created under the below location.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;For Windows:
  C:\Users\&amp;lt;yourusername&amp;gt;\.aws\credentials
For  Linux, MacOS, or Unix:
  ~/.aws/credentials
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Optional) Users can specify the profile name using parameter credential_profile_name in aws module config. For more details on AWS credentials types and supported formats, please see &lt;a href="https://www.elastic.co/guide/en/beats/metricbeat/7.4/metricbeat-module-aws.html#aws-credentials-config" rel="noopener noreferrer"&gt;AWS credentials configuration&lt;/a&gt; for more detail.&lt;/p&gt;

&lt;h5&gt;
  
  
  Sample AWS module Configuration:
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;metricbeat.modules:
- module: aws
  period: 300s
  metricsets:
    - ec2
- module: aws
  period: 300s
  metricsets:
    - sqs
  regions:
    - us-west-1
- module: aws
  period: 86400s
  metricsets:
    - s3_request
    - s3_daily_storage
- module: aws
  period: 300s
  metricsets:
    - cloudwatch
  metrics:
    - namespace: AWS/EC2
      name: ["CPUUtilization"]
      statistic: ["Average"]    
    - namespace: AWS/EBS
    - namespace: AWS/ELB
      resource_type: elasticloadbalancing
- module: aws
  period: 60s
  metricsets:
    - elb
    - natgateway
    - rds
    - transitgateway
    - usage
    - vpn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;namespace:&lt;/strong&gt; A namespace in AWS CloudWatch is a container for metrics from a specific application or service. Each service has its own namespace, for example Amazon EC2 uses AWS/EC2 namespace and Amazon Elastic Block Storage uses AWS/EBS namespace. Please see the full list of services and namespaces that publish CloudWatch metrics for more details.
name: Users can specify what are the specific CloudWatch metrics that need to be collected per namespace.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;dimensions:&lt;/strong&gt; Dimensions are used to refine metrics returned for each instance. For example, InstanceId, ImageId and InstanceType all can be used as dimensions to filter data requested from Amazon EC2.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;statistic:&lt;/strong&gt; Users can specify one or more statistic methods for each CloudWatch metric setting. By default, average, count, maximum, minimum and sum will all be collected for each metric.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;tags:&lt;/strong&gt; resource_type_filter: Tags for resources will not be collected unless this parameter is set. Each resource in AWS has a specific resource type and the common format is service[:resourceType]. Please see &lt;a href="https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_GetResources.html#resourcegrouptagging-GetResources-request-ResourceTypeFilters" rel="noopener noreferrer"&gt;resource type filters&lt;/a&gt; for more details.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;credential_profile_name:&lt;/strong&gt; If the aws credentials config is done it will be automatically picked up, else one can enter the details manually.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Start Metricbeat:
&lt;/h5&gt;

&lt;p&gt;The setup command loads the Kibana dashboards. If the dashboards are already set up, omit this command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo metricbeat setup&lt;br&gt;
sudo service metricbeat start&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Module Status:
&lt;/h5&gt;

&lt;p&gt;Metricbeat comes with pre-built Kibana dashboards and UIs for visualizing log data. The dashboards would have been loaded earlier when the setup command was run. &lt;/p&gt;

&lt;p&gt;In the Kibana side navigation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click Discover, to see Metricbeat data. Also make sure the predefined metricbeat-* index pattern is selected.&lt;/li&gt;
&lt;li&gt;Click Dashboard, then search for "AWS metric*", select the dashboard that you want to open.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Filebeat
&lt;/h2&gt;

&lt;p&gt;Filebeat is a lightweight shipper for forwarding and centralizing log data. Installed as an agent on your servers, Filebeat monitors the log files or locations that you specify, collects log events, and forwards them either to Elasticsearch or Logstash for indexing. Filbeat by default supports various pre-built modules but in this article we will be focusing on the AWS module. &lt;/p&gt;
&lt;h3&gt;
  
  
  AWS Module of Filebeat:
&lt;/h3&gt;

&lt;p&gt;The AWS module for filebeat currently supports the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CloudTrail&lt;/li&gt;
&lt;li&gt;CloudWatch&lt;/li&gt;
&lt;li&gt;EC2&lt;/li&gt;
&lt;li&gt;Elastic Loadbalancer&lt;/li&gt;
&lt;li&gt;S3 Access&lt;/li&gt;
&lt;li&gt;VPC Flow logs&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Prerequisites:
&lt;/h3&gt;

&lt;p&gt;Running a filebeat requires the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Configure AWS Services to send logs to S3.  All files can be placed on the same bucket.

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.amazonaws.cn/en_us/awscloudtrail/latest/userguide/cloudtrail-create-a-trail-using-the-console-first-time.html" rel="noopener noreferrer"&gt;CloudTrail logs to S3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs-s3.html" rel="noopener noreferrer"&gt;VPC flow logs to S3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html#enable-access-logging" rel="noopener noreferrer"&gt;Elastic Loadbalancer Access logs to S3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/enable-server-access-logging.html#enable-sever-access-logs" rel="noopener noreferrer"&gt;Enable S3 Access Logs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Setting up the SQS service in the AWS Account. (&lt;a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-getting-started.html" rel="noopener noreferrer"&gt;SQS Service&lt;/a&gt;). This SQS service will be used to notify filebeat when new file is placed in S3 bucket configured in step 1.
AWS account with credentials.&lt;/li&gt;
&lt;li&gt;Running Elastic Stack. (This can either be a cluster in 4. Elasticsearch Service on Elastic Cloud)&lt;/li&gt;
&lt;li&gt;Filebeat agent&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Filebeat Agent:
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Installing the Filebeat Agent
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.11.1-amd64.deb&lt;br&gt;
sudo dpkg -i filebeat-7.11.1-amd64.deb&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Configure
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Modify &lt;em&gt;/etc/filebeat/filebeat.yml&lt;/em&gt; to set the connection information for Elastic Cloud:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;cloud.id: &amp;lt;Get your cloud_id from the Elastic Cloud&amp;gt;&lt;br&gt;
cloud.auth: "elastic:&amp;lt;password&amp;gt;"&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enable S3 to send a notification to SQS when a new file is placed in bucket. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Steps to Enable S3 Event notification to SQS are &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/enable-event-notifications.html" rel="noopener noreferrer"&gt;documented here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Enable the AWS module
&lt;/h4&gt;

&lt;p&gt;From the configuration of Filebeat, one will need to explicitly enable the AWS module. The following command enables the AWS configuration in the &lt;em&gt;modules.d&lt;/em&gt; directory on MacOS and Linux systems:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo filebeat modules enable aws&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Set AWS credentials in the config file
&lt;/h4&gt;

&lt;p&gt;(Skip, if this has already been done during metricbeat setup) &lt;br&gt;
To configure AWS credentials, users can put the credentials into the Filebeat module configuration or use environment variables to pass them.  &lt;a href="https://docs.aws.amazon.com/ses/latest/DeveloperGuide/create-shared-credentials-file.html" rel="noopener noreferrer"&gt;Create a shared credential&lt;/a&gt; by following these steps. File will be created under the below location.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;For Windows:
C:\Users\&amp;lt;yourusername&amp;gt;\.aws\credentials

For  Linux, MacOS, or Unix:
~/.aws/credentials
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Optional) Users can specify the profile name using parameter credential_profile_name in aws module config. For more details on AWS credentials types and supported formats, please see &lt;a href="https://www.elastic.co/guide/en/beats/metricbeat/7.4/metricbeat-module-aws.html#aws-credentials-config" rel="noopener noreferrer"&gt;AWS credentials configuration&lt;/a&gt; for more detail.&lt;/p&gt;

&lt;h4&gt;
  
  
  Sample AWS Configuration for filebeat:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- module: aws
  cloudtrail:
    enabled: true
    var.queue_url: https://sqs.myregion.amazonaws.com/123456/myqueue
  cloudwatch:
    enabled: true
    var.queue_url: https://sqs.myregion.amazonaws.com/123456/myqueue
  ec2:
    enabled: true
    var.queue_url: https://sqs.myregion.amazonaws.com/123456/myqueue
  elb:
    enabled: true
    var.queue_url: https://sqs.myregion.amazonaws.com/123456/myqueue
  s3access:
    enabled: true
    var.queue_url: https://sqs.myregion.amazonaws.com/123456/myqueue
  vpcflow:
    enabled: true
    var.queue_url: https://sqs.myregion.amazonaws.com/123456/myqueue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;var.queue_url: (Required) AWS SQS queue url. &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Start Filebeat:
&lt;/h4&gt;

&lt;p&gt;The setup command loads the Kibana dashboards. If the dashboards are already set up, omit this command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo filebeat setup&lt;br&gt;
sudo service filebeat start&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Module Status:
&lt;/h4&gt;

&lt;p&gt;Filebeat comes with pre-built Kibana dashboards and UIs for visualizing log data. The dashboards would have been loaded earlier when the setup command was run. &lt;/p&gt;

&lt;p&gt;In the Kibana side navigation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click Discover, to see Filebeat data. Also make sure the predefined filebeat-* index pattern is selected.&lt;/li&gt;
&lt;li&gt;Click Dashboard, then search for "AWS Filebeat*", select the dashboard that you want to open.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>elasticsearch</category>
      <category>infrastructureautomation</category>
      <category>devops</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
