Class MetricsPersistenceService
java.lang.Object
com.nmontytskyi.monitoring.server.service.MetricsPersistenceService
Core service responsible for persisting incoming metric snapshots and triggering
real-time anomaly detection for every saved record.
For each inbound MetricSnapshotRequest
the service:
- Maps the request to a
MetricRecordEntityand persists it. - Fetches the 100 most recent records for the same service to build a historical baseline.
- Delegates to
AnomalyDetectorfor Z-score computation; updatesanomalyandzScorefields when sufficient history is available (≥ 10 records). - Triggers alert evaluation via
AlertEvaluationService.
- Author:
- Nazar Montytskyi
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAggregate(Long serviceId, LocalDateTime from, LocalDateTime to) saveBatch(List<MetricSnapshotRequest> requests) Saves a batch of metric snapshots in a single transaction.saveEndpointSnapshot(MetricSnapshotRequest request, MetricRecordEntity.MetricSource source)
-
Constructor Details
-
MetricsPersistenceService
public MetricsPersistenceService()
-
-
Method Details
-
saveEndpointSnapshot
-
saveEndpointSnapshot
@Transactional public MetricRecordResponse saveEndpointSnapshot(MetricSnapshotRequest request, MetricRecordEntity.MetricSource source) -
saveBatch
Saves a batch of metric snapshots in a single transaction. Alert evaluation runs for each record individually. -
getLatest
-
getAggregate
@Transactional(readOnly=true) public AggregateMetricsResponse getAggregate(Long serviceId, LocalDateTime from, LocalDateTime to)
-