Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 9f7b0d0

Browse files
uwedeportivobeyang
authored andcommitted
monitoring: add postgres_exporter process to dev and single server (#6616)
* monitoring: add postgres_exporter process to dev and single server and postgres grafana dashboard * prettier * pin postgres_exporter docker image
1 parent ceb664d commit 9f7b0d0

File tree

9 files changed

+2003
-4
lines changed

9 files changed

+2003
-4
lines changed

cmd/server/Dockerfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,18 @@ RUN set -ex && \
6969
apk add --no-cache libc6-compat=1.1.24-r0 ca-certificates su-exec
7070

7171
# hadolint ignore=DL3022
72-
COPY --from=sourcegraph/grafana:10.0.4@sha256:ba3742bb63787d23664ace0b0b84e6e486d73c925f5870d92845f1f86eb7918d /usr/share/grafana /usr/share/grafana
72+
COPY --from=sourcegraph/grafana:10.0.5@sha256:bd332c36c5aa36942f502d8078e2b7d57eaf0fa945380fe43c30fcfc902f91bd /usr/share/grafana /usr/share/grafana
7373

7474
# hadolint ignore=DL3022
7575
COPY --from=libsqlite3-pcre /sqlite3-pcre/pcre.so /libsqlite3-pcre.so
7676
ENV LIBSQLITE3_PCRE /libsqlite3-pcre.so
7777
COPY . /
7878

7979
# hadolint ignore=DL3022
80-
COPY --from=sourcegraph/grafana:10.0.4@sha256:ba3742bb63787d23664ace0b0b84e6e486d73c925f5870d92845f1f86eb7918d /sg_config_grafana/provisioning/dashboards/sourcegraph/*json /sg_config_grafana/provisioning/dashboards/sourcegraph/
80+
COPY --from=sourcegraph/grafana:10.0.5@sha256:bd332c36c5aa36942f502d8078e2b7d57eaf0fa945380fe43c30fcfc902f91bd /sg_config_grafana/provisioning/dashboards/sourcegraph/*json /sg_config_grafana/provisioning/dashboards/sourcegraph/
81+
82+
# hadolint ignore=DL3022
83+
COPY --from=wrouesnel/postgres_exporter:v0.7.0@sha256:785c919627c06f540d515aac88b7966f352403f73e931e70dc2cbf783146a98b /postgres_exporter /usr/local/bin/postgres_exporter
8184

8285
RUN echo "hosts: files dns" > /etc/nsswitch.conf
8386

cmd/server/shared/shared.go

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func Main() {
141141
`syntect_server: sh -c 'env QUIET=true ROCKET_ENV=production ROCKET_PORT=9238 ROCKET_LIMITS='"'"'{json=10485760}'"'"' ROCKET_SECRET_KEY='"'"'SeerutKeyIsI7releuantAndknvsuZPluaseIgnorYA='"'"' ROCKET_KEEP_ALIVE=0 ROCKET_ADDRESS='"'"'"127.0.0.1"'"'"' syntect_server | grep -v "Rocket has launched" | grep -v "Warning: environment is"' | grep -v 'Configured for production'`,
142142
`prometheus: prometheus --config.file=/sg_config_prometheus/prometheus.yml --storage.tsdb.path=/var/opt/sourcegraph/prometheus --web.console.libraries=/usr/share/prometheus/console_libraries --web.console.templates=/usr/share/prometheus/consoles >> /var/opt/sourcegraph/prometheus.log 2>&1`,
143143
`grafana: /usr/share/grafana/bin/grafana-server -config /sg_config_grafana/grafana-single-container.ini -homepath /usr/share/grafana >> /var/opt/sourcegraph/grafana.log 2>&1`,
144+
`postgres_exporter: env DATA_SOURCE_NAME="postgresql://postgres:[email protected]:5432/postgres?sslmode=disable" postgres_exporter`,
144145
}
145146
procfile = append(procfile, ProcfileAdditions...)
146147

dev/Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ lsif-server: yarn --cwd lsif run run:server
2323
lsif-worker: yarn --cwd lsif run run:worker
2424
prometheus: ./dev/prometheus.sh
2525
grafana: ./dev/grafana.sh
26+
postgres_exporter: ./dev/postgres_exporter.sh

dev/grafana.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
99

1010
GRAFANA_DISK="${HOME}/.sourcegraph-dev/data/grafana"
1111

12-
IMAGE=sourcegraph/grafana:10.0.4
12+
IMAGE=sourcegraph/grafana:10.0.5
1313
CONTAINER=grafana
1414

1515
mkdir -p ${GRAFANA_DISK}/logs

dev/postgres_exporter.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
# Description: Prometheus collects metrics and aggregates them into graphs.
4+
#
5+
6+
set -euf -o pipefail
7+
8+
IMAGE=wrouesnel/postgres_exporter:v0.7.0@sha256:785c919627c06f540d515aac88b7966f352403f73e931e70dc2cbf783146a98b
9+
CONTAINER=postgres_exporter
10+
11+
NET_ARG=""
12+
DATA_SOURCE_NAME="postgresql://sourcegraph:[email protected]:5432/postgres?sslmode=disable"
13+
14+
if [[ "$OSTYPE" == "linux-gnu" ]]; then
15+
NET_ARG="--net=host"
16+
DATA_SOURCE_NAME="postgresql://sourcegraph:[email protected]:5432/postgres?sslmode=disable"
17+
fi
18+
19+
exec docker run --rm -p9187:9187 ${NET_ARG} --name=postgres_exporter -e DATA_SOURCE_NAME=${DATA_SOURCE_NAME} ${IMAGE}

dev/prometheus/all/prometheus_targets.yml

+6
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@
4444
targets:
4545
# lsif-worker
4646
- host.docker.internal:3187
47+
- labels:
48+
job: postgres_exporter
49+
targets:
50+
# postgres exporter
51+
- host.docker.internal:9187
52+

dev/prometheus/linux/prometheus_targets.yml

+5
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@
4444
targets:
4545
# lsif-worker
4646
- 127.0.0.1:3187
47+
- labels:
48+
job: postgres_exporter
49+
targets:
50+
# postgres exporter
51+
- 127.0.0.1:9187

0 commit comments

Comments
 (0)