avatarSaverio Mazza

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1432

Abstract

span>

<span class="hljs-attr">scrape_configs:</span> <span class="hljs-bullet">-</span> <span class="hljs-attr">job_name:</span> <span class="hljs-string">'prometheus'</span> <span class="hljs-attr">static_configs:</span> <span class="hljs-bullet">-</span> <span class="hljs-attr">targets:</span> [<span class="hljs-string">'localhost:9090'</span>]</pre></div><p id="3dda">In summary, this configuration tells Prometheus to scrape metrics from itself every 15 seconds. This is often useful for getting started and testing, but in a production environment, you’d replace or augment this with configurations that scrape your actual services and applications.</p><p id="427f">Save the file and exit the text editor. You can now run Prometheus with the following command:</p><div id="a757"><pre>prometheus --config.file=/etc/prometheus/prometheus.yml</pre></div><p id="1117">You should be able to access the Prometheus UI by navigating to <a href="http://localhost:9090."><code>http://localhost:9</code>090.</a></p><figure id="621f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*KPGned80oZimTpyUWx8V8Q.png"><figcaption></figcaption></figure><h1 id="ed60">Install Grafana</h1><p id="7146">Add APT Repository and Install Grafana</p><div id="ff53"><pre>sudo apt-get install -y software-properties-common sudo add-apt-repository <span class="hljs-string">"deb https://packages.grafana.com/oss/deb stable main"

Options

</span> wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - sudo apt-get update sudo apt-get install grafana</pre></div><p id="df8a">Enable and Start Grafana Service</p><div id="7bb2"><pre>sudo systemctl <span class="hljs-built_in">enable</span> grafana-server sudo systemctl start grafana-server</pre></div><p id="fade">Now Grafana should be running, and you can access the UI by navigating to <code>http://localhost:3000</code>. The default login is <code>admin</code> for the username and <code>admin</code> for the password.</p><h1 id="a8d5">Configure Grafana to Use Prometheus</h1><p id="0be6">Add Data Source</p><ul><li>Log in to Grafana (<code>http://localhost:3000</code>).</li><li>Go to <code>Settings -&gt; Data Sources -&gt; Add data source</code>.</li><li>Choose <code>Prometheus</code>.</li><li>Set the URL to <a href="http://localhost:9090."><code>http://localhost:9</code>090.</a></li><li>Click <code>Save &amp; Test</code>.</li></ul><p id="5dbb">You now have Prometheus and Grafana installed and configured. Prometheus is scraping metrics, and Grafana is ready to visualize them. You can start creating dashboards in Grafana to visualize your Prometheus metrics.</p><p id="be41"><a href="https://substack.com/profile/29984465-saverio-mazza?utm_source=profile-page"><i>Subscribe to my newsletter</i></a><i> to get access to all the content I’ll be publishing in the future.</i></p></article></body>

Setting Up Prometheus and Grafana

First, download the latest Prometheus version from the official website. You can do this via wget or curl. After downloading, unpack the tarball.

# Download and Unpack Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz
tar xvfz prometheus-2.30.3.linux-amd64.tar.gz

For easier access, you can move the Prometheus and Promtool binaries to /usr/local/bin/.

sudo mv prometheus-2.30.3.linux-amd64/prometheus /usr/local/bin/
sudo mv prometheus-2.30.3.linux-amd64/promtool /usr/local/bin/

Create a prometheus.yml file. You can place this in a directory of your choice; for this example, let's use /etc/prometheus/

sudo mkdir /etc/prometheus
sudo nano /etc/prometheus/prometheus.yml

Add the following content to prometheus.yml. This is a simple configuration to scrape metrics from itself:

global:
  scrape_interval: 15s

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

In summary, this configuration tells Prometheus to scrape metrics from itself every 15 seconds. This is often useful for getting started and testing, but in a production environment, you’d replace or augment this with configurations that scrape your actual services and applications.

Save the file and exit the text editor. You can now run Prometheus with the following command:

prometheus --config.file=/etc/prometheus/prometheus.yml

You should be able to access the Prometheus UI by navigating to http://localhost:9090.

Install Grafana

Add APT Repository and Install Grafana

sudo apt-get install -y software-properties-common
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install grafana

Enable and Start Grafana Service

sudo systemctl enable grafana-server
sudo systemctl start grafana-server

Now Grafana should be running, and you can access the UI by navigating to http://localhost:3000. The default login is admin for the username and admin for the password.

Configure Grafana to Use Prometheus

Add Data Source

  • Log in to Grafana (http://localhost:3000).
  • Go to Settings -> Data Sources -> Add data source.
  • Choose Prometheus.
  • Set the URL to http://localhost:9090.
  • Click Save & Test.

You now have Prometheus and Grafana installed and configured. Prometheus is scraping metrics, and Grafana is ready to visualize them. You can start creating dashboards in Grafana to visualize your Prometheus metrics.

Subscribe to my newsletter to get access to all the content I’ll be publishing in the future.

Prometheus
Grafana
Data Visualization
DevOps
System Admin
Recommended from ReadMedium