Skip to main content

Monitoring Guide

Monitor your Bellamy Book installation for health and performance.

Health Checks

API Health Endpoint

curl http://localhost:5000/health

Response:

{
"status": "healthy",
"database": "connected",
"redis": "connected",
"mongodb": "connected"
}

Frontend Health

curl http://localhost:3000

Application Metrics

Key Metrics to Monitor

  • Response Times: API endpoint response times
  • Error Rates: 4xx and 5xx error rates
  • Request Rates: Requests per second
  • Database Performance: Query times, connection pool usage
  • Cache Hit Rates: Redis cache effectiveness
  • Storage Usage: Disk space for uploads

Logging

Backend Logs

Systemd

sudo journalctl -u bellamy-book-backend -f

Docker

docker-compose logs -f backend

Frontend Logs

docker-compose logs -f frontend

Log Levels

Configure in appsettings.json:

{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

Database Monitoring

PostgreSQL

-- Active connections
SELECT count(*) FROM pg_stat_activity;

-- Slow queries
SELECT * FROM pg_stat_statements
ORDER BY total_time DESC
LIMIT 10;

-- Database size
SELECT pg_size_pretty(pg_database_size('bellamybook'));

MongoDB

// Database stats
db.stats()

// Server status
db.serverStatus()

// Current operations
db.currentOp()

Redis

redis-cli INFO stats
redis-cli INFO memory

Performance Monitoring

Application Insights

Add Application Insights to backend:

services.AddApplicationInsightsTelemetry();

Custom Metrics

Track custom metrics:

_metrics.IncrementCounter("posts.created");
_metrics.RecordGauge("active.users", activeUserCount);
_metrics.RecordHistogram("api.response_time", responseTime);

Alerting

Set Up Alerts

Monitor for:

  • High error rates (> 5%)
  • Slow response times (> 1 second)
  • Database connection failures
  • Disk space low (< 20% free)
  • High memory usage (> 80%)

Alert Examples

Prometheus Alert

groups:
- name: bellamy-book
rules:
- alert: HighErrorRate
expr: rate(http_requests_total{status=~"5.."}[5m]) > 0.05
for: 5m
annotations:
summary: "High error rate detected"

Uptime Monitoring

External Monitoring

Use services like:

  • UptimeRobot
  • Pingdom
  • StatusCake

Monitor endpoints:

  • API health: /health
  • Frontend: /
  • Admin panel: /admin

Resource Monitoring

CPU and Memory

# System resources
htop

# Docker resources
docker stats

Disk Usage

df -h
du -sh /var/www/uploads

Log Aggregation

ELK Stack

Set up Elasticsearch, Logstash, and Kibana:

services:
elasticsearch:
image: elasticsearch:7.17.0
logstash:
image: logstash:7.17.0
kibana:
image: kibana:7.17.0

Loki

Use Grafana Loki for log aggregation:

services:
loki:
image: grafana/loki:latest
promtail:
image: grafana/promtail:latest

Dashboard

Grafana Dashboard

Create dashboards for:

  • API metrics
  • Database performance
  • System resources
  • User activity

Next Steps