<?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: Ritesh Yadav</title>
    <description>The latest articles on DEV Community by Ritesh Yadav (@darkart108).</description>
    <link>https://dev.to/darkart108</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%2F337574%2F09159aa4-dbe8-4271-b59b-af6e978af5fb.jpg</url>
      <title>DEV Community: Ritesh Yadav</title>
      <link>https://dev.to/darkart108</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/darkart108"/>
    <language>en</language>
    <item>
      <title>Prometheus Made Easy</title>
      <dc:creator>Ritesh Yadav</dc:creator>
      <pubDate>Tue, 24 Nov 2020 17:46:54 +0000</pubDate>
      <link>https://dev.to/darkart108/prometheus-made-easy-571o</link>
      <guid>https://dev.to/darkart108/prometheus-made-easy-571o</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%2Fi%2Fmym467zb9a90kbx6xpsz.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%2Fi%2Fmym467zb9a90kbx6xpsz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is High Scale Application Monitoring?
&lt;/h2&gt;

&lt;p&gt;Let's assume we are working on an Application for months and the Application is getting complex day by day and are needed to be managed on a large scale in order to ensure that the infrastructure of your application stays operational. To ensure that your application is running well, You have to solve some Questions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is your Application is Up or Down?&lt;/li&gt;
&lt;li&gt;Are the resources are utilized well enough or not?&lt;/li&gt;
&lt;li&gt;What is the growth of resources needed after each Release?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, It is important to have a centralized view of a Sys to Pinpoint a source or problem.&lt;/p&gt;

&lt;p&gt;Typically you have, let's say multiple servers running containers on them. As the user input grows, it makes sense to distribute these services individually, getting us to a microservice infrastructure. Now, if services want to connect with each other, there should be some sort of a way for them to be interconnected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Not Debug Our Code? Why Monitoring?
&lt;/h2&gt;

&lt;p&gt;Let's say you have completed your thousand dollar Project after a day and night hard work, and another day when you woke up you have&lt;br&gt;
seen that your application stopped working, some of the build components of your application or microservices got failed/stopped running and these errors are too much that you are not able to find which component or services are failing or caused the failure. Or let's say your application is responding very slowly as all the traffic is being directed to just limited servers. That is a place no one would want to be in. As debugging this manually is going to be very time-consuming, So at this place, monitoring and alerts are places an important role.&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%2Fi%2Fwhqq7xc7xwuqk4rpzuqt.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%2Fi%2Fwhqq7xc7xwuqk4rpzuqt.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is the Solution?
&lt;/h2&gt;

&lt;p&gt;So how do you ensure that your application is being maintained properly, and is running with no downtime? We need some sort of an automated tool that constantly monitors our application and alerts us when something goes wrong (or right depending on the use case). Now, in our previous example, we would be notified when a service causes failure, and hence we can prevent our application from going down.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Prometheus?
&lt;/h2&gt;

&lt;p&gt;Prometheus is a free software application used for &lt;strong&gt;event monitoring and alerting&lt;/strong&gt;. It records real-time metrics in a time series database (allowing for high dimensionality) built using an HTTP pull model, with flexible queries and real-time alerting. Prometheus is built by SoundCloud and currently, it is a F/OSS incubated project under Cloud Native Cloud Foundation(CNCF).&lt;/p&gt;
&lt;h2&gt;
  
  
  Prometheus Architecture and Metrics
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Prometheus Terminologies
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Target&lt;/strong&gt; - It is What the Prometheus Monitors, it can be your microservice, application, or docker containers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Metric&lt;/strong&gt; - For our target, we would like to monitor some particular things. Let's say we have some docker container(Target) running and we want to monitor the CONTAINER_MEMORY_USAGE(Metric) for every running container.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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%2Fi%2Fvucc4i9km6l1c60gq2bl.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%2Fi%2Fvucc4i9km6l1c60gq2bl.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above, we see some important components of Prometheus Server. It consists of three parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time Series Database(TSDB)&lt;/strong&gt; - It stores the metric data. It also ingest it (append-only), compacts, and allows querying efficiently. Time series data are simply measurements or events that are tracked, monitored, downsampled, and aggregated over time. This could be server metrics, application performance monitoring.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scrape Engine&lt;/strong&gt; - Pulls the metrics (description above) from our target resources and sends them to the TSDB. (Prometheus pulls are called scrapes).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Server&lt;/strong&gt; - Used to make queries for the data stored in TSDB using a very powerful query language using PromQL.This is also used to display the metric in a dashboard using &lt;strong&gt;Grafana or Prometheus UI&lt;/strong&gt;.&lt;/p&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7x4c61dclkys7a9dv0lr.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%2Fi%2F7x4c61dclkys7a9dv0lr.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;A More Detailed Querying Structure:&lt;/em&gt;&lt;/strong&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcf1mjcsc4pba12n2ursz.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%2Fi%2Fcf1mjcsc4pba12n2ursz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  More About Metrics
&lt;/h3&gt;

&lt;p&gt;The metrics are defined with two types of major attributes &lt;code&gt;TYPE&lt;/code&gt; and &lt;code&gt;HELP&lt;/code&gt; to increase logs readability.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;HELP&lt;/code&gt;: It shows the details about the metric with a description.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;TYPE&lt;/code&gt;: Prometheus offers 4 core metric types so that we can classify different types of metrics easily and we can also create custom tags using these existing metric types also for a specific use.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Counter&lt;/strong&gt;: A counter is a cumulative metric that represents a single monotonically increasing counter whose value can only increase or be reset to zero on restart. For example, you can use a counter to represent the number of requests served, tasks completed, or errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gauge&lt;/strong&gt;: A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.For eg: CPU_MEMORY_USAGE.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Histogram&lt;/strong&gt;: A histogram samples observations (usual things like request durations or response sizes) and counts them in configurable buckets. It also provides a sum of all observed values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Summary&lt;/strong&gt;: Similar to a histogram, a summary samples observations (usually things like request durations and response sizes). While it also provides a total count of observations and a sum of all observed values, it calculates configurable quantiles over a sliding time window.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Understanding Prometheus Backend
&lt;/h2&gt;
&lt;h3&gt;
  
  
  How does it Pull the data from Targets?
&lt;/h3&gt;

&lt;p&gt;The Data Retrieval Worker pulls the data from the HTTP endpoints of the targets on path &lt;code&gt;/metrics&lt;/code&gt;. Here we notice 2 things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The endpoint should be exposed to the &lt;code&gt;/metric&lt;/code&gt; path.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The data provided by the endpoint should be in the correct format that Prometheus understands&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%2Fi%2F30khl29sx1k3b7hgn6lz.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%2Fi%2F30khl29sx1k3b7hgn6lz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Q.&lt;/strong&gt; How do we make sure that the target services expose /metric &amp;amp; that data is in correct format?&lt;br&gt;
&lt;strong&gt;A.&lt;/strong&gt; Some of them expose the endpoint by default. Ones that do not, need a component to do so. This component is known as an &lt;strong&gt;Exporter&lt;/strong&gt;. An Exporter does the following:&lt;/p&gt;

&lt;p&gt;1.Fetch data from the target&lt;/p&gt;

&lt;p&gt;2.Convert data into a format that Prometheus understands&lt;/p&gt;

&lt;p&gt;3.Expose the &lt;code&gt;/metrics&lt;/code&gt; endpoint (This can now be retrieved by the Data Retrieval Worker) For different types of services, like APIs, Databases, Storage, HTTP, etc, Prometheus has a &lt;a href="https://prometheus.io/docs/instrumenting/exporters/" rel="noopener noreferrer"&gt;Exporters&lt;/a&gt; you can use.&lt;/p&gt;
&lt;h3&gt;
  
  
  How you can Monitor your own Application?
&lt;/h3&gt;

&lt;p&gt;Let's say you have written your application in python and you want to expose it to the HTTP endpoint &lt;code&gt;/metric&lt;/code&gt; on your application instance so you need some client libraries or you can say an exporter which then can be used to send data to the data retrieval worker. In the official documentation of &lt;a href="https://prometheus.io/docs/instrumenting/clientlibs/" rel="noopener noreferrer"&gt;Prometheus Clients&lt;/a&gt;, you can get the list of all clients. &lt;/p&gt;
&lt;h2&gt;
  
  
  PUSH VS PULL Model for Metric Collection
&lt;/h2&gt;

&lt;p&gt;Metrics are one of the &lt;strong&gt;“go-to” standards for any monitoring&lt;/strong&gt; system of which there are a variety of different types. At its core, a metric is essentially a measurement of a property of a portion of an application or system. Metrics make an observation by keeping track of the state of an object. These observations are some value or a series of related values combined with a timestamp that describes the observations, the output of which is commonly called &lt;strong&gt;time-series data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Prometheus is a pull-based system that pulls data from configured sources at regular intervals.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As mentioned above, Prometheus uses a &lt;strong&gt;pull mechanism&lt;/strong&gt; to get data from targets. But mostly, other monitoring systems use a &lt;strong&gt;push mechanism&lt;/strong&gt;. How is this different and what makes Prometheus so special?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q.&lt;/strong&gt; What do you mean by push mechanism?&lt;br&gt;
&lt;strong&gt;A.&lt;/strong&gt; Instead of the server of the monitoring tool making requests to get the data, the servers of the application push the data to a database instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q.&lt;/strong&gt; Why is Prometheus better?&lt;br&gt;
&lt;strong&gt;A.&lt;/strong&gt; You can just get the data from the endpoint of the target, by multiple Prometheus instances. Also note that this way Prometheus can also monitor whether an application is responsive or not, rather than waiting for the target to push data.&lt;br&gt;
(Check out the &lt;a href="https://prometheus.io/docs/introduction/comparison/" rel="noopener noreferrer"&gt;official comparison documentation&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; But what happens if the targets don't give us enough time to make a pull request? For this, Prometheus uses &lt;strong&gt;Pushgateway&lt;/strong&gt;. Using this, these services can now push their data to the Data Retrieval Worker instead of it pulling data like it usually does. Using this, you get the best out of both ways!&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%2Fi%2Fjuukzrb1v29tmc19jo5j.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%2Fi%2Fjuukzrb1v29tmc19jo5j.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to Use Prometheus?
&lt;/h2&gt;

&lt;p&gt;Till now we have got to know &lt;strong&gt;What is Prometheus?&lt;/strong&gt; and &lt;strong&gt;How the Prometheus Architecture?&lt;/strong&gt; look like, Now let's see &lt;strong&gt;&lt;em&gt;How we can set up Prometheus Locally?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q.&lt;/strong&gt; When you define what targets you want to collect data from in the file, how does Prometheus find these targets&lt;br&gt;
&lt;strong&gt;A.&lt;/strong&gt; Using the Service Discovery. It also discovers services automatically based on the application running.  &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%2Fi%2Fa4rozll9gkrt3bbaknys.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%2Fi%2Fa4rozll9gkrt3bbaknys.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Prometheus.yml File
&lt;/h2&gt;

&lt;p&gt;The most important file in Prometheus is the &lt;strong&gt;config(yml)&lt;/strong&gt; file, which is Prometheus.yml here we define all set of instruction that should build the Prometheus Server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;global:
  # How frequently to scrape targets by default.
  [ scrape_interval: &amp;lt;duration&amp;gt; | default = 1m ]

  # How long until a scrape request times out.
  [ scrape_timeout: &amp;lt;duration&amp;gt; | default = 10s ]

  # How frequently to evaluate rules.
  [ evaluation_interval: &amp;lt;duration&amp;gt; | default = 1m ]

  # The labels to add to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    [ &amp;lt;labelname&amp;gt;: &amp;lt;labelvalue&amp;gt; ... ]

  # File to which PromQL queries are logged.
  # Reloading the configuration will reopen the file.
  [ query_log_file: &amp;lt;string&amp;gt; ]

# Rule files specify a list of globs. Rules and alerts are read from
# all matching files.
rule_files:
  [ - &amp;lt;filepath_glob&amp;gt; ... ]

# A list of scrape configurations.
scrape_configs:
  [ - &amp;lt;scrape_config&amp;gt; ... ]

# Alerting specifies settings related to the Alertmanager.
alerting:
  alert_relabel_configs:
    [ - &amp;lt;relabel_config&amp;gt; ... ]
  alertmanagers:
    [ - &amp;lt;alertmanager_config&amp;gt; ... ]

# Settings related to the remote write feature.
remote_write:
  [ - &amp;lt;remote_write&amp;gt; ... ]

# Settings related to the remote read feature.
remote_read:
  [ - &amp;lt;remote_read&amp;gt; ... ] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Check the &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt; for configuration)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;A More Simplified Prometheus.yml!!!&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;global:
  scrape_interval:     15s
  evaluation_interval: 15s

rule_files:
  # - "first.rules"
  # - "second.rules"

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;global&lt;/code&gt; - &lt;code&gt;scrape_interval&lt;/code&gt; defines how often Prometheus is going to collect data from the targets mentioned in the file. This can of course be overridden.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;rule_files&lt;/code&gt; - This allows us to set rules for metrics &amp;amp; alerts. These files can be reloaded at runtime by sending &lt;code&gt;SIGHUP&lt;/code&gt; to the Prometheus process. The &lt;code&gt;evaluation_interval&lt;/code&gt; defines how often these rules are evaluated. &lt;strong&gt;&lt;em&gt;Prometheus supports 2 types of such rules:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Recording Rules&lt;/strong&gt; - If you are performing some frequent operations, they can be precomputed and saved in as a new set of time series. This makes the monitoring system a bit faster.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Alerting Rules&lt;/strong&gt; - This lets you define conditions to send alerts to external services, for example, when a particular condition is triggered.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;code&gt;scrape_configs&lt;/code&gt; - Here we define the services/targets that we need Prometheus to monitor. In this example file, the &lt;code&gt;job_name&lt;/code&gt; is &lt;code&gt;prometheus&lt;/code&gt;. Meaning that it is monitoring the target as the Prometheus server itself. In short, it will get data from the &lt;code&gt;/metrics&lt;/code&gt; endpoint exposed by the Prometheus server. Here, the target by default is &lt;code&gt;localhost:9090&lt;/code&gt; which is where Prometheus will expect the metrics to be, at &lt;code&gt;/metrics&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Alerting in Prometheus
&lt;/h2&gt;

&lt;p&gt;Prometheus has an &lt;strong&gt;AlertManager&lt;/strong&gt; that is used to set Alerts and send them using Emails, webhooks, Slack, and other methods. As mentioned above, the Prometheus server uses the &lt;strong&gt;Alerting Rules&lt;/strong&gt; to send alerts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where is the data stored?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The data collected by the &lt;strong&gt;Data Retrieval Worker&lt;/strong&gt; is stored in a &lt;strong&gt;TSDB&lt;/strong&gt; and queried using &lt;strong&gt;PromQL&lt;/strong&gt; query language. You can use a Web UI to request data from the Prometheus server via PromQL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;A combined Prometheus Architecture&lt;/em&gt;&lt;/strong&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%2Fi%2Fqty5lzwiasm0ejgvkdv1.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%2Fi%2Fqty5lzwiasm0ejgvkdv1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Running Prometheus Using Docker
&lt;/h2&gt;

&lt;p&gt;For the demonstration purposes we will use Docker to make things really easy and reproducible anywhere. Here is a simple Dockerfile which sets up the stage for us.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It starts off with &lt;strong&gt;Ubuntu 18.04 (bionic) official image&lt;/strong&gt;&lt;br&gt;
Installs some of the tools we will be using like &lt;strong&gt;wget&lt;/strong&gt;, &lt;strong&gt;screen&lt;/strong&gt; and &lt;strong&gt;vim&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It downloads the latest binary releases for &lt;strong&gt;Prometheus&lt;/strong&gt;, &lt;strong&gt;node_exporter&lt;/strong&gt;, and &lt;strong&gt;alert manager&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It also downloads &lt;strong&gt;Grafana&lt;/strong&gt; which will be used later for Visualization&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Exposes the default ports from the respective services&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Dockerfile&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM ubuntu:bionic
LABEL Name="Ritesh" Mail="daydreamingguy941@gmail.com"

RUN  apt-get update \
  &amp;amp;&amp;amp; apt-get install -y wget \
  &amp;amp;&amp;amp; apt-get install -y screen \
  &amp;amp;&amp;amp; apt-get install -y vim

WORKDIR /root
RUN wget -nv https://github.com/prometheus/prometheus/releases/download/v2.22.2/prometheus-2.22.2.linux-amd64.tar.gz
RUN wget -nv https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
RUN wget -nv https://github.com/prometheus/alertmanager/releases/download/v0.21.0/alertmanager-0.21.0.linux-amd64.tar.gz
RUN wget -nv https://dl.grafana.com/oss/release/grafana-7.3.3.linux-amd64.tar.gz

# node_exporter expose port
EXPOSE 9100

# prometheus server expose port
EXPOSE 9090

# grafana
EXPOSE 3000

# alertmanager
EXPOSE 9093

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

&lt;/div&gt;



&lt;p&gt;Now, we will create a simple &lt;strong&gt;docker-compose&lt;/strong&gt; file to prepare our &lt;strong&gt;docker image&lt;/strong&gt; to run, only thing it does is, it gives us a handy name to work with which will &lt;strong&gt;expose multiple ports&lt;/strong&gt; to the host for us. With this, we can access them from the host machine. &lt;strong&gt;&lt;em&gt;I generally prefer docker-compose a lot than writing long docker run commands with options.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;docker-compose.yml&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3'
services:
  prometheus_demo:
    build: .
    ports:
      - "9100:9100"
      - "9090:9090"
      - "3000:3000"
      - "9093:9093"

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

&lt;/div&gt;



&lt;p&gt;Once these two files are there, you can go to the folder containing them and run the service from &lt;code&gt;docker-compose&lt;/code&gt; in interactive mode. Note that &lt;code&gt;--service-ports&lt;/code&gt; is a very important option, it allows us to do the port binding right (which is disabled by default).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose run --service-ports prometheus_demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you run the command, you will see a bunch of outputs corresponding to the build steps in Dockerfile.&lt;/p&gt;

&lt;p&gt;After all the steps are done you will be thrown into an interactive shell inside a docker container. If you want to check the no of the running container with a &lt;code&gt;prometheus_demo&lt;/code&gt; image name you can use &lt;code&gt;docker-compose ps&lt;/code&gt; or &lt;code&gt;docker ps -a&lt;/code&gt; you will get the single container running multiple services like Grafana, Prometheus, node_exporter, and alert manager on a default port or ports mentioned in Dockerfile.&lt;/p&gt;

&lt;p&gt;Now let's extract all the Packages which we have downloaded using Dockerfile.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tar xvf prometheus-2.22.2.linux-amd64.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tar xvf node_exporter-0.18.1.linux-amd64.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tar xvf grafana-7.3.3.linux-amd64.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, you can extract other packages like alertmanager.&lt;/p&gt;

&lt;p&gt;The next step is to move to the package directory. I am showing with Prometheus you can follow these steps with other packages also.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MOVE TO DIREC&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd prometheus-2.22.2.linux-amd64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can run the Prometheus file and make your Prometheus Monitoring System running.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RUN&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;Now you can see a msg in the logs that &lt;code&gt;Server is Up and ready to receive web request&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Your Server is running it on &lt;code&gt;localhost:9090&lt;/code&gt;, you'll get the following &lt;strong&gt;Prometheus UI Dashboard&lt;/strong&gt; that you can now configure:&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%2Fi%2Fex6fl2g5y7ifupfvfsyy.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%2Fi%2Fex6fl2g5y7ifupfvfsyy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above &lt;strong&gt;Prometheus UI Dashboard&lt;/strong&gt; we're monitoring the Docker Containers.&lt;/p&gt;

&lt;p&gt;Now you can connect your Prometheus Server to &lt;strong&gt;node_exporter&lt;/strong&gt;(It is an exporter used to get a Linux server health by exposing &lt;code&gt;/metric&lt;/code&gt; endpoint to Data Retrieval Worker) by mentioning the other job_name in your &lt;strong&gt;prometheus.yml&lt;/strong&gt; file which we have discussed in Prometheus.yml file section,node_exporter will fetch you the metrics like &lt;code&gt;MEMORY_USAGE_INFO&lt;/code&gt; or &lt;code&gt;CPU_LOAD&lt;/code&gt; in your Prometheus dashboard and you can also see the node_exporter &lt;code&gt;/metric&lt;/code&gt; HTTP endpoint on &lt;code&gt;localhost:9100&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Connect To Grafana
&lt;/h3&gt;

&lt;p&gt;You can set up Grafana by following the below steps&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd grafana-7.3.3.linux-amd64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./grafana-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will find your Grafana Server Running at &lt;code&gt;localhost:3000&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now you can fetch the metrics and see the beautiful visualization in Gafana Dashboard.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Monitor Prometheus Health&lt;/li&gt;
&lt;li&gt;Monitor HOST Machine Health&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe0aic6vksn2ldxgtntfi.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%2Fi%2Fe0aic6vksn2ldxgtntfi.PNG" alt="Alt Text"&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fruz9p2y136yig07p1b4k.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%2Fi%2Fruz9p2y136yig07p1b4k.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thanks for Reading🥰!!
&lt;/h2&gt;

&lt;p&gt;In the next blog, we will Discuss more &lt;strong&gt;Prometheus Advanced Visualization with Grafana&lt;/strong&gt; and also monitors &lt;strong&gt;K8's&lt;/strong&gt; using Prometheus!&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect with Me🛸
&lt;/h2&gt;

&lt;p&gt;🚩 &lt;a href="https://www.linkedin.com/in/ritesh-yadav2011/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;
🚩 Shoot me a &lt;a href="//daydreamingguy941@gmail.com"&gt;Mail&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources📚
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://youtu.be/h4Sl21AKiDg" rel="noopener noreferrer"&gt;https://youtu.be/h4Sl21AKiDg&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/9DqOMZrc4PA" rel="noopener noreferrer"&gt;https://youtu.be/9DqOMZrc4PA&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://prometheus.io/docs/guides/node-exporter/" rel="noopener noreferrer"&gt;https://prometheus.io/docs/guides/node-exporter/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>monitoring</category>
      <category>devops</category>
      <category>opensource</category>
      <category>go</category>
    </item>
  </channel>
</rss>
