first commit
This commit is contained in:
commit
a9e4cb9d3c
14
Dockerfiles/backup.Dockerfile
Normal file
14
Dockerfiles/backup.Dockerfile
Normal file
@ -0,0 +1,14 @@
|
||||
# Use the Alpine image as the base
|
||||
FROM alpine:latest as backup_custom
|
||||
|
||||
# Copy the entrypoint script into the container
|
||||
COPY entrypoint_backup.sh /usr/local/bin/entrypoint_backup.sh
|
||||
|
||||
# Switch to root user for setup
|
||||
USER root
|
||||
|
||||
# Make the entrypoint script executable
|
||||
RUN chmod +x /usr/local/bin/entrypoint_backup.sh
|
||||
|
||||
# Set the new entrypoint
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint_backup.sh"]
|
27
Dockerfiles/exporter.Dockerfile
Normal file
27
Dockerfiles/exporter.Dockerfile
Normal file
@ -0,0 +1,27 @@
|
||||
# Use a Python slim image as base
|
||||
FROM python:3.9-slim as exporter_custom
|
||||
|
||||
# Set environment variables to avoid buffering
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# Create and set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install required dependencies
|
||||
RUN apt-get update && \
|
||||
apt-get install -y \
|
||||
libpq-dev && \
|
||||
pip install psycopg2-binary prometheus-client && \
|
||||
apt-get clean
|
||||
|
||||
# Create a directory for logs
|
||||
RUN mkdir /app/logs
|
||||
|
||||
# Copy the Python script into the container
|
||||
COPY pg_metrics_exporter.py /app/
|
||||
|
||||
# Set permissions for log directory (if required)
|
||||
RUN chmod 755 /app/logs
|
||||
|
||||
# Run the script and redirect logs to a file
|
||||
CMD ["python", "/app/pg_metrics_exporter.py", ">", "/app/logs/exporter.log", "2>&1"]
|
13
Dockerfiles/odoo.Dockerfile
Normal file
13
Dockerfiles/odoo.Dockerfile
Normal file
@ -0,0 +1,13 @@
|
||||
# Use the existing Odoo image as the base
|
||||
FROM odoo:latest as odoo-custom
|
||||
|
||||
# Copy the entrypoint script into the container
|
||||
COPY entrypoint_odoo.sh /usr/local/bin/entrypoint_odoo.sh
|
||||
|
||||
USER root
|
||||
|
||||
# Make the entrypoint script executable
|
||||
RUN chmod +x /usr/local/bin/entrypoint_odoo.sh
|
||||
|
||||
# Set the new entrypoint
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint_odoo.sh"]
|
5
deploy.yml
Normal file
5
deploy.yml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
become: true
|
||||
roles:
|
||||
- role: docker-compose
|
109
docker-compose.yml
Normal file
109
docker-compose.yml
Normal file
@ -0,0 +1,109 @@
|
||||
version: "3.9"
|
||||
services:
|
||||
admin:
|
||||
image: postgres:latest
|
||||
environment:
|
||||
POSTGRES_DB: admin
|
||||
POSTGRES_USER: admin
|
||||
POSTGRES_PASSWORD: admin
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
networks:
|
||||
- testNetwork
|
||||
|
||||
pgadmin:
|
||||
image: dpage/pgadmin4:latest
|
||||
environment:
|
||||
PGADMIN_DEFAULT_EMAIL: admin@admin.com
|
||||
PGADMIN_DEFAULT_PASSWORD: admin
|
||||
ports:
|
||||
- "5050:80"
|
||||
networks:
|
||||
- testNetwork
|
||||
|
||||
prometheus_exporter:
|
||||
image: exporter_custom
|
||||
ports:
|
||||
- "8000:8000"
|
||||
networks:
|
||||
- testNetwork
|
||||
depends_on:
|
||||
- admin #Make sure Postgres is up before exporter
|
||||
|
||||
odoo:
|
||||
image: odoo_custom
|
||||
environment:
|
||||
HOST: admin
|
||||
USER: admin
|
||||
PASSWORD: admin
|
||||
DATABASE: admin
|
||||
ODOO_PASSWORD: admin
|
||||
ports:
|
||||
- "8069:8069"
|
||||
volumes:
|
||||
- ./odoo.conf:/etc/odoo/odoo.conf
|
||||
- ./logs/odoo:/var/log/odoo
|
||||
networks:
|
||||
- testNetwork
|
||||
depends_on:
|
||||
- admin
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:latest
|
||||
environment:
|
||||
GF_SECURITY_ADMIN_PASSWORD: grafana_pwd
|
||||
GF_DATASOURCES_PROMETHEUS_URL: http://prometheus:9090
|
||||
ports:
|
||||
- "3000:3000"
|
||||
networks:
|
||||
- testNetwork
|
||||
depends_on:
|
||||
- prometheus
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:latest
|
||||
ports:
|
||||
- "9090:9090"
|
||||
volumes:
|
||||
- prometheus-data:/prometheus
|
||||
- ./prometheus.yml:/etc/prometheus/prometheus.yml
|
||||
networks:
|
||||
- testNetwork
|
||||
|
||||
fluentd:
|
||||
image: fluent/fluentd:v1.13-1
|
||||
ports:
|
||||
- "24224:24224"
|
||||
volumes:
|
||||
- ./logs/odoo:/var/log/odoo
|
||||
- ./fluent.conf:/fluentd/etc/fluent.conf
|
||||
networks:
|
||||
- testNetwork
|
||||
depends_on:
|
||||
- odoo
|
||||
|
||||
|
||||
backup:
|
||||
image: backup_custom
|
||||
environment:
|
||||
POSTGRES_HOST: admin
|
||||
POSTGRES_DB: admin
|
||||
POSTGRES_USER: admin
|
||||
POSTGRES_PASSWORD: admin
|
||||
volumes:
|
||||
- backup-data:/backup
|
||||
networks:
|
||||
- testNetwork
|
||||
depends_on:
|
||||
- admin
|
||||
|
||||
networks:
|
||||
testNetwork:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
postgres-data:
|
||||
prometheus-data:
|
||||
backup-data:
|
11
entrypoint_backup.sh
Normal file
11
entrypoint_backup.sh
Normal file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Install PostgreSQL client
|
||||
apk add --no-cache postgresql-client
|
||||
|
||||
# Wait until the PostgreSQL server is ready
|
||||
until pg_isready -h admin -U admin; do
|
||||
echo "Waiting for PostgreSQL..."
|
||||
sleep 2
|
||||
done
|
||||
|
4
entrypoint_odoo.sh
Normal file
4
entrypoint_odoo.sh
Normal file
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
sleep 20
|
||||
odoo -i base
|
13
fluent.conf
Normal file
13
fluent.conf
Normal file
@ -0,0 +1,13 @@
|
||||
<source>
|
||||
@type tail
|
||||
path "/var/log/odoo/odoo.log"
|
||||
pos_file "/fluentd/logs/odoo.pos"
|
||||
format none
|
||||
tag "odoo.log"
|
||||
</source>
|
||||
|
||||
<match odoo.log>
|
||||
@type file
|
||||
path "/fluentd/logs/collected-logs"
|
||||
</match>
|
||||
|
2
inventory/hosts
Normal file
2
inventory/hosts
Normal file
@ -0,0 +1,2 @@
|
||||
[localhost]
|
||||
localhost ansible_connection=local
|
8
odoo.conf
Normal file
8
odoo.conf
Normal file
@ -0,0 +1,8 @@
|
||||
[options]
|
||||
db_host = admin
|
||||
db_port = 5432
|
||||
db_user = admin
|
||||
db_password = admin
|
||||
default_productivity_apps = True
|
||||
db_name = admin
|
||||
logfile = /var/log/odoo/odoo.log
|
59
pg_metrics_exporter.py
Normal file
59
pg_metrics_exporter.py
Normal file
@ -0,0 +1,59 @@
|
||||
import psycopg2
|
||||
from prometheus_client import start_http_server, Gauge
|
||||
import time
|
||||
|
||||
# Configuration for database connection
|
||||
DB_PARAMS = {
|
||||
"host": "admin",
|
||||
"database": "admin",
|
||||
"user": "admin",
|
||||
"password": "admin"
|
||||
}
|
||||
|
||||
# Prometheus metrics
|
||||
QUERY_CALLS = Gauge('postgresql_query_calls', 'Number of calls for each query', ['query'])
|
||||
QUERY_TOTAL_TIME = Gauge('postgresql_query_total_time_ms', 'Total execution time for each query in ms', ['query'])
|
||||
|
||||
def fetch_metrics():
|
||||
try:
|
||||
# Log connection attempt
|
||||
print("Connecting to PostgreSQL database...")
|
||||
|
||||
conn = psycopg2.connect(**DB_PARAMS)
|
||||
cur = conn.cursor()
|
||||
|
||||
# Execute query to get data
|
||||
cur.execute("""
|
||||
SELECT query, calls, total_exec_time
|
||||
FROM pg_stat_statements
|
||||
ORDER BY total_exec_time DESC;
|
||||
""")
|
||||
|
||||
# Iterate through results and set Prometheus metrics
|
||||
for row in cur:
|
||||
query = row[0].replace("\\", "\\\\").replace('"', '\\"') # Escape special characters
|
||||
calls = row[1]
|
||||
total_time = row[2] * 1000 # Convert seconds to milliseconds
|
||||
|
||||
QUERY_CALLS.labels(query=query).set(calls)
|
||||
QUERY_TOTAL_TIME.labels(query=query).set(total_time)
|
||||
|
||||
# Log the metrics being set
|
||||
print(f"Metrics set for query: {query} | Calls: {calls} | Total execution time: {total_time} ms")
|
||||
|
||||
cur.close()
|
||||
conn.close()
|
||||
except psycopg2.Error as e:
|
||||
print(f"Error fetching data: {e}")
|
||||
except Exception as e:
|
||||
print(f"Unexpected error: {e}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Start Prometheus HTTP server on port 8000
|
||||
start_http_server(8000)
|
||||
print("Exporter running on http://localhost:8000/metrics")
|
||||
|
||||
# Main loop to fetch metrics at regular intervals
|
||||
while True:
|
||||
fetch_metrics()
|
||||
time.sleep(60) # Scrape every 60 seconds
|
5
prometheus.yml
Normal file
5
prometheus.yml
Normal file
@ -0,0 +1,5 @@
|
||||
scrape_configs:
|
||||
- job_name: 'pg_stat_statements'
|
||||
static_configs:
|
||||
- targets: ['prometheus_exporter:8000']
|
||||
scrape_interval: 15s
|
0
roles/docker-compose/tasks/main.yml
Normal file
0
roles/docker-compose/tasks/main.yml
Normal file
0
roles/docker-compose/vars/main.yml
Normal file
0
roles/docker-compose/vars/main.yml
Normal file
Loading…
Reference in New Issue
Block a user