Skip to content

Commit

Permalink
add prometheus/grafana monitoring/analytics setup
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Mar 29, 2024
1 parent 29f02b8 commit b77c306
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ up:
docker compose $(DOCKER_COMPOSE_ARGS) up --detach

dev:
docker compose $(DOCKER_COMPOSE_ARGS) --file docker-compose.dev.yml up --detach
docker compose $(DOCKER_COMPOSE_ARGS) --file docker-compose.dev.yml up

login:
docker exec -it wis2-gdc-management /bin/bash
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ wis2-gdc is a Reference Implementation of a WIS2 Global Discovery Catalogue.
- [OGC API - Features - Part 4: Create, Replace, Update and Delete](https://docs.ogc.org/DRAFTS/20-002.html)
- Elasticsearch direct (default)
- collect real-time and offline GDC metrics and make them available as [OpenMetrics](https://openmetrics.io)
- produce a metadata zipfile for download (daily)
- provide analytics and visualization via [Prometheus](https://prometheus.io) and [Grafana](https://grafana.com)
- produce a metadata zipfile archive for download (daily)

## Installation

Expand Down Expand Up @@ -85,7 +86,10 @@ wis2-gdc archive foo.zip
The Docker setup uses Docker and Docker Compose to manage the following services:

- **wis2-gdc-api**: GDC API powered by [pygeoapi](https://pygeoapi.io)
- **wis2-gdc-metrics-collector**: GDC metrics collector
- **wis2-gdc-monitoring**: GDC monitoring
- **metrics-collector**: GDC metrics collector
- **prometheus**: metrics scraper
- **grafana**: analytics and visualization
- **wis2-gdc-broker**: MQTT broker
- **wis2-gdc-management**: management service to ingest, validate and publish discovery metadata published from a WIS2 Global Broker instance
- the default Global Broker connection is to Météo-France. This can be modified in `wis2-gdc.env` to point to a different Global Broker
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ services:
wis2-gdc-api:
ports:
- 80:80
grafana:
ports:
- 3000:3000
32 changes: 31 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,36 @@ services:
networks:
- wis2-gdc-net

prometheus:
image: prom/prometheus
volumes:
- ./wis2-gdc-monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
networks:
- wis2-gdc-net

grafana:
image: grafana/grafana-oss
container_name: grafana
env_file:
- wis2-gdc.env
networks:
- wis2-gdc-net
volumes:
- ./wis2-gdc-monitoring/grafana/datasource.yml:/etc/grafana/provisioning/datasources/grafana-datasource.yml
environment:
- GF_SECURITY_ADMIN_USER=${GRAFANA_ADMIN_USER:-admin}
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD:-admin}
- GF_USERS_ALLOW_SIGN_UP=false
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_HIDE_VERSION=true
- GF_ANALYTICS_CHECK_FOR_UPDATES=false
- GF_USERS_VIEWERS_CAN_EDIT=true
- GF_UNIFIED_ALERTING_ENABLED=false
- GF_ALERTING_ENABLED=true
- GF_USERS_DEFAULT_THEME=dark
- GF_DISABLE_SIGNOUT_MENU=true
- GF_SERVER_SERVE_FROM_SUB_PATH=true

wis2-gdc-broker:
container_name: wis2-gdc-broker
restart: always
Expand All @@ -64,7 +94,7 @@ services:
container_name: wis2-gdc-metrics-collector
restart: unless-stopped
build:
context: ./wis2-gdc-metrics-collector/
context: ./wis2-gdc-monitoring/metrics-collector/
env_file:
- wis2-gdc.env
networks:
Expand Down
Binary file modified docs/architecture/c4.container.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion wis2-gdc-management/wis2_gdc/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def str2bool(value: Any) -> bool:
BROKER_URL = os.environ.get('WIS2_GDC_BROKER_URL')
CENTRE_ID = os.environ.get('WIS2_GDC_CENTRE_ID')
GB = os.environ.get('WIS2_GDC_GB')
GB_CENTRE_ID = None
GB_TOPIC = os.environ.get('WIS2_GDC_GB_TOPIC')
PUBLISH_REPORTS = str2bool(os.environ.get('WIS2_GDC_PUBLISH_REPORTS', 'false'))
REJECT_ON_FAILING_ETS = str2bool(os.environ.get('WIS2_GDC_REJECT_ON_FAILING_ETS', 'true')) # noqa
Expand All @@ -63,4 +64,7 @@ def str2bool(value: Any) -> bool:

for key, value in os.environ.items():
if key.startswith('WIS2_GDC_GB_LINK'):
GB_LINKS.append(value.rsplit(',', 1))
centre_id, url, title = value.rsplit(',', 2)
if GB == url:
GB_CENTRE_ID = centre_id
GB_LINKS.append(value.split(',', 2))
2 changes: 1 addition & 1 deletion wis2-gdc-management/wis2_gdc/registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def is_wis2_mqtt_link(link) -> bool:

for gb_link in GB_LINKS:
gb_link_to_add = deepcopy(new_link)
title = f'Notifications from {gb_link[0]} Global Broker'
title = f'Notifications from {gb_link[2]} ({gb_link[0]})'
gb_link_to_add['title'] = title
gb_link_to_add['href'] = gb_link[1]

Expand Down
7 changes: 7 additions & 0 deletions wis2-gdc-monitoring/grafana/datasource.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: 1

datasources:
- name: wis2-gdc-prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
BROKER_URL = os.environ['WIS2_GDC_BROKER_URL']
CENTRE_ID = os.environ['WIS2_GDC_CENTRE_ID']
CENTRE_ID_CSV = os.environ['WIS2_GDC_CENTRE_ID_CSV']
GB = urlparse(os.environ['WIS2_GDC_GB'])
GB = os.environ['WIS2_GDC_GB']
GB_TOPIC = os.environ['WIS2_GDC_GB_TOPIC']
HTTP_PORT = 8006
LOGGING_LEVEL = os.environ['WIS2_GDC_LOGGING_LEVEL']
Expand Down Expand Up @@ -123,21 +123,37 @@
)


def get_gb_centre_id() -> str:
"""
Derive GB centre id from WIS2_GDC_GB_LINK environment variables
:returns: centre-id of matching GB
"""

for key, value in os.environ.items():
if key.startswith('WIS2_GDC_GB_LINK'):
centre_id, url, title = value.split(',', 2)
if GB == url:
return centre_id


def init_metrics() -> None:
"""
Initializes metrics on startup
:returns: `None`
"""

gb_centre_id = get_gb_centre_id()

METRIC_INFO.info({
'centre_id': CENTRE_ID,
'url': API_URL,
'subscribed_to': f'{GB.scheme}://{GB.hostname}:{GB.port} (topic: {GB_TOPIC})' # noqa
'subscribed_to': f'{gb_centre_id}'
})

METRIC_CONNECTED_FLAG.labels(
centre_id=GB.hostname, report_by=CENTRE_ID).inc(1)
centre_id=gb_centre_id, report_by=CENTRE_ID).inc(1)

with open(CENTRE_ID_CSV) as fh:
reader = csv.DictReader(fh)
Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions wis2-gdc-monitoring/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
global:
scrape_interval: 10s

scrape_configs:
- job_name: prometheus
static_configs:
- targets:
- prometheus:9090
- job_name: 'wis2-gdc-metrics-collector'
static_configs:
- targets:
- 'wis2-gdc-metrics-collector:8006'
8 changes: 4 additions & 4 deletions wis2-gdc.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export WIS2_GDC_REJECT_ON_FAILING_ETS=false
export WIS2_GDC_RUN_KPI=true

# global broker links
export WIS2_GDC_GB_LINK_METEOFRANCE="Météo-France,mqtts://everyone:everyone@globalbroker.meteo.fr:8883"
export WIS2_GDC_GB_LINK_CMA="China Meteorological Agency,mqtts://everyone:everyone@gb.wis.cma.cn:8883"
export WIS2_GDC_GB_LINK_NOAA="National Oceanic and Atmospheric Administration, National Weather Service, Global Broker Service,mqtts://everyone:everyone@wis2globalbroker.nws.noaa.gov:8883"
export WIS2_GDC_GB_LINK_INMET="Instituto Nacional de Meteorologia, Global Broker Service,mqtts://everyone:everyone@globalbroker.inmet.gov.br:8883"
export WIS2_GDC_GB_LINK_METEOFRANCE="fr-meteo-france-global-broker,mqtts://everyone:everyone@globalbroker.meteo.fr:8883,Météo-France, Global Broker Service"
export WIS2_GDC_GB_LINK_CMA="cn-cma-globalbroker,mqtts://everyone:everyone@gb.wis.cma.cn:8883,China Meteorological Agency, Global Broker Service"
export WIS2_GDC_GB_LINK_NOAA="us-noaa-nws-global-broker,mqtts://everyone:everyone@wis2globalbroker.nws.gov:8883,National Oceanic and Atmospheric Administration, National Weather Service, Global Broker Service"
export WIS2_GDC_GB_LINK_INMET="br-inmet-global-broker,mqtts://everyone:everyone@globalbroker.inmet.gov.br:8883,Instituto Nacional de Meteorologia, Global Broker Service"

0 comments on commit b77c306

Please sign in to comment.