diff --git a/Dockerfile b/Dockerfile index c506d3c..bcc1a02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,12 @@ -FROM centos:7 +FROM golang:alpine -MAINTAINER Yogesh Sharma +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"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..29bf329 --- /dev/null +++ b/docker-compose.yml @@ -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 diff --git a/makefile b/makefile index f8f20f5..619adc1 100644 --- a/makefile +++ b/makefile @@ -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 diff --git a/prometheus.yml b/prometheus.yml new file mode 100644 index 0000000..d4c1b73 --- /dev/null +++ b/prometheus.yml @@ -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=` 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" diff --git a/start.sh b/start.sh index 721f016..6d492db 100755 --- a/start.sh +++ b/start.sh @@ -1,15 +1,15 @@ #!/bin/bash if [[ "${DATABASE_URL}" == "" ]]; then - echo 'Missing DATABASE_URL' - echo 'example -e DATABASE_URL="user= password= host= port= database="' - exit 1 + echo 'Missing DATABASE_URL' + echo 'example -e DATABASE_URL="user= password= host= port= database="' + 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'} @@ -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}