mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 03:42:27 +03:00
Added prometheus and grafana services to docker compose (#21213)
ref
https://linear.app/tryghost/issue/ENG-1591/add-prometheus-and-grafana-services-to-docker-compose
This commit adds 2 new services to the docker compose file to enable
monitoring metrics from Ghost locally in real-time:
1. Prometheus - a service that scrapes Ghost's new `/metrics` endpoint
introduced in this
[commit](768336efad
).
2. Grafana - a service that consumes the metrics from prometheus and
exposes them in a dashboard that you can view locally at
`localhost:3000`.
# Usage
Both of these services are selectively enabled using docker compose
[profiles](https://docs.docker.com/compose/how-tos/profiles/). This way,
if you don't opt-in to using these monitoring tools, they won't start
and consume resources on your host machine. To enable these services,
enable the `monitoring` profile by either setting the `COMPOSE_PROFILES`
environment variable to `monitoring`, or specifying the `--profile
monitoring` CLI argument to any `docker compose ...` commands.
I've found the easiest way to configure this in an 'always on' fashion
is to create a `.env` file in the project's root directory and add
`COMPOSE_PROFILES=monitoring` to it. As an added convenience, you can
also set `COMPOSE_FILE=.github/scripts/docker-compose.yml`, which will
allow you to run `docker compose ...` commands from the root directory
without specifying the full path each time.
# Intended for development only
These services are meant for local development only, and are not
configured for a production use-case. For example, the Grafana instance
is configured to have _no authorization_ so you won't need a
username/password to login at `localhost:3000`. Prometheus is also
configured to scrape the metrics once every second, which is likely
excessive for production use-cases, but may be useful for getting more
granular metrics while e.g. load testing locally.
# Dashboards
The Grafana instance includes a default dashboard including most of the
main default metrics provided by our prometheus client integration. The
dashboard is defined in a JSON file at
`.github/scripts/docker/grafana/dashboards/main-dashboard.json' and can
be modified & committed to add new visualizations that will be available
to anyone work on Ghost locally. You can also add other dashboards to
the same directory for specific use-cases, which should be picked up and
made available in the Grafana UI. [Read
more](https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/view-dashboard-json-model/)
about Grafana's JSON schema for dashboards.
This commit is contained in:
parent
77ab8baa82
commit
8b26b52513
22
.github/scripts/docker-compose.yml
vendored
22
.github/scripts/docker-compose.yml
vendored
@ -28,5 +28,27 @@ services:
|
||||
ports:
|
||||
- "6379:6379"
|
||||
restart: always
|
||||
prometheus:
|
||||
profiles: [monitoring]
|
||||
image: prom/prometheus:v2.30.3
|
||||
container_name: ghost-prometheus
|
||||
ports:
|
||||
- "9090:9090"
|
||||
restart: always
|
||||
volumes:
|
||||
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
|
||||
grafana:
|
||||
profiles: [monitoring]
|
||||
image: grafana/grafana:8.2.3
|
||||
container_name: ghost-grafana
|
||||
ports:
|
||||
- "3000:3000"
|
||||
restart: always
|
||||
environment:
|
||||
- GF_AUTH_ANONYMOUS_ENABLED=true
|
||||
volumes:
|
||||
- ./grafana/datasources:/etc/grafana/provisioning/datasources
|
||||
- ./grafana/dashboard.yml:/etc/grafana/provisioning/dashboards/main.yaml
|
||||
- ./grafana/dashboards:/var/lib/grafana/dashboards
|
||||
volumes:
|
||||
mysql-data:
|
||||
|
15
.github/scripts/grafana/dashboard.yml
vendored
Normal file
15
.github/scripts/grafana/dashboard.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
## This file is used to point to the folder where the dashboards are stored
|
||||
## To edit or create a dashboard, add a .json file to the ./dashboards folder
|
||||
|
||||
apiVersion: 1
|
||||
|
||||
providers:
|
||||
- name: "Dashboard provider"
|
||||
orgId: 1
|
||||
type: file
|
||||
disableDeletion: false
|
||||
updateIntervalSeconds: 10
|
||||
allowUiUpdates: false
|
||||
options:
|
||||
path: /var/lib/grafana/dashboards
|
||||
foldersFromFilesStructure: true
|
1634
.github/scripts/grafana/dashboards/main-dashboard.json
vendored
Normal file
1634
.github/scripts/grafana/dashboards/main-dashboard.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
9
.github/scripts/grafana/datasources/datasource.yml
vendored
Normal file
9
.github/scripts/grafana/datasources/datasource.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
apiVersion: 1
|
||||
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
type: prometheus
|
||||
url: http://prometheus:9090
|
||||
isDefault: true
|
||||
access: proxy
|
||||
editable: true
|
31
.github/scripts/prometheus/prometheus.yml
vendored
Normal file
31
.github/scripts/prometheus/prometheus.yml
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
global:
|
||||
scrape_interval: 15s # By default, scrape targets every 15 seconds.
|
||||
|
||||
# Attach these labels to any time series or alerts when communicating with
|
||||
# external systems (federation, remote storage, Alertmanager).
|
||||
external_labels:
|
||||
monitor: 'codelab-monitor'
|
||||
|
||||
# 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']
|
||||
|
||||
- job_name: 'ghost'
|
||||
|
||||
scrape_interval: 1s
|
||||
|
||||
static_configs:
|
||||
- targets: ['host.docker.internal:9416']
|
||||
|
||||
metrics_path: '/metrics'
|
||||
|
||||
remote_write:
|
||||
- url: http://grafana:3000/api/prom/push
|
Loading…
Reference in New Issue
Block a user