From c054533c8401cfb20f84d096a82989ebd1f0bf39 Mon Sep 17 00:00:00 2001 From: aditya-opsverse Date: Mon, 11 Jul 2022 10:14:03 +0530 Subject: [PATCH 1/4] Added Postgres Exporter --- .../install-exporter-amd64.sh | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/prometheus-exporters/install-exporter-amd64.sh b/prometheus-exporters/install-exporter-amd64.sh index 9b1b876..a9a245b 100755 --- a/prometheus-exporters/install-exporter-amd64.sh +++ b/prometheus-exporters/install-exporter-amd64.sh @@ -58,7 +58,7 @@ while [[ $# -gt 0 ]]; do done # Show help, if necessary, and exit -if [ "$HELP" = true ] || [ "$EXPORTER" != "mysqld" -a "$EXPORTER" != "mongodb" -a "$EXPORTER" != "redis" -a "$EXPORTER" != "jmx" -a "$EXPORTER" != "nginx" -a "$EXPORTER" != "cadvisor" -a "$EXPORTER" != "vmware" "$EXPORTER" != "opsverse-otelcontribcol" ]; then +if [ "$HELP" = true ] || [ "$EXPORTER" != "mysqld" -a "$EXPORTER" != "mongodb" -a "$EXPORTER" != "redis" -a "$EXPORTER" != "jmx" -a "$EXPORTER" != "nginx" -a "$EXPORTER" != "cadvisor" -a "$EXPORTER" != "vmware" "$EXPORTER" != "opsverse-otelcontribcol" -a "$EXPORTER" != "postgres" ]; then echo "Installs a prometheus exporter on your machine" echo "" echo "Usage: sudo ./install-exporter.sh -e " @@ -75,6 +75,7 @@ if [ "$HELP" = true ] || [ "$EXPORTER" != "mysqld" -a "$EXPORTER" != "mongodb" - echo " - opsverse-otelcontribcol" echo " - redis" echo " - vmware" + echo " - postgres" echo "" echo "Example:" echo " sudo ./install-exporter.sh -e mysqld" @@ -194,6 +195,21 @@ function download_exporter () { # cleanup what was downloaded rm -rf ${EXPORTER_BASE_NAME}* fi + + if [ "$EXPORTER" == "postgres" ]; then + EXPORTER_VERSION="0.10.1" + EXPORTER_BASE_NAME="postgres_exporter-${EXPORTER_VERSION}.aix-ppc64" + EXPORTER_DL_URL="https://github.com/prometheus-community/postgres_exporter/releases/download/v${EXPORTER_VERSION}/${EXPORTER_BASE_NAME}.tar.gz" + + wget ${EXPORTER_DL_URL} + tar -xzf ${EXPORTER_BASE_NAME}.tar.gz + mv postgres_exporter /usr/local/bin/ + chmod +x /usr/local/bin/postgres_exporter + + # cleanup what was downloaded + rm -rf ${EXPORTER_BASE_NAME}* + rm -rf postgres_exporter + fi } function set_exporter_custom_confs () { @@ -353,6 +369,13 @@ default: EOF fi + if [ "$EXPORTER" == "postgres" ]; then + cat << EOF > /etc/opsverse/exporters/postgres/config.yaml +default: + DATA_SOURCE_NAME="user=postgres host=/var/run/postgresql/ sslmode=disable" +EOF + fi + } function set_exporter_systemd () { @@ -465,6 +488,21 @@ User=root ExecStart=/usr/local/bin/vmware_exporter/vmware_exporter/vmware_exporter.py -c /etc/opsverse/exporters/vmware/config.yaml Restart=always +[Install] +WantedBy=multi-user.target +EOF + fi + + if [ "$EXPORTER" == "postgres" ]; then + cat << EOF > $EXPORTER_SERVICE_FILE +[Unit] +Description=Prometheus Postgres Exporter + +[Service] +User=root +ExecStart=/usr/local/bin/postgres_exporter -c /etc/opsverse/exporters/postgres/config.yaml +Restart=always + [Install] WantedBy=multi-user.target EOF @@ -484,7 +522,7 @@ EOF # returns true (0) if exporter needs a sysv init script function exporter_needs_sysv () { - if [ "$1" == "redis" ] || [ "$1" == "mysqld" ] || [ "$1" == "mongodb" ] || [ "$1" == 'nginx' ] || [ "$1" == "cadvisor" ] || [ "$1" == "vmware" ] || [ "$1" == "opsverse-otelcontribcol" ] ; then + if [ "$1" == "redis" ] || [ "$1" == "mysqld" ] || [ "$1" == "mongodb" ] || [ "$1" == 'nginx' ] || [ "$1" == "cadvisor" ] || [ "$1" == "vmware" ] || [ "$1" == "opsverse-otelcontribcol" ] || [ "$1" == "postgres" ] ; then return 0 fi @@ -547,6 +585,12 @@ function set_exporter_sysv () { EXPORTER_KILLPROC="vmware_exporter.py" fi + if [ "$EXPORTER" == "postgres" ]; then + EXPORTER_CONFIG="/etc/opsverse/exporters/postgres/config.yaml" + EXPORTER_COMMAND="/usr/local/bin/postgres_exporter -c /etc/opsverse/exporters/postgres/config.yaml" + EXPORTER_KILLPROC="postgres_exporter" + fi + cat << EOF > $EXPORTER_SYSV_SCRIPT #!/bin/bash # @@ -744,6 +788,21 @@ EOF ] } ] +EOF + fi + + if [ "$EXPORTER" == "postgres" ]; then + cat << EOF > /etc/opsverse/targets/${EXPORTER}-exporter.json +[ + { + "labels": { + "job": "integrations/postgres-exporter" + }, + "targets": [ + "localhost:9187" + ] + } +] EOF fi From 69e96bb39571863420f8bb252e4a5917efb09093 Mon Sep 17 00:00:00 2001 From: aditya-opsverse Date: Mon, 11 Jul 2022 14:28:31 +0530 Subject: [PATCH 2/4] Minor changes --- .../install-exporter-amd64.sh | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/prometheus-exporters/install-exporter-amd64.sh b/prometheus-exporters/install-exporter-amd64.sh index a9a245b..2171674 100755 --- a/prometheus-exporters/install-exporter-amd64.sh +++ b/prometheus-exporters/install-exporter-amd64.sh @@ -203,7 +203,7 @@ function download_exporter () { wget ${EXPORTER_DL_URL} tar -xzf ${EXPORTER_BASE_NAME}.tar.gz - mv postgres_exporter /usr/local/bin/ + cp postgres_exporter /usr/local/bin chmod +x /usr/local/bin/postgres_exporter # cleanup what was downloaded @@ -370,9 +370,8 @@ EOF fi if [ "$EXPORTER" == "postgres" ]; then - cat << EOF > /etc/opsverse/exporters/postgres/config.yaml -default: - DATA_SOURCE_NAME="user=postgres host=/var/run/postgresql/ sslmode=disable" + cat << EOF > /etc/opsverse/exporters/postgres/postgres_exporter.env +DATA_SOURCE_NAME="postgresql://postgres:password@localhost:5432/postgres?sslmode=disable" wrouesnel/postgres_exporter EOF fi @@ -496,11 +495,16 @@ EOF if [ "$EXPORTER" == "postgres" ]; then cat << EOF > $EXPORTER_SERVICE_FILE [Unit] -Description=Prometheus Postgres Exporter +Description=Prometheus exporter for Postgresql +Wants=network-online.target +After=network-online.target [Service] -User=root -ExecStart=/usr/local/bin/postgres_exporter -c /etc/opsverse/exporters/postgres/config.yaml +User=postgres +Group=postgres +WorkingDirectory=/usr/local/bin/postgres_exporter +EnvironmentFile=/etc/opsverse/exporters/postgres/postgres_exporter.env +ExecStart=/usr/local/bin/postgres_exporter --web.listen-address=:9187 --web.telemetry-path=/metrics Restart=always [Install] @@ -586,8 +590,8 @@ function set_exporter_sysv () { fi if [ "$EXPORTER" == "postgres" ]; then - EXPORTER_CONFIG="/etc/opsverse/exporters/postgres/config.yaml" - EXPORTER_COMMAND="/usr/local/bin/postgres_exporter -c /etc/opsverse/exporters/postgres/config.yaml" + EXPORTER_CONFIG="/etc/opsverse/exporters/postgres/postgres_exporter.env" + EXPORTER_COMMAND="/usr/local/bin/postgres_exporter -c /etc/opsverse/exporters/postgres/postgres_exporter.env" EXPORTER_KILLPROC="postgres_exporter" fi From 9441977a76c6a66f3ec5d2c33370990744872d77 Mon Sep 17 00:00:00 2001 From: aditya-opsverse Date: Tue, 12 Jul 2022 13:33:16 +0530 Subject: [PATCH 3/4] Made changes in the file --- prometheus-exporters/install-exporter-amd64.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/prometheus-exporters/install-exporter-amd64.sh b/prometheus-exporters/install-exporter-amd64.sh index 2171674..507d918 100755 --- a/prometheus-exporters/install-exporter-amd64.sh +++ b/prometheus-exporters/install-exporter-amd64.sh @@ -58,7 +58,7 @@ while [[ $# -gt 0 ]]; do done # Show help, if necessary, and exit -if [ "$HELP" = true ] || [ "$EXPORTER" != "mysqld" -a "$EXPORTER" != "mongodb" -a "$EXPORTER" != "redis" -a "$EXPORTER" != "jmx" -a "$EXPORTER" != "nginx" -a "$EXPORTER" != "cadvisor" -a "$EXPORTER" != "vmware" "$EXPORTER" != "opsverse-otelcontribcol" -a "$EXPORTER" != "postgres" ]; then +if [ "$HELP" = true ] || [ "$EXPORTER" != "mysqld" -a "$EXPORTER" != "mongodb" -a "$EXPORTER" != "redis" -a "$EXPORTER" != "jmx" -a "$EXPORTER" != "nginx" -a "$EXPORTER" != "cadvisor" -a "$EXPORTER" != "vmware" -a "$EXPORTER" != "opsverse-otelcontribcol" -a "$EXPORTER" != "postgres" ]; then echo "Installs a prometheus exporter on your machine" echo "" echo "Usage: sudo ./install-exporter.sh -e " @@ -198,12 +198,12 @@ function download_exporter () { if [ "$EXPORTER" == "postgres" ]; then EXPORTER_VERSION="0.10.1" - EXPORTER_BASE_NAME="postgres_exporter-${EXPORTER_VERSION}.aix-ppc64" + EXPORTER_BASE_NAME="postgres_exporter-${EXPORTER_VERSION}.linux-amd64" EXPORTER_DL_URL="https://github.com/prometheus-community/postgres_exporter/releases/download/v${EXPORTER_VERSION}/${EXPORTER_BASE_NAME}.tar.gz" wget ${EXPORTER_DL_URL} tar -xzf ${EXPORTER_BASE_NAME}.tar.gz - cp postgres_exporter /usr/local/bin + cp ${EXPORTER_BASE_NAME}/postgres_exporter /usr/local/bin chmod +x /usr/local/bin/postgres_exporter # cleanup what was downloaded @@ -371,7 +371,7 @@ EOF if [ "$EXPORTER" == "postgres" ]; then cat << EOF > /etc/opsverse/exporters/postgres/postgres_exporter.env -DATA_SOURCE_NAME="postgresql://postgres:password@localhost:5432/postgres?sslmode=disable" wrouesnel/postgres_exporter +DATA_SOURCE_NAME="postgresql://postgres:postgres123@localhost:5432/?sslmode=disable" EOF fi @@ -502,7 +502,6 @@ After=network-online.target [Service] User=postgres Group=postgres -WorkingDirectory=/usr/local/bin/postgres_exporter EnvironmentFile=/etc/opsverse/exporters/postgres/postgres_exporter.env ExecStart=/usr/local/bin/postgres_exporter --web.listen-address=:9187 --web.telemetry-path=/metrics Restart=always From 3f27693c87d0237203384f6ecf05ef6ca5e72aad Mon Sep 17 00:00:00 2001 From: aditya-opsverse Date: Wed, 13 Jul 2022 09:39:32 +0530 Subject: [PATCH 4/4] Changed postgres username and password --- prometheus-exporters/install-exporter-amd64.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prometheus-exporters/install-exporter-amd64.sh b/prometheus-exporters/install-exporter-amd64.sh index 507d918..27ad833 100755 --- a/prometheus-exporters/install-exporter-amd64.sh +++ b/prometheus-exporters/install-exporter-amd64.sh @@ -371,7 +371,7 @@ EOF if [ "$EXPORTER" == "postgres" ]; then cat << EOF > /etc/opsverse/exporters/postgres/postgres_exporter.env -DATA_SOURCE_NAME="postgresql://postgres:postgres123@localhost:5432/?sslmode=disable" +DATA_SOURCE_NAME="postgresql://postgres_user:postgres_password@localhost:5432/?sslmode=disable" EOF fi