Skip to content

Commit

Permalink
feat:setup prometheus and grafana to run on the local host and config…
Browse files Browse the repository at this point in the history
…ured promethus diasboard
  • Loading branch information
Tekum-Emmanuella committed Jan 9, 2025
1 parent 50549d1 commit 2d5eba8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 51 deletions.
3 changes: 1 addition & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ SERVER_PUBLIC_DOMAIN="http://didcomm-mediator.com"
SERVER_LOCAL_PORT="8080"
STORAGE_DIRPATH="crates/generic-server/target/storage"
MONGO_DBN="mediator-coordination"


MONGO_URI="mongodb://localhost:27017"
17 changes: 13 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ services:
- grafana
networks:
- mediator-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3

# MongoDB Service
mongodb:
Expand All @@ -33,7 +38,7 @@ services:

# Prometheus Service
prometheus:
image: prom/prometheus latest
image: prom/prometheus:latest
container_name: prometheus
ports:
- "9091:9090" # Prometheus web interface
Expand All @@ -44,16 +49,20 @@ services:
- mediator-network
restart: unless-stopped

# Grafana Service
# Grafana Service with Anonymous Access Enabled
grafana:
image: grafana/grafana latest
image: grafana/grafana:latest
container_name: grafana
ports:
- "3001:3000" # Expose Grafana web interface on port 3001
depends_on:
- prometheus
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin # Set Grafana admin password
- GF_SECURITY_ADMIN_PASSWORD=admin # Set admin password (optional, can be removed)
- GF_AUTH_ANONYMOUS_ENABLED=true # Enable anonymous access
- GF_AUTH_ANONYMOUS_ORG_NAME="Main Org." # Specify organization name for anonymous users
- GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer # Set role for anonymous users (e.g., Viewer)
- GF_AUTH_DISABLE_LOGIN_FORM=true # Disable the login form (optional)
networks:
- mediator-network
restart: unless-stopped
Expand Down
14 changes: 11 additions & 3 deletions prometheus.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# Prometheus configuration file
global:
scrape_interval: 15s # Scrape every 15 seconds
evolution_interval: 30s

scrape_configs:
- job_name: 'didcomm-mediator'
honor_labels: true # Fixed indentation and spelling
static_configs:
- targets: ['mediator:9100'] # Scrape the metrics from the mediator service
- targets:
- 'didcomm-mediator:9100' # Scrape the metrics from the mediator service

- job_name: 'mongodb'
static_configs:
- targets: ['mongodb:27017']

- job_name: 'node-exporter'
static_configs:
- targets: ['node-exporter:9100']
38 changes: 0 additions & 38 deletions src/health_metrics.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod plugins;
mod health_metrics;

use axum::Router;
use eyre::{eyre, Result};
Expand Down
14 changes: 11 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ async fn generic_server_with_graceful_shutdown(
// Load plugins and get the application router
let (mut plugin_container, app_router) = app()?;

// Add a `/metrics` route
// Add a `/health` route for health checks
let health_router = Router::new().route("/health", get(health_check));

// Add a `/metrics` route for Prometheus metrics
let metrics_router = Router::new().route(
"/metrics",
get({
Expand All @@ -50,8 +53,8 @@ async fn generic_server_with_graceful_shutdown(
}),
);

// Combine the app router with the metrics router
let app_router = app_router.merge(metrics_router);
// Combine the app router with the health and metrics routers
let app_router = app_router.merge(health_router).merge(metrics_router);

// Run the server
Server::bind(&addr)
Expand All @@ -73,6 +76,11 @@ async fn generic_server_with_graceful_shutdown(
Ok(())
}

/// Health check handler
async fn health_check() -> String {
String::from("{\"status\": \"healthy\"}")
}

/// Expose Prometheus metrics
async fn metrics_handler(registry: Arc<Mutex<Registry>>) -> String {
let registry = registry.lock().await;
Expand Down

0 comments on commit 2d5eba8

Please sign in to comment.