"""
Task Manager Metrics

Prometheus 监控指标定义。
"""

from prometheus_client import Counter, Gauge, Histogram, Summary

# 任务计数器
task_created_counter = Counter(
    'task_created_total',
    'Total number of tasks created',
    ['type', 'priority']
)

task_completed_counter = Counter(
    'task_completed_total',
    'Total number of tasks completed',
    ['type', 'status']
)

task_failed_counter = Counter(
    'task_failed_total',
    'Total number of tasks failed',
    ['type', 'reason']
)

task_retry_counter = Counter(
    'task_retry_total',
    'Total number of task retries',
    ['type']
)

# 任务队列指标
task_queue_size_gauge = Gauge(
    'task_queue_size',
    'Current number of tasks in queue'
)

task_active_gauge = Gauge(
    'task_active_total',
    'Current number of active tasks',
    ['type']
)

# 任务执行时间
task_duration_histogram = Histogram(
    'task_duration_seconds',
    'Task execution duration in seconds',
    ['type'],
    buckets=[1, 5, 10, 30, 60, 120, 300, 600, 1800]  # 1s to 30min
)

task_wait_time_histogram = Histogram(
    'task_wait_time_seconds',
    'Task wait time in queue before execution',
    ['type'],
    buckets=[0.1, 0.5, 1, 5, 10, 30, 60, 120]
)

# 任务执行摘要
task_execution_summary = Summary(
    'task_execution_summary',
    'Summary of task execution metrics',
    ['type']
)
