Skip to content

Commit

Permalink
Update to latest postgres and node exporters
Browse files Browse the repository at this point in the history
  • Loading branch information
danivovich committed Mar 15, 2023
1 parent 964f70a commit ab46f64
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
44 changes: 24 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,38 @@ Set up common prometheus exporter configurations
```
- src: [email protected]:smartlogic/ansible-role-prometheus-exporters
name: prometheus-exporters
version: 0.5.3
version: 1.0.0
```

## Requirements

### For postgres_exporter

Set up permission for the prometheus user (by default) to have access to the necessary stats
Set up permission for the postgres_exporter user (by default) to have access to the necessary stats, update the password to something more secure

```sql
CREATE USER prometheus;
CREATE DATABASE prometheus;
ALTER USER prometheus SET SEARCH_PATH TO prometheus,pg_catalog;

-- If deploying as non-superuser (for example in AWS RDS)
-- GRANT prometheus TO :MASTER_USER;
CREATE SCHEMA prometheus AUTHORIZATION prometheus;

CREATE VIEW prometheus.pg_stat_activity
AS
SELECT * from pg_catalog.pg_stat_activity;

GRANT SELECT ON prometheus.pg_stat_activity TO prometheus;

CREATE VIEW prometheus.pg_stat_replication AS
SELECT * from pg_catalog.pg_stat_replication;

GRANT SELECT ON prometheus.pg_stat_replication TO prometheus;
CREATE OR REPLACE FUNCTION __tmp_create_user() returns void as $$
BEGIN
IF NOT EXISTS (
SELECT -- SELECT list can stay empty for this
FROM pg_catalog.pg_user
WHERE usename = 'postgres_exporter') THEN
CREATE USER postgres_exporter;
END IF;
END;
$$ language plpgsql;

SELECT __tmp_create_user();
DROP FUNCTION __tmp_create_user();

ALTER USER postgres_exporter WITH PASSWORD '<set-a-password>';
ALTER USER postgres_exporter SET SEARCH_PATH TO postgres_exporter,pg_catalog;

-- If deploying as non-superuser (for example in AWS RDS), uncomment the GRANT
-- line below and replace <MASTER_USER> with your root user.
-- GRANT postgres_exporter TO <MASTER_USER>;

GRANT CONNECT ON DATABASE postgres TO postgres_exporter;
```

### Firewall Ports
Expand Down
10 changes: 5 additions & 5 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
node_exporter_version: 0.15.2
node_exporter_checksum: 1ce667467e442d1f7fbfa7de29a8ffc3a7a0c84d24d7c695cc88b29e0752df37
node_exporter_version: 1.5.0
node_exporter_checksum: af999fd31ab54ed3a34b9f0b10c28e9acee9ef5ac5a5d5edfdde85437db7acbb

redis_exporter_version: 0.15.0
redis_exporter_checksum: 170458f8c9e1588861b1584451cfc636b1339b4cf495f82396f03e474d6e626f
redis_addr: redis://localhost:6379

postgres_exporter_version: 0.4.1
postgres_exporter_checksum: 219c2c116cb496d54ddbd23f392a38c3496ab8e7118dfbf8b7c0b21593dedbfd
postgres_exporter_version: 0.11.1
postgres_exporter_checksum: ec27e2a52b764c4313076ea6db335607cc40fb8a503dcb74d9517dc8baf049f0
postgres_exporter_connection_host: /var/run/postgresql/
postgres_exporter_connection_ssl_mode: disable
postgres_exporter_connection_user: prometheus
postgres_exporter_connection_user: postgres_exporter
postgres_exporter_connection_dbname: postgres

blackbox_exporter_version: 0.11.0
Expand Down
8 changes: 4 additions & 4 deletions tasks/postgres_exporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

- name: "Download the postgres_exporter file"
get_url:
url: "https://github.com/wrouesnel/postgres_exporter/releases/download/v{{ postgres_exporter_version }}/postgres_exporter_v{{ postgres_exporter_version }}_linux-amd64.tar.gz"
url: "https://github.com/prometheus-community/postgres_exporter/releases/download/v{{ postgres_exporter_version }}/postgres_exporter-{{ postgres_exporter_version }}.linux-amd64.tar.gz"
dest: "/home/prometheus/postgres_exporter/{{ postgres_exporter_version }}/postgres_exporter.tar.gz"
mode: 0400
checksum: "sha256:{{ postgres_exporter_checksum }}"
become: yes
become_user: prometheus

- name: stat extracted folder
stat: path="/home/prometheus/postgres_exporter/postgres_exporter/{{ postgres_exporter_version }}/postgres_exporter_v{{ postgres_exporter_version }}_linux-amd64"
stat: path="/home/prometheus/postgres_exporter/postgres_exporter/{{ postgres_exporter_version }}/postgres_exporter-{{ postgres_exporter_version }}.linux-amd64"
register: postgres_exporter_extracted_folder_stat
become: yes
become_user: prometheus
Expand All @@ -37,13 +37,13 @@
become_user: prometheus

- name: stat extracted folder
stat: path="/home/prometheus/postgres_exporter/{{ postgres_exporter_version }}/postgres_exporter_v{{ postgres_exporter_version }}_linux-amd64"
stat: path="/home/prometheus/postgres_exporter/{{ postgres_exporter_version }}/postgres_exporter-{{ postgres_exporter_version }}.linux-amd64"
register: postgres_exporter_extracted_folder_stat
become: yes
become_user: prometheus

- name: Move extracted folder to standard path
command: mv /home/prometheus/postgres_exporter/{{ postgres_exporter_version }}/postgres_exporter_v{{ postgres_exporter_version }}_linux-amd64 /home/prometheus/postgres_exporter/{{ postgres_exporter_version }}/postgres_exporter
command: mv /home/prometheus/postgres_exporter/{{ postgres_exporter_version }}/postgres_exporter-{{ postgres_exporter_version }}.linux-amd64 /home/prometheus/postgres_exporter/{{ postgres_exporter_version }}/postgres_exporter
when: postgres_exporter_extracted_folder_stat.stat.exists
become: yes
become_user: prometheus
Expand Down

0 comments on commit ab46f64

Please sign in to comment.