<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Postgres Exporter on Grafana Labs</title><link>https://grafana.com/oss/prometheus/exporters/postgres-exporter/</link><description>Recent content in Postgres Exporter on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/oss/prometheus/exporters/postgres-exporter/index.xml" rel="self" type="application/rss+xml"/><item><title>Alerting rules</title><link>https://grafana.com</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://grafana.com</guid><description>&lt;p>This quickstart includes the following alerting rules:&lt;/p>
&lt;ul>
&lt;li>&lt;code>PostgreSQLMaxConnectionsReached&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>Postgres ran out of available connections&lt;/p>
&lt;ul>
&lt;li>&lt;code>PostgreSQLHighConnections&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>Postgres is exceeding 80% of the currently configured maximum Postgres connection limit&lt;/p>
&lt;ul>
&lt;li>&lt;code>PostgreSQLDown&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>Postgres is not processing queries&lt;/p>
&lt;ul>
&lt;li>&lt;code>PostgreSQLSlowQueries&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>Postgres has high number of slow queries&lt;/p>
&lt;ul>
&lt;li>&lt;code>PostgreSQLQPS&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>Postgres has high number of queries per second&lt;/p>
&lt;ul>
&lt;li>&lt;code>PostgreSQLCacheHitRatio&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>Postgres is low on cache hit rate&lt;/p>
&lt;a class="btn btn--primary br-5 mb-1" href="assets/alerting_rules.yaml" rel="noopener noreferrer">Download the following alerting rules YAML file&lt;/a>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">YAML&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-yaml">groups:
- name: PostgreSQL
rules:
- alert: PostgreSQLMaxConnectionsReached
expr: sum(pg_stat_activity_count) by (instance) &amp;gt;= sum(pg_settings_max_connections) by (instance) - sum(pg_settings_superuser_reserved_connections) by (instance)
for: 1m
labels:
severity: email
annotations:
summary: &amp;#34;{{ $labels.instance }} has maxed out Postgres connections.&amp;#34;
description: &amp;#34;{{ $labels.instance }} is exceeding the currently configured maximum Postgres connection limit (current value: {{ $value }}s). Services may be degraded - please take immediate action (you probably need to increase max_connections in the Docker image and re-deploy.&amp;#34;
- alert: PostgreSQLHighConnections
expr: sum(pg_stat_activity_count) by (instance) &amp;gt; (sum(pg_settings_max_connections) by (instance) - sum(pg_settings_superuser_reserved_connections) by (instance)) * 0.8
for: 10m
labels:
severity: email
annotations:
summary: &amp;#34;{{ $labels.instance }} is over 80% of max Postgres connections.&amp;#34;
description: &amp;#34;{{ $labels.instance }} is exceeding 80% of the currently configured maximum Postgres connection limit (current value: {{ $value }}s). Please check utilization graphs and confirm if this is normal service growth, abuse or an otherwise temporary condition or if new resources need to be provisioned (or the limits increased, which is mostly likely).&amp;#34;
- alert: PostgreSQLDown
expr: pg_up != 1
for: 1m
labels:
severity: email
annotations:
summary: &amp;#34;PostgreSQL is not processing queries: {{ $labels.instance }}&amp;#34;
description: &amp;#34;{{ $labels.instance }} is rejecting query requests from the exporter, and thus probably not allowing DNS requests to work either. User services should not be effected provided at least 1 node is still alive.&amp;#34;
- alert: PostgreSQLSlowQueries
expr: avg(rate(pg_stat_activity_max_tx_duration{datname!~&amp;#34;template.*&amp;#34;}[2m])) by (datname) &amp;gt; 2 * 60
for: 2m
labels:
severity: email
annotations:
summary: &amp;#34;PostgreSQL high number of slow on {{ $labels.cluster }} for database {{ $labels.datname }} &amp;#34;
description: &amp;#34;PostgreSQL high number of slow queries {{ $labels.cluster }} for database {{ $labels.datname }} with a value of {{ $value }} &amp;#34;
- alert: PostgreSQLQPS
expr: avg(irate(pg_stat_database_xact_commit{datname!~&amp;#34;template.*&amp;#34;}[5m]) &amp;#43; irate(pg_stat_database_xact_rollback{datname!~&amp;#34;template.*&amp;#34;}[5m])) by (datname) &amp;gt; 10000
for: 5m
labels:
severity: email
annotations:
summary: &amp;#34;PostgreSQL high number of queries per second {{ $labels.cluster }} for database {{ $labels.datname }}&amp;#34;
description: &amp;#34;PostgreSQL high number of queries per second on {{ $labels.cluster }} for database {{ $labels.datname }} with a value of {{ $value }}&amp;#34;
- alert: PostgreSQLCacheHitRatio
expr: avg(rate(pg_stat_database_blks_hit{datname!~&amp;#34;template.*&amp;#34;}[5m]) / (rate(pg_stat_database_blks_hit{datname!~&amp;#34;template.*&amp;#34;}[5m]) &amp;#43; rate(pg_stat_database_blks_read{datname!~&amp;#34;template.*&amp;#34;}[5m]))) by (datname) &amp;lt; 0.98
for: 5m
labels:
severity: email
annotations:
summary: &amp;#34;PostgreSQL low cache hit rate on {{ $labels.cluster }} for database {{ $labels.datname }}&amp;#34;
description: &amp;#34;PostgreSQL low on cache hit rate on {{ $labels.cluster }} for database {{ $labels.datname }} with a value of {{ $value }}&amp;#34;&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>This alerting rule YAML file was generated using the Postgres Exporter &lt;a href="https://github.com/prometheus-community/postgres_exporter/tree/master/postgres_mixin" target="_blank" rel="noopener noreferrer">mixin&lt;/a>.&lt;/p></description></item><item><title>Cloud integration</title><link>https://grafana.com</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://grafana.com</guid><description>
&lt;div class="bg-solitude p-1 mb-1" style="">
&lt;p>Grafana Cloud comes with an ever-expanding set of integrations to quickly get an observability stack up and running in minutes. The Postgres Integration, built-in to the Grafana Cloud Agent, exposes and scrapes essential Postgres metrics and pushes them to Grafana Cloud. The agent will scrape metrics using an embedded Postgres Exporter, and Grafana Cloud will automatically provision tailored Grafana dashboards and alerts for visualizing and acting on this data.&lt;/p>
&lt;div>
&lt;a class="btn btn--primary br-5 " href="/signup/cloud/connect-account?pg=oss-prom-postgres-exporter-exporter&amp;amp;plcmt=body-txt-overview" rel="noopener noreferrer">Sign up for a free account to get started&lt;/a>
&lt;/div>
&lt;/div>
&lt;p>To learn more, check out the &lt;a href="/docs/grafana-cloud/integrations/">Grafana Cloud docs&lt;/a>.&lt;/p>
&lt;h4 id="how-it-works">How it works&lt;/h4>
&lt;p>Configuring, installing, connecting, and maintaining Prometheus monitoring components typically involves significant domain knowledge. It can take quite a while to go from setup to dashboard and alerts. As the creators of Grafana - and core contributors to Prometheus and Cortex - we build simple integrations to abstract some of this work away in order to quickly get started. How it works:&lt;/p>
&lt;ol>
&lt;li>Sign up (or log in) for a &lt;a href="/signup/cloud/connect-account?pg=oss-prom-postgres-exporter-exporter&amp;amp;plcmt=body-txt-overview">free Grafana Cloud account&lt;/a>.&lt;/li>
&lt;li>Select the target you’d like to observe (an ever-expanding catalogue).&lt;/li>
&lt;li>Run a one-line command to install the Grafana Agent. The agent embeds abnd preconfigures Exporters to expose default metrics, and pushes them to the Grafana Cloud metrics backend.&lt;/li>
&lt;li>Voila! You’ll see tailored Grafana dashboards and will benefit from sane alerting defaults.&lt;/li>
&lt;/ol>
&lt;p>Looking for a different Exporter or integration? Check out our &lt;a href="/docs/grafana-cloud/integrations/">growing library of integrations for popular components&lt;/a> like MySQL, Postgres, Redis, Memcached and more.&lt;/p></description></item><item><title>Dashboards</title><link>https://grafana.com</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://grafana.com</guid><description>&lt;h3 id="postgres-overview-dashboard">&lt;a href="/grafana/dashboards/14114">Postgres Overview Dashboard&lt;/a>&lt;/h3>
&lt;p>&lt;img
class="lazyload d-inline-block"
src="/api/dashboards/14114/images/10102/image"
alt="Postgres Overview Dashboard"/>&lt;/p>
&lt;p>This dashboard includes panels for the following metrics:&lt;/p>
&lt;ul>
&lt;li>Current QPS&lt;/li>
&lt;li>Fetched, Returned, Inserted, Updated, Deleted Rows&lt;/li>
&lt;li>Database Deadlocks and Conflicts&lt;/li>
&lt;li>Cache Hit Ratio&lt;/li>
&lt;li>Number of Active Connections&lt;/li>
&lt;li>Buffers&lt;/li>
&lt;/ul>
&lt;p>You can import the dashboard directly using the following dashboard ID: &lt;code>14114&lt;/code>.&lt;/p>
&lt;p>You can fetch the dashboard JSON &lt;a href="/api/dashboards/14114/revisions/1/download">&lt;strong>here&lt;/strong>&lt;/a>.&lt;/p>
&lt;p>This dashboard was generated using the Postgres Exporter &lt;a href="https://github.com/prometheus-community/postgres_exporter/tree/master/postgres_mixin" target="_blank" rel="noopener noreferrer">mixin&lt;/a>.&lt;/p></description></item><item><title>Install</title><link>https://grafana.com</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://grafana.com</guid><description>&lt;h2 id="postgres-exporter-quickstart">Postgres Exporter Quickstart&lt;/h2>
&lt;p>In this guide you&amp;rsquo;ll learn how to set up and configure the Postgres Exporter to collect Postgres metrics like queries per second (QPS), database deadlocks and conflicts, and expose them as Prometheus-style metrics. You&amp;rsquo;ll then configure &lt;a href="https://prometheus.io/" target="_blank" rel="noopener noreferrer">Prometheus&lt;/a> to scrape Postgres metrics and optionally ship them to Grafana Cloud. Finally, you&amp;rsquo;ll set up a preconfigured and curated set of Grafana &lt;a href="/grafana/dashboards">dashboards&lt;/a> and &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/" target="_blank" rel="noopener noreferrer">alerting rules&lt;/a>. At the end of this guide you&amp;rsquo;ll have dashboards that you can use to visualize your Postgres metrics, and set of preconfigured alerts.&lt;/p>
&lt;p>If you&amp;rsquo;re using &lt;a href="/products/cloud/">Grafana Cloud&lt;/a>, the &lt;a href="/docs/grafana-cloud/integrations/integration-postgres/">Postgres&lt;/a> Integration can help you get up and running quickly. The Postgres Integration embeds the Postgres Exporter into the &lt;a href="https://github.com/grafana/agent" target="_blank" rel="noopener noreferrer">Grafana Cloud Agent&lt;/a> and automatically provisions alerting rules and dashboards, so you don&amp;rsquo;t have to run through the steps in this guide. To learn how to set up Postgres Exporter using the Postgres Integration, please see &lt;a href="/docs/grafana-cloud/integrations/integration-postgres/">Postgres Integration&lt;/a> from the Grafana Cloud docs.&lt;/p>
&lt;h2 id="prerequisites">Prerequisites&lt;/h2>
&lt;p>Before you get started, you should have the following available to you:&lt;/p>
&lt;ul>
&lt;li>A machine compatible with a Postgres Exporter release. To see a list of available releases, please see &lt;a href="https://github.com/prometheus-community/postgres_exporter/releases" target="_blank" rel="noopener noreferrer">Releases&lt;/a>.&lt;/li>
&lt;li>Postgres running on your machine. To learn more about installing and running Postgres, please see the &lt;a href="https://www.postgresql.org/docs/13/tutorial-install.html" target="_blank" rel="noopener noreferrer">Postgres Installation Guide&lt;/a>.&lt;/li>
&lt;li>Prometheus running in your environment or directly on the machine. To learn how to install Prometheus, please see &lt;a href="https://prometheus.io/docs/prometheus/latest/installation/" target="_blank" rel="noopener noreferrer">Installation&lt;/a> from the Prometheus docs.&lt;/li>
&lt;li>Grafana running in your environment or directly on the machine. To learn how to install Grafana, please see &lt;a href="/docs/grafana/latest/installation/">Install Grafana&lt;/a> from the Grafana docs.&lt;/li>
&lt;li>(Optional) A Grafana Cloud account. Grafana Cloud hosts Grafana and a &lt;a href="/oss/mimir/">Mimir&lt;/a>-based Prometheus metrics endpoint. You will still need to scrape metrics, using either Prometheus installed in your environment, or the &lt;a href="https://github.com/grafana/agent" target="_blank" rel="noopener noreferrer">Grafana Cloud Agent&lt;/a>. To learn more about Grafana Cloud, please see &lt;a href="/products/cloud/">Grafana Cloud&lt;/a>.&lt;/li>
&lt;/ul>
&lt;h2 id="step-1-setting-up-postgres-exporter">Step 1: Setting up Postgres Exporter&lt;/h2>
&lt;p>In this step you&amp;rsquo;ll set up the Postgres exporter on your machine to collect and expose Postgres metrics in Prometheus format. This guide uses an Ubuntu 20.04 system with Postgres 13.2. Steps may vary slightly depending on your operating system and Postgres version.&lt;/p>
&lt;p>To begin, log in to your machine and download the relevant Postgres Exporter binary. This guide uses the &lt;code>linux-amd64&lt;/code> binary but you should choose the one corresponding to your system&amp;rsquo;s OS and architecture:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">wget https://github.com/prometheus-community/postgres_exporter/releases/download/v0.9.0/postgres_exporter-0.9.0.linux-amd64.tar.gz&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Replace &lt;code>v0.9.0&lt;/code> with the version you&amp;rsquo;d like to install. This guide may become stale so it&amp;rsquo;s best to check the Postgres Exporter &lt;a href="https://github.com/prometheus-community/postgres_exporter/releases" target="_blank" rel="noopener noreferrer">Releases&lt;/a> page for the latest stable version.&lt;/p>
&lt;p>Unzip the tarball and &lt;code>cd&lt;/code> into the directory:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">tar xvfz postgres_exporter-*.linux-amd64.tar.gz
cd postgres_exporter-*.linux-amd64&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>We&amp;rsquo;ll be running the Postgres exporter as the &lt;code>postgres&lt;/code> user to fetch database metrics. To fetch metrics as a non-superuser, you can follow the instructions from the &lt;a href="https://github.com/prometheus-community/postgres_exporter#running-as-non-superuser" target="_blank" rel="noopener noreferrer">Postgres Exporter Github Repo&lt;/a>.&lt;/p>
&lt;p>We need to inform the exporter how to reach the Postgres server. We do that by setting the following environment variable:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">export DATA_SOURCE_NAME=&amp;#39;postgresql://postgres:enter_password_here@postgres_hostname:5432/postgres?sslmode=disable&amp;#39;&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Be sure to replace &lt;code>postgres&lt;/code> with the user you will be using to fetch metrics from Postgres, &lt;code>enter_password_here&lt;/code> with the password for your user, and &lt;code>postgres_hostname&lt;/code> with the hostname of the Postgres instance (localhost if you’re on the same machine).&lt;/p>
&lt;p>Finally, run the exporter:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">./postgres_exporter
INFO[0000] Starting Server: :9187 source=&amp;#34;postgres_exporter.go:1850&amp;#34;&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>If you see the above output, you successfully ran Postgres Exporter.&lt;/p>
&lt;p>Postgres Exporter publishes Postgres metrics in Prometheus format on port &lt;code>9187&lt;/code>. You can test this using &lt;code>curl&lt;/code>. You will need to open a new SSH session or background the Postgres Exporter process to use &lt;code>curl&lt;/code>.&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">curl http://localhost:9187/metrics&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none"># TYPE pg_exporter_scrapes_total counter
pg_exporter_scrapes_total 1
# HELP pg_locks_count Number of locks
# TYPE pg_locks_count gauge
pg_locks_count{datname=&amp;#34;postgres&amp;#34;,mode=&amp;#34;accessexclusivelock&amp;#34;,server=&amp;#34;localhost:5432&amp;#34;} 0
pg_locks_count{datname=&amp;#34;postgres&amp;#34;,mode=&amp;#34;accesssharelock&amp;#34;,server=&amp;#34;localhost:5432&amp;#34;} 1
pg_locks_count{datname=&amp;#34;postgres&amp;#34;,mode=&amp;#34;exclusivelock&amp;#34;,server=&amp;#34;localhost:5432&amp;#34;} 0
pg_locks_count{datname=&amp;#34;postgres&amp;#34;,mode=&amp;#34;rowexclusivelock&amp;#34;,server=&amp;#34;localhost:5432&amp;#34;} 0
pg_locks_count{datname=&amp;#34;postgres&amp;#34;,mode=&amp;#34;rowsharelock&amp;#34;,server=&amp;#34;localhost:5432&amp;#34;} 0
pg_locks_count{datname=&amp;#34;postgres&amp;#34;,mode=&amp;#34;sharelock&amp;#34;,server=&amp;#34;localhost:5432&amp;#34;} 0
pg_locks_count{datname=&amp;#34;postgres&amp;#34;,mode=&amp;#34;sharerowexclusivelock&amp;#34;,server=&amp;#34;localhost:5432&amp;#34;} 0
pg_locks_count{datname=&amp;#34;postgres&amp;#34;,mode=&amp;#34;shareupdateexclusivelock&amp;#34;,server=&amp;#34;localhost:5432&amp;#34;} 0
pg_locks_count{datname=&amp;#34;postgres&amp;#34;,mode=&amp;#34;sireadlock&amp;#34;,server=&amp;#34;localhost:5432&amp;#34;} 0&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>If you see the above output, you&amp;rsquo;re ready to begin scraping Postgres metrics using Prometheus.&lt;/p>
&lt;p>To avoid running and managing Postgres Exporter from the command line, you can create a &lt;code>systemd&lt;/code> service. To learn how to do this, please see &lt;a href="/docs/grafana-cloud/agent/agent_as_service/">Creating a systemd service to manage the agent&lt;/a>. Replace the path to the agent binary with the path to Postgres Exporter.&lt;/p>
&lt;p>You can specify the &lt;code>--extend.query-path&lt;/code> flag to the path of your &lt;code>queries.yaml&lt;/code> file, where you can specify your custom queries. To learn more about these features, please see the &lt;a href="https://github.com/prometheus-community/postgres_exporter" target="_blank" rel="noopener noreferrer">Postgres Exporter GitHub repository&lt;/a>.&lt;/p>
&lt;h2 id="step-2-scraping-postgres-exporter-using-prometheus">Step 2: Scraping Postgres Exporter using Prometheus&lt;/h2>
&lt;p>Now that the Postgres Exporter is up and running on your machine, you can configure a Prometheus scrape job to collect and store Postgres Exporter metrics.&lt;/p>
&lt;p>Add the following scrape job config to the &lt;code>scrape_configs&lt;/code> section of your &lt;code>prometheus.yml&lt;/code> configuration file:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">- job_name: postgres
static_configs:
- targets: [&amp;#39;postgres_exporter_machine_IP_address:9187&amp;#39;]&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Replace &lt;code>postgres_exporter_machine_IP_address&lt;/code> with the IP address of the machine running Postgres Exporter. If you&amp;rsquo;re running Prometheus on the same machine, this will be &lt;code>localhost&lt;/code>. To learn more about configuring Prometheus, please see &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/" target="_blank" rel="noopener noreferrer">Configuration&lt;/a> from the Prometheus docs.&lt;/p>
&lt;p>If you don&amp;rsquo;t have a &lt;code>prometheus.yml&lt;/code> configuration file, create a simple one using your favorite text editor. Open your preferred text editor and paste in the following Prometheus configuration:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">global:
scrape_interval: 15s
scrape_configs:
- job_name: postgres
static_configs:
- targets: [&amp;#39;postgres_exporter_machine_IP_address:9187&amp;#39;]&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>This configuration tells Prometheus to scrape all jobs every 15 seconds. The only configured scrape job is called &lt;code>postgres&lt;/code> and defines a &lt;code>postgres_exporter_machine_IP_address:9187&lt;/code> target. By default, Prometheus will scrape the &lt;code>/metrics&lt;/code> endpoint using HTTP.&lt;/p>
&lt;p>Save and close the file. You can then run Prometheus with the file using the following command:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">./prometheus --config.file=./prometheus.yml&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;h3 id="shipping-metrics-to-grafana-cloud">Shipping metrics to Grafana Cloud&lt;/h3>
&lt;p>To ship Postgres Exporter metrics to Grafana Cloud from Prometheus, configure the &lt;code>remote_write&lt;/code> parameter in your &lt;code>prometheus.yml&lt;/code> configuration file. To learn more, please see &lt;a href="/docs/grafana-cloud/metrics/prometheus/">Metrics — Prometheus&lt;/a> from the Grafana Cloud docs. To learn more about the &lt;code>remote_write&lt;/code> parameter, please see &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write" target="_blank" rel="noopener noreferrer">&lt;code>remote_write&lt;/code>&lt;/a> from the Prometheus docs.&lt;/p>
&lt;h2 id="step-3-configuring-dashboards">Step 3: Configuring dashboards&lt;/h2>
&lt;p>This quickstart includes one dashboard:&lt;/p>
&lt;ul>
&lt;li>Postgres Overview&lt;/li>
&lt;/ul>
&lt;p>To learn how to import these dashboards into Grafana, please see &lt;a href="/docs/grafana/latest/dashboards/export-import/#importing-a-dashboard">Importing a dashboard&lt;/a> from the Grafana docs.&lt;/p>
&lt;p>You can fetch the dashboards &lt;a href="?tab=dashboards">here&lt;/a>.&lt;/p>
&lt;h2 id="step-4-configuring-alerts">Step 4: Configuring alerts&lt;/h2>
&lt;p>With Prometheus alerting rules, you can define alerts that fire when PromQL expressions breach some threshold or satisfy specified conditions over a period of time. For example, you can define a &lt;code>HighRequestLatency&lt;/code> alert that fires when a request latency metric is greater than some threshold over a period of time. As soon as the alerting condition is triggered, the alert moves into &lt;code>Pending&lt;/code> state. After satisfying the condition for the period of time defined by the &lt;code>for&lt;/code> parameter, the alert moves into &lt;code>Firing&lt;/code> state. You can configure routing and notifications for firing alerts using a tool like &lt;a href="https://prometheus.io/docs/alerting/latest/alertmanager/" target="_blank" rel="noopener noreferrer">Alertmanager&lt;/a>. Alertmanager is also built-in to Grafana Cloud.&lt;/p>
&lt;p>You can fetch the alerting rule YAML file &lt;a href="?tab=alerting-rules">here&lt;/a>.&lt;/p>
&lt;h3 id="load-alerting-rules-into-prometheus">Load alerting rules into Prometheus&lt;/h3>
&lt;p>To load alerting rules into Prometheus, add the following to your &lt;code>prometheus.yml&lt;/code> configuration file:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">rule_files:
- &amp;#34;postgres_exporter_alerting_rules.yml&amp;#34;&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Be sure to replace &lt;code>postgres_exporter_alerting_rules.yml&lt;/code> with the path to your Postgres alerting rules YAML file.&lt;/p>
&lt;h3 id="load-alerting-rules-into-grafana-cloud">Load alerting rules into Grafana Cloud&lt;/h3>
&lt;p>To learn how to load alerting rules into Grafana Cloud, please see &lt;a href="/docs/grafana-cloud/alerts/alerts-rules/#prometheus-and-loki-rules-with-cortextool">Prometheus and Loki rules with cortextool&lt;/a>.&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>In this quickstart you installed and ran Postgres Exporter on your Linux machine. You then configured Prometheus to scrape the database and Postgres metrics exposed by Postgres Exporter. You loaded alerting rules into Prometheus, and finally imported Grafana dashboards to visualize your Postgres metrics.&lt;/p>
&lt;p>If you&amp;rsquo;re using Grafana Cloud, you can skip all of the steps in this guide by installing the Postgres integration with the Grafana Cloud Agent. This integration embeds a preconfigured Postgres Exporter into the agent and automatically provisions Grafana dashboards and Prometheus alerting and recording rules, so you don&amp;rsquo;t have to import them manually. To learn how to set up the Postgres integration, please see &lt;a href="/docs/grafana-cloud/integrations/">Grafana Cloud Integrations&lt;/a>.&lt;/p>
&lt;p>The dashboards, recording rules, and alerting rules were generated using the Postgres Exporter Mixin. Mixins are reusable templates for dasboards, recording rules, and alerts curated and designed by subject matter experts. To learn more, please see the &lt;a href="https://github.com/prometheus-community/postgres_exporter/tree/master/postgres_mixin" target="_blank" rel="noopener noreferrer">Postgres Mixin&lt;/a> repository.&lt;/p></description></item></channel></rss>