Class MetricsPersistenceService

java.lang.Object
com.nmontytskyi.monitoring.server.service.MetricsPersistenceService

@Service public class MetricsPersistenceService extends Object
Core service responsible for persisting incoming metric snapshots and triggering real-time anomaly detection for every saved record.

For each inbound MetricSnapshotRequest the service:

  1. Maps the request to a MetricRecordEntity and persists it.
  2. Fetches the 100 most recent records for the same service to build a historical baseline.
  3. Delegates to AnomalyDetector for Z-score computation; updates anomaly and zScore fields when sufficient history is available (≥ 10 records).
  4. Triggers alert evaluation via AlertEvaluationService.
Author:
Nazar Montytskyi
See Also: