-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b0c3d8d
Showing
12 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
skip_list: | ||
- "204" | ||
- "yaml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Push workflow | ||
|
||
on: push | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
name: ansible-lint | ||
steps: | ||
- uses: actions/checkout@master | ||
- uses: actions/setup-python@v2 | ||
- run: pip install ansible ansible-lint | ||
- run: ansible-lint --version | ||
- run: ansible-lint . | ||
|
||
commitlint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Lint Commit | ||
uses: wagoid/commitlint-github-action@v3 | ||
|
||
release: | ||
name: Publish new release | ||
needs: [lint, commitlint] | ||
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 14 | ||
- name: Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: npx semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"branches": [ | ||
"main" | ||
], | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
[ | ||
"@semantic-release/github", | ||
{ | ||
"successComment": false, | ||
"releasedLabels": false | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2022 angristan | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Ansible role for Postgres exporter | ||
|
||
This role will setup [postgres_exporter](https://github.com/prometheus-community/postgres_exporter) on any Linux machine using systemd. | ||
|
||
## Role Variables | ||
|
||
- `postgres_exporter_version`: the version of Postgres exporter that will be installed. | ||
|
||
The role will download the Postgres exporter release on the deployer and upload the binary to the target host. | ||
|
||
If the `/usr/local/bin/postgres_exporter` binary already exists, the role will skip the install steps. You can force them (to update, for instance), by setting `postgres_exporter_force_install` to true. | ||
|
||
- `postgres_exporter_web_listen_address`: the address Node exporter will listen on. (`0.0.0.0:9187`) | ||
|
||
## Example playbook | ||
|
||
```yaml | ||
--- | ||
- hosts: myhost | ||
roles: postgres-exporter | ||
``` | ||
## License | ||
MIT. See LICENSE for more details. | ||
## Author Information | ||
See my other Ansible roles at [angristan/ansible-roles](https://github.com/angristan/ansible-roles). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
postgres_exporter_version: 0.11.1 | ||
postgres_exporter_force_install: false | ||
postgres_exporter_web_listen_address: "0.0.0.0:9187" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
- name: Restart postgres_exporter | ||
ansible.builtin.systemd: | ||
daemon_reload: true | ||
name: postgres-exporter | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
- name: Copy the Postgres Exporter systemd service file | ||
ansible.builtin.template: | ||
src: postgres-exporter.service.j2 | ||
dest: /etc/systemd/system/postgres-exporter.service | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
notify: Restart postgres-exporter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
- name: Download the postgres_exporter binary to a local folder | ||
ansible.builtin.get_url: | ||
url: "https://github.com/prometheus-community/postgres_exporter/releases/download/v{{ postgres_exporter_version }}/postgres_exporter-{{ postgres_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz" | ||
dest: "/tmp/postgres_exporter-{{ postgres_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz" | ||
mode: 0644 | ||
register: _download_binary | ||
until: _download_binary is succeeded | ||
retries: 5 | ||
delay: 2 | ||
delegate_to: localhost | ||
check_mode: false | ||
|
||
- name: Unarchive the postgres_exporter binary | ||
ansible.builtin.unarchive: | ||
src: "/tmp/postgres_exporter-{{ postgres_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz" | ||
dest: "/tmp" | ||
creates: "/tmp/postgres_exporter-v{{ postgres_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/postgres_exporter" | ||
delegate_to: localhost | ||
check_mode: false | ||
|
||
- name: Upload the postgres_exporter binary | ||
ansible.builtin.copy: | ||
src: "/tmp/postgres_exporter-{{ postgres_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/postgres_exporter" | ||
dest: "/usr/local/bin/postgres_exporter" | ||
mode: 0750 | ||
owner: postgres | ||
group: postgres | ||
notify: Restart postgres_exporter | ||
when: not ansible_check_mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
- name: Check if postgres_exporter is installed | ||
ansible.builtin.stat: | ||
path: "/usr/local/bin/postgres_exporter" | ||
register: postgres_exporter_binary | ||
|
||
- name: Install postgres_exporter | ||
ansible.builtin.include_tasks: install.yml | ||
when: not postgres_exporter_binary.stat.exists or postgres_exporter_force_install | ||
|
||
- name: Configure postgres_exporter | ||
ansible.builtin.import_tasks: configure.yml | ||
tags: | ||
- postgres_exporter.configure | ||
|
||
- name: Ensure Postgres exporter is enabled on boot | ||
ansible.builtin.systemd: | ||
daemon_reload: true | ||
name: postgres-exporter | ||
enabled: true | ||
state: started |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{{ ansible_managed | comment }} | ||
|
||
[Unit] | ||
Description=Prometheus Postgres exporter | ||
After=network.target | ||
|
||
[Service] | ||
Type=simple | ||
User=postgres | ||
Group=postgres | ||
ExecStart=/usr/local/bin/postgres_exporter \ | ||
--web.listen-address={{ postgres_exporter_web_listen_address }} | ||
|
||
SyslogIdentifier=postgres-exporter | ||
Restart=always | ||
Environment=DATA_SOURCE_NAME="user=postgres host=/var/run/postgresql/ sslmode=disable" | ||
|
||
PrivateTmp=yes | ||
ProtectHome=yes | ||
NoNewPrivileges=yes | ||
ProtectSystem=strict | ||
ProtectControlGroups=true | ||
ProtectKernelModules=true | ||
ProtectKernelTunables=yes | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
go_arch_map: | ||
i386: '386' | ||
x86_64: 'amd64' | ||
aarch64: 'arm64' | ||
armv7l: 'armv7' | ||
armv6l: 'armv6' |