metrics Package

Overview

Package metrics provides comprehensive business intelligence and analytics for the incident management platform.

This package implements the metrics collection and analysis system that transforms raw incident data into actionable business intelligence, performance indicators, and trend analysis. It serves as the foundation for incident management KPIs, SLA reporting, team performance analysis, and service reliability monitoring.

Key Features:

  • Comprehensive incident metrics calculation (MTTR, MTTA, volume analysis)
  • Team performance analytics with role-based reporting
  • Service reliability metrics and error budget tracking
  • Time-range comparisons and trend analysis
  • SLA compliance monitoring and reporting
  • Real-time metrics calculation with configurable time windows
  • Multi-dimensional data analysis (severity, service, team, time)
  • Statistical analysis including percentiles and distributions

Architecture:

The metrics system follows a multi-layered analytical approach:

┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│ Raw Events      │───►│ Metrics Engine   │───►│ Analytics Views │
│ (Timeline/SLA)  │    │ (Calculation)    │    │ (Dashboards)    │
└─────────────────┘    └──────────────────┘    └─────────────────┘
                                                      
┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│ Data Sources    │    │ Statistical      │    │ Trend Analysis  │
│ (Multi-table)   │    │ Processing       │    │ (Comparisons)   │
└─────────────────┘    └──────────────────┘    └─────────────────┘

Metric Categories:

  • Volume Metrics: Incident counts, breakdowns by severity/service/status
  • Time Metrics: MTTR, MTTA, resolution times, percentile analysis
  • SLA Metrics: Compliance rates, breach analysis, trend tracking
  • Team Metrics: Role assignments, workload distribution, performance
  • Service Metrics: Reliability scores, availability, error budgets
  • Comparative Metrics: Period-over-period analysis, trend identification

Example usage:

// Create metrics service
metricsService := metrics.NewService(db)

// Get comprehensive incident metrics
start := time.Now().AddDate(0, 0, -30) // Last 30 days
end := time.Now()
incidentMetrics, err := metricsService.GetIncidentMetrics(ctx, start, end)
if err != nil {
	log.Fatal(err)
}

// Analyze key performance indicators
fmt.Printf("Total Incidents: %d\n", incidentMetrics.TotalIncidents)
fmt.Printf("Mean Time to Resolve: %v\n", incidentMetrics.MTTR)
fmt.Printf("SLA Compliance: %.2f%%\n", incidentMetrics.SLACompliance*100)

// Get team performance metrics
teamMetrics, err := metricsService.GetTeamMetrics(ctx, start, end)
if err != nil {
	log.Fatal(err)
}

// Analyze service reliability
serviceReliability, err := metricsService.GetServiceReliability(ctx, "api-service", start, end)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Service Uptime: %.3f%%\n", serviceReliability.Uptime)

// Compare time periods
currentPeriod := TimeRange{Start: start, End: end}
previousPeriod := TimeRange{Start: start.AddDate(0, 0, -30), End: start}
comparison, err := metricsService.CompareTimeRanges(ctx, currentPeriod, previousPeriod)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("MTTR Change: %.2f%%\n", comparison.MTTRChange)

Statistical Analysis: The metrics system provides comprehensive statistical analysis including:

  • Percentile calculations (P50, P90, P99) for response time distribution
  • Mean and median calculations for central tendency analysis
  • Trend analysis with period-over-period comparisons
  • Variance analysis for identifying performance consistency
  • Correlation analysis between different metrics dimensions

Performance Optimization: The system is optimized for large-scale incident data processing:

  • Efficient database queries with appropriate indexing
  • Streaming data processing for memory efficiency
  • Configurable time windows to balance accuracy and performance
  • Caching strategies for frequently accessed metrics
  • Incremental calculations for real-time updates

Data Sources Integration: Metrics are calculated from multiple data sources:

  • Timeline events for activity analysis
  • Incident records for status and metadata
  • SLA tracking for compliance measurements
  • User assignments for team analysis
  • External connectors for cross-platform metrics

Reporting and Visualization: The metrics provide structured data for various reporting needs:

  • Executive dashboards with high-level KPIs
  • Operational dashboards for team performance
  • Service owner reports for reliability tracking
  • Compliance reports for SLA adherence
  • Trend analysis for capacity planning

Import Path: github.com/systmms/incidents/internal/metrics

Types

DailyMetric

DailyMetric represents metrics for a single day

{<nil> 1706 type 0 [0x140002b5700] 0}

HourlyMetric

HourlyMetric represents metrics for a single hour

{<nil> 2085 type 0 [0x140002bd180] 0}

IncidentMetrics

IncidentMetrics represents comprehensive incident metrics

{<nil> 282 type 0 [0x14000290f00] 0}

MetricComparison

MetricComparison represents comparison between two time periods

{<nil> 4827 type 0 [0x140002c7500] 0}

ResponderMetric

ResponderMetric represents metrics for an individual responder

{<nil> 3393 type 0 [0x140002c6300] 0}

Service

Service provides comprehensive metrics calculation and business intelligence for incident management.

The Service acts as the central analytics engine for the incident management platform, transforming raw incident data into actionable business intelligence, performance metrics, and trend analysis. It provides a comprehensive suite of analytical capabilities supporting executive reporting, operational dashboards, and performance optimization.

Core Capabilities:

  • Multi-dimensional incident analysis (time, severity, service, team)
  • Statistical processing with percentiles, distributions, and trends
  • SLA compliance monitoring and breach analysis
  • Team performance metrics and workload analysis
  • Service reliability tracking with error budget calculations
  • Comparative analysis between time periods
  • Real-time metrics calculation with efficient data processing

The service integrates with multiple data sources including timeline events, incident records, SLA tracking, and team assignments to provide comprehensive analytical insights across all aspects of incident management operations.

{<nil> 12162 type 0 [0x140002d8540] 0}

Methods

NewService

NewService creates a new metrics service with database connectivity for analytics processing.

This constructor initializes the metrics service with database access required for comprehensive incident analytics and business intelligence calculations. The service is immediately ready for metrics calculation across all supported dimensions and time ranges.

The metrics service provides read-only analytics operations and does not modify incident data, ensuring safe concurrent access for reporting and dashboard applications without impacting operational incident management workflows.

Parameters:

  • db: Database connection for accessing incident, timeline, and SLA data

Integration: The service integrates with:

  • Timeline events for activity analysis and trend calculation
  • Incident records for status, severity, and service breakdowns
  • SLA tracking for compliance metrics and breach analysis
  • User assignments for team performance and workload metrics

Returns a configured Service ready for comprehensive metrics calculation and business intelligence operations.

{<nil> <nil> NewService 0x140002e25c0 <nil>}

ServiceMetric

ServiceMetric represents metrics for a specific service

{<nil> 2309 type 0 [0x140002bd580] 0}

ServiceReliability

ServiceReliability represents reliability metrics for a service

{<nil> 3769 type 0 [0x140002c6840] 0}

TeamMetrics

TeamMetrics represents team performance metrics

{<nil> 2770 type 0 [0x140002bd840] 0}

TimeRange

TimeRange represents a time period for metrics calculation

{<nil> 100 type 0 [0x14000290dc0] 0}

TrendAnalysis

TrendAnalysis represents trend analysis results

{<nil> 4469 type 0 [0x140002c6fc0] 0}

Functions

calculateReliabilityScore

{<nil> <nil> calculateReliabilityScore 0x140003ba460 <nil>}

formatTimeRange

{<nil> <nil> formatTimeRange 0x140003baea0 <nil>}

percentile

{<nil> <nil> percentile 0x140003ba060 <nil>}

Generated automatically from Go source code. Last updated: 2025-08-25T07:51:05-04:00