Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker compose with prometheus #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
FROM centos:7
FROM golang:alpine

MAINTAINER Yogesh Sharma <[email protected]>
WORKDIR /source
COPY . /source
RUN apk --update-cache add --virtual \
build-dependencies \
build-base \
&& go mod download \
&& make all

COPY postgresql-prometheus-adapter start.sh /

ENTRYPOINT ["/start.sh"]
ENTRYPOINT ["/bin/sh", "/source/start.sh"]

90 changes: 90 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# This docker compose setup configures:
# - the Unleash server instance + the necessary backing Postgres database
# - the Unleash proxy
#
# To learn more about all the parts of Unleash, visit
# https://docs.getunleash.io
#
# NOTE: please do not use this configuration for production setups.
# Unleash does not take responsibility for any data leaks or other
# problems that may arise as a result.
#
# This is intended to be used for demo, development, and learning
# purposes only.

version: "3.9"
services:
# The Unleash server contains the Unleash configuration and
# communicates with server-side SDKs and the Unleash Proxy
db:
ports:
- "5432:5432"
image: postgres:15
environment:
# create a database called `db`
POSTGRES_DB: "db"
POSTGRES_PASSWORD: "unleash"
# trust incoming connections blindly (DON'T DO THIS IN PRODUCTION!)
POSTGRES_HOST_AUTH_METHOD: "trust"
healthcheck:
test:
[
"CMD",
"pg_isready",
"--username=postgres",
"--host=127.0.0.1",
"--port=5432",
]
interval: 2s
timeout: 1m
retries: 5
start_period: 10s
node1:
image: prom/node-exporter
ports:
- "9100:9100"
depends_on:
db:
condition: service_healthy
prom:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/prometheus/prometheus.yml
command: "--web.enable-remote-write-receiver"
depends_on:
db:
condition: service_healthy
# healthcheck:
# test: ["CMD", "curl", "localhost:9090"]
# interval: 1s
# timeout: 1m
# retries: 5
# start_period: 15s
web:
image: crunchydata/postgresql-prometheus-adapter:latest
build:
context: .
ports:
- "9201:9201"
environment:
DATABASE_URL: "postgres://postgres:unleash@db:5432/db"
web_listen_address: ":9201"
web_telemetry_path: "/metrics"
log_level: info
log_format: json
pg_partition: "hourly"
pg_commit_secs: 15
pg_commit_rows: 20000
pg_threads: 1
parser_threads: 5
depends_on:
db:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9201/write"]
interval: 1s
timeout: 1m
retries: 5
start_period: 15s
6 changes: 3 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ all: $(TARGET)
build: $(TARGET)

$(TARGET): main.go $(SOURCES)
go build -ldflags="-X 'main.Version=${VERSION}'" -o $(TARGET)
go build -ldflags="-X 'main.Version=${VERSION}' -extldflags '-static'" -o $(TARGET)

container: $(TARGET) Dockerfile
@#podman rmi $(ORGANIZATION)/$(TARGET):latest $(ORGANIZATION)/$(TARGET):$(VERSION)
podman build -t $(ORGANIZATION)/$(TARGET):latest .
podman tag $(ORGANIZATION)/$(TARGET):latest $(ORGANIZATION)/$(TARGET):$(VERSION)
docker build -t $(ORGANIZATION)/$(TARGET):latest .
# podman tag $(ORGANIZATION)/$(TARGET):latest $(ORGANIZATION)/$(TARGET):$(VERSION)

container-save: container
rm -f $(TARGET)-$(VERSION).tar
Expand Down
21 changes: 21 additions & 0 deletions prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"

# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s

static_configs:
- targets: ["localhost:9090"]
- targets: ["node1:9100"]
labels:
group: "test"
remote_write:
- url: "http://web:9201/write"
remote_read:
- url: "http://web:9201/read"
53 changes: 26 additions & 27 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash

if [[ "${DATABASE_URL}" == "" ]]; then
echo 'Missing DATABASE_URL'
echo 'example -e DATABASE_URL="user=<db user> password=<db user password> host=<db host> port=<db port> database=<db name>"'
exit 1
echo 'Missing DATABASE_URL'
echo 'example -e DATABASE_URL="user=<db user> password=<db user password> host=<db host> port=<db port> database=<db name>"'
exit 1
fi

trap shutdown INT

function shutdown() {
pkill -SIGINT postgresql-prometheus-adapter
pkill -SIGINT postgresql-prometheus-adapter
}

adapter_send_timeout=${adapter_send_timeout:-'30s'}
Expand All @@ -23,27 +23,26 @@ pg_commit_rows=${pg_commit_rows:-20000}
pg_threads="${pg_threads:-1}"
parser_threads="${parser_threads:-5}"

echo /postgresql-prometheus-adapter \
--adapter-send-timeout=${adapter_send_timeout} \
--web-listen-address=${web_listen_address} \
--web-telemetry-path=${web_telemetry_path} \
--log.level=${log_level} \
--log.format=${log_format} \
--pg-partition=${pg_partition} \
--pg-commit-secs=${pg_commit_secs} \
--pg-commit-rows=${pg_commit_rows} \
--pg-threads=${pg_threads} \
--parser-threads=${parser_threads}

/postgresql-prometheus-adapter \
--adapter-send-timeout=${adapter_send_timeout} \
--web-listen-address=${web_listen_address} \
--web-telemetry-path=${web_telemetry_path} \
--log.level=${log_level} \
--log.format=${log_format} \
--pg-partition=${pg_partition} \
--pg-commit-secs=${pg_commit_secs} \
--pg-commit-rows=${pg_commit_rows} \
--pg-threads=${pg_threads} \
--parser-threads=${parser_threads}
echo /source/postgresql-prometheus-adapter \
--adapter-send-timeout=${adapter_send_timeout} \
--web-listen-address=${web_listen_address} \
--web-telemetry-path=${web_telemetry_path} \
--log.level=${log_level} \
--log.format=${log_format} \
--pg-partition=${pg_partition} \
--pg-commit-secs=${pg_commit_secs} \
--pg-commit-rows=${pg_commit_rows} \
--pg-threads=${pg_threads} \
--parser-threads=${parser_threads}

/source/postgresql-prometheus-adapter \
--adapter-send-timeout=${adapter_send_timeout} \
--web-listen-address=${web_listen_address} \
--web-telemetry-path=${web_telemetry_path} \
--log.level=${log_level} \
--log.format=${log_format} \
--pg-partition=${pg_partition} \
--pg-commit-secs=${pg_commit_secs} \
--pg-commit-rows=${pg_commit_rows} \
--pg-threads=${pg_threads} \
--parser-threads=${parser_threads}