This commit is contained in:
fix 2021-03-02 20:52:56 +01:00
parent a57b737179
commit fd99b98800
5 changed files with 88 additions and 5 deletions

2
.env.dist Normal file
View File

@ -0,0 +1,2 @@
PROMETHEUS_CONFIG_FILE_PATH=/path/to/prometheus/config/prometheus.yaml
PROMETHEUS_DATA_PATH=/path/to/prometheus/data

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.env
.prometheus.yaml

View File

@ -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/ '

19
docker-compose.yaml Normal file
View File

@ -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

58
prometheus.yaml.dist Normal file
View File

@ -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']