1
0
mirror of https://github.com/chylex/Apache-Prometheus-Exporter.git synced 2025-04-10 20:15:45 +02:00

Add Docker Compose example

This commit is contained in:
chylex 2022-09-11 16:28:18 +02:00
parent e4ef6726c1
commit 5d96ade510
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
9 changed files with 146 additions and 0 deletions

4
.dockerignore Normal file
View File

@ -0,0 +1,4 @@
.git
.idea
docker
target

12
Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM rust:alpine as builder
RUN apk add --no-cache musl-dev
WORKDIR /app/
COPY . .
RUN cargo install --path .
FROM alpine
COPY --from=builder /usr/local/cargo/bin/apache_prometheus_exporter /usr/local/bin/apache_prometheus_exporter
CMD ["apache_prometheus_exporter"]

24
docker/README.md Normal file
View File

@ -0,0 +1,24 @@
# Apache Prometheus Exporter - Docker Example
Here you can find an example Docker Compose configuration you can use to develop and test the exporter.
This configuration will create a Docker volume for the logs, and the following containers:
1. **Apache** running on 3 ports, each of which has its own access log:
- http://localhost:2001
- http://localhost:2002
- http://localhost:2003
2. **Grafana** running on http://localhost:2000 with a pre-configured Prometheus data source.
- **User** : `admin`
- **Password** : `admin`
3. **Prometheus** configured with the exporter's endpoint.
4. **Exporter** built using the source code from this repository.
This example is not suitable for production. You can use it as inspiration, but you will have to modify it in order to persist container data and follow the latest security practices:
- Create Docker volumes for persistent storage of container data and configuration files
- Create a dedicated user for each container instead of running as `root`
- Customize the configuration of every containerized application for your needs
- Use HTTPS for all domains served by Apache
- Have Apache act as a reverse proxy for Grafana instead of exposing Grafana's web server port
- Use a strong password for Grafana and pass it via Docker secrets instead of environment variables

View File

@ -0,0 +1 @@
LoadModule macro_module /usr/lib/apache2/modules/mod_macro.so

View File

@ -0,0 +1,5 @@
Listen 2001
Listen 2002
Listen 2003
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

View File

@ -0,0 +1,27 @@
ServerName localhost
LogFormat "%t %h \"%r\" %>s %O %{ms}T \"%{Referer}i\" \"%{User-Agent}i\"" prometheus
<Macro Logs $domain>
ErrorLog "|/usr/bin/rotatelogs -l -f -D -L ${APACHE_LOG_DIR}/$domain.error.log ${APACHE_LOG_DIR}/%Y-%m-%d/$domain.error.log 86400"
CustomLog "|/usr/bin/rotatelogs -l -f -D -L ${APACHE_LOG_DIR}/$domain.access.log ${APACHE_LOG_DIR}/%Y-%m-%d/$domain.access.log 86400" prometheus
</Macro>
<VirtualHost *:2001>
DocumentRoot /var/www/html
Use Logs first
</VirtualHost>
<VirtualHost *:2002>
DocumentRoot /var/www/html
Use Logs second
</VirtualHost>
<VirtualHost *:2003>
DocumentRoot /var/www/html
Use Logs third
</VirtualHost>
UndefMacro Logs
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

View File

@ -0,0 +1,11 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
orgId: 1
url: http://prometheus:9090
basicAuth: false
isDefault: true
editable: true

View File

@ -0,0 +1,10 @@
global:
scrape_interval: 10s
scrape_timeout: 5s
evaluation_interval: 1m
scrape_configs:
- job_name: 'apache'
static_configs:
- targets: ['exporter:9240']

52
docker/docker-compose.yml Normal file
View File

@ -0,0 +1,52 @@
version: "2.4"
services:
apache:
container_name: ape_dev_apache
image: "php:apache"
ports:
- "127.0.0.1:2001:2001"
- "127.0.0.1:2002:2002"
- "127.0.0.1:2003:2003"
volumes:
- ./config/apache/ports.conf:/etc/apache2/ports.conf:ro
- ./config/apache/modules.conf:/etc/apache2/mods-enabled/modules.conf:ro
- ./config/apache/sites.conf:/etc/apache2/sites-enabled/sites.conf:ro
- logs:/var/log/apache2
restart: "always"
grafana:
container_name: ape_dev_grafana
image: grafana/grafana
ports:
- "127.0.0.1:2000:3000"
volumes:
- ./config/grafana/datasource.yml:/etc/grafana/provisioning/datasources/datasource.yml:ro
environment:
GF_SECURITY_ADMIN_USER: "admin"
GF_SECURITY_ADMIN_PASSWORD: "admin"
GF_USERS_ALLOW_SIGN_UP: "false"
restart: "always"
prometheus:
container_name: ape_dev_prometheus
image: prom/prometheus
volumes:
- ./config/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
restart: "always"
exporter:
container_name: ape_dev_exporter
build: "../"
expose:
- "9240"
volumes:
- logs:/logs
environment:
HTTP_HOST: "0.0.0.0"
LOG_FILE_PATTERN: "/logs/*.access.log"
restart: "always"
volumes:
logs:
name: exporter_dev_logs