mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-20 00:25:02 +01:00
This is a large-scale refactoring across the codebase that replaces the custom `gperr.Error` type with Go's standard `error` interface. The changes include: - Replacing `gperr.Error` return types with `error` in function signatures - Using `errors.New()` and `fmt.Errorf()` instead of `gperr.New()` and `gperr.Errorf()` - Using `%w` format verb for error wrapping instead of `.With()` method - Replacing `gperr.Subject()` calls with `gperr.PrependSubject()` - Converting error logging from `gperr.Log*()` functions to zerolog's `.Err().Msg()` pattern - Update NewLogger to handle multiline error message - Updating `goutils` submodule to latest commit This refactoring aligns with Go idioms and removes the dependency on custom error handling abstractions in favor of standard library patterns.
Metrics Package
System monitoring and metrics collection for GoDoxy with time-series storage and REST/WebSocket APIs.
Overview
This package provides a unified metrics collection system that:
- Polls system and route data at regular intervals
- Stores historical data across multiple time periods
- Exposes both REST and WebSocket APIs for consumption
Primary Consumers
internal/api/v1/metrics/- REST API endpoints- WebUI - Real-time charts
internal/metrics/uptime/- Route health monitoring
Non-goals
- Metric aggregation from external sources
- Alerting (handled by
internal/notif/) - Long-term storage (30-day retention only)
Stability
Internal package. See internal/metrics/period/README.md for the core framework documentation.
Packages
period/
Generic time-bucketed metrics storage framework with:
Period[T]- Multi-timeframe containerPoller[T, A]- Background data collectorEntries[T]- Circular buffer for time-series data
See period/README.md for full documentation.
uptime/
Route health status monitoring using the period framework.
systeminfo/
System metrics collection (CPU, memory, disk, network, sensors) using the period framework.
Architecture
graph TB
subgraph "Data Sources"
SI[SystemInfo Poller]
UP[Uptime Poller]
end
subgraph "Period Framework"
P[Period<T> Generic]
E[Entries<T> Ring Buffer]
PL[Poller<T, A> Orchestrator]
H[Handler HTTP API]
end
subgraph "Storage"
JSON[(data/metrics/*.json)]
end
P --> E
PL --> P
PL --> SI
PL --> UP
H --> PL
PL --> JSON
Configuration Surface
No explicit configuration. Pollers respect common.MetricsDisable* flags:
| Flag | Disables |
|---|---|
MetricsDisableCPU |
CPU percentage collection |
MetricsDisableMemory |
Memory statistics |
MetricsDisableDisk |
Disk usage and I/O |
MetricsDisableNetwork |
Network counters |
MetricsDisableSensors |
Temperature sensors |
Dependency and Integration Map
Internal Dependencies
github.com/yusing/goutils/task- Lifetime managementinternal/types- Health check types
External Dependencies
github.com/shirou/gopsutil/v4- System metrics collectiongithub.com/puzpuzpuz/xsync/v4- Atomic value storagegithub.com/bytedance/sonic- JSON serialization
Observability
Logs
| Level | When |
|---|---|
Debug |
Poller start, data load/save |
Error |
Data source failures (aggregated every 30s) |
Failure Modes and Recovery
| Failure Mode | Impact | Recovery |
|---|---|---|
| Data source timeout | Missing data point | Logged, aggregated, continues |
| Disk read failure | No historical data | Starts fresh, warns |
| Disk write failure | Data loss on restart | Continues, retries next interval |
| Memory allocation failure | OOM risk | Go runtime handles |