From fd99b9880057822b3f716802f97d2890abd5030a Mon Sep 17 00:00:00 2001 From: fix Date: Tue, 2 Mar 2021 20:52:56 +0100 Subject: [PATCH] init --- .env.dist | 2 ++ .gitignore | 2 ++ Dockerfile | 12 +++++---- docker-compose.yaml | 19 +++++++++++++++ prometheus.yaml.dist | 58 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 .env.dist create mode 100644 .gitignore create mode 100644 docker-compose.yaml create mode 100644 prometheus.yaml.dist diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..1d6b6a7 --- /dev/null +++ b/.env.dist @@ -0,0 +1,2 @@ +PROMETHEUS_CONFIG_FILE_PATH=/path/to/prometheus/config/prometheus.yaml +PROMETHEUS_DATA_PATH=/path/to/prometheus/data diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7091a99 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +.prometheus.yaml diff --git a/Dockerfile b/Dockerfile index de694d3..ac8aa68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -ARG GO_VERSION=1.16.0 +ARG GO_VERSION=alpine -FROM golang:${GO_VERSION}-alpine as build +FROM golang:${GO_VERSION} as build ARG PROMETHEUS_VERSION= ARG PROMETHEUS_REPO="https://github.com/prometheus/prometheus.git" @@ -33,11 +33,13 @@ RUN \ FROM alpine:3 COPY --from=build /prometheus/prometheus /prometheus +RUN mkdir /data ENV UID=1000 ENV GID=1000 -CMD addgroup -g "${GID}" prometheus && \ - adduser -D -u "${UID}" -G prometheus prometheus && \ +CMD (grep -qE '^prometheus:x:'"${UID}"':prometheus$' /etc/group || addgroup -g "${GID}" prometheus) && \ + (grep -qE '^prometheus:x:'"${UID}"':'"${GID}"':.*$' /etc/passwd || adduser -D -u "${UID}" -G prometheus prometheus) && \ chmod 700 /prometheus && chown prometheus:prometheus /prometheus && \ - su prometheus -c '/prometheus --config.file=/config/prometheus.yml' + chown prometheus:prometheus /data && \ + su prometheus -c '/prometheus --config.file=/config/prometheus.yaml --storage.tsdb.path=/data/ ' diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..efcbe09 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,19 @@ +version: '3' + +services: + prometheus: + build: + context: ./ + container_name: prometheus + image: prometheus:local + logging: + driver: journald + options: + tag: pdns-recursor + restart: unless-stopped + ports: + - 9090:9090 + volumes: + - ${PROMETHEUS_CONFIG_FILE_PATH}:/config/prometheus.yaml:ro + - ${PROMETHEUS_DATA_PATH}:/data:rw + diff --git a/prometheus.yaml.dist b/prometheus.yaml.dist new file mode 100644 index 0000000..8add010 --- /dev/null +++ b/prometheus.yaml.dist @@ -0,0 +1,58 @@ +global: + scrape_interval: 60s + evaluation_interval: 60s + scrape_timeout: 60s + + external_labels: + monitor: 'codelab-monitor' + +rule_files: + # - "first.rules" + # - "second.rules" + +scrape_configs: + - job_name: 'prometheus' + + static_configs: + - targets: ['127.0.0.1:9090'] + + - job_name: 'netdata-one' + + metrics_path: '/api/v1/allmetrics' + params: + # format: prometheus | prometheus_all_hosts + # You can use `prometheus_all_hosts` if you want Prometheus to set the `instance` to your hostname instead of IP + format: [prometheus_all_hosts] + # + # sources: as-collected | raw | average | sum | volume + # default is: average + source: [as-collected] + # + # server name for this prometheus - the default is the client IP + # for Netdata to uniquely identify it + server: ['one.example.com'] + honor_labels: true + + static_configs: + - targets: ['10.0.0.1:19999'] + + - job_name: 'netdata-two' + + metrics_path: '/api/v1/allmetrics' + params: + # format: prometheus | prometheus_all_hosts + # You can use `prometheus_all_hosts` if you want Prometheus to set the `instance` to your hostname instead of IP + format: [prometheus_all_hosts] + # + # sources: as-collected | raw | average | sum | volume + # default is: average + source: [as-collected] + # + # server name for this prometheus - the default is the client IP + # for Netdata to uniquely identify it + server: ['two.example.com'] + honor_labels: true + + static_configs: + - targets: ['10.0.0.2:19999'] +