Skip to main content
pb-ext includes comprehensive system monitoring that collects and displays real-time metrics for CPU usage, memory consumption, disk space, network activity, and Go runtime statistics.

Key Features

  • CPU metrics — per-core usage and average utilization
  • Memory tracking — total, used, free, and cache/buffer breakdown
  • Disk monitoring — space usage and read/write statistics
  • Network stats — interface information, connections, and throughput
  • Runtime metrics — goroutines, heap allocation, GC statistics
  • Temperature sensors — CPU, disk, and system temperatures (if available)
  • Request tracking — rate, duration, and status code distribution
  • Smart caching — 2-second refresh interval to reduce overhead

System Metrics Collection

From core/monitoring/stats.go:47:

SystemStats Structure

From core/monitoring/stats.go:18:

CPU Monitoring

From core/monitoring/cpu.go:

Memory Monitoring

From core/monitoring/memory.go:

Disk Monitoring

From core/monitoring/disk.go:

Network Monitoring

From core/monitoring/network.go:

Runtime Monitoring

From core/monitoring/runtime.go:

Request Tracking

From core/monitoring/requests.go:

Server Stats Access

From core/server/server.go:

Temperature Monitoring

From core/monitoring/temperature.go:

Smart Caching

From core/monitoring/stats.go:13:
Metrics are cached for 2 seconds to reduce CPU overhead from frequent collection.

Usage Example

Dashboard Integration

View real-time metrics in the pb-ext dashboard at /_/_:
  • System Health — CPU, memory, disk usage gauges
  • Network Activity — bytes sent/received, active connections
  • Runtime Metrics — goroutines, heap allocation, GC stats
  • Request Statistics — request rate, average response time
  • Temperature Sensors — CPU, disk, and system temperatures (if available)
  • Uptime — server start time and duration

Error Handling

From core/monitoring/errors.go:

Best Practices

  1. Use context timeouts (5 seconds recommended) to prevent hangs
  2. Handle partial errors — some metrics may fail while others succeed
  3. Leverage caching — don’t collect stats more than once per 2 seconds
  4. Monitor goroutine count — watch for leaks
  5. Track request rate — use for auto-scaling decisions
  6. Set up alerts — trigger notifications on high CPU/memory usage
  7. Check temperature data — not all systems provide sensor information

Performance Impact

  • CPU overhead: ~0.5% per collection (cached)
  • Memory overhead: ~50KB for cached stats
  • Collection time: 10-50ms (with caching: <1ms)
  • Goroutines: +1 for analytics session cleanup