#5752 "Container CPU and memory history lives in the one metric store; docker_metrics and docker_metrics_hourly are retired". Container cpu_pct and mem_pct already went to plugin_metrics for alerting; now mem_usage_bytes does too, and every snapshot in an ingest (backlog included) is recorded at its own time. The container history chart, Busiest Containers, a service's history and the MCP container tools read plugin_metrics under resource "<host>/<container>", rolled up and pruned by the shared metric retention. docker_012_drop_metrics drops both tables. Their history is not copied (lesson #5221 "A data migration's cost is set by the live table"); the store already holds 7 days of container CPU and memory %. Docker retention now prunes only lifecycle events, and Settings -> Thresholds has one "Metric retention" card for every source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
2.5 KiB
Python
57 lines
2.5 KiB
Python
"""Container CPU and memory move to the one metric store
|
|
|
|
Drops docker_metrics and docker_metrics_hourly (#5752). Container cpu_pct,
|
|
mem_pct and mem_usage_bytes are recorded into plugin_metrics as source
|
|
"docker", resource "<host>/<container>", and roll up with every other metric.
|
|
CPU and memory % were already recorded there for alerting, so their history
|
|
stays; memory in bytes starts fresh.
|
|
|
|
Revision ID: docker_012_drop_metrics
|
|
Revises: docker_011_host_status
|
|
Create Date: 2026-10-14
|
|
"""
|
|
from typing import Sequence, Union
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision: str = "docker_012_drop_metrics"
|
|
down_revision: Union[str, None] = "docker_011_host_status"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.execute("DROP TABLE IF EXISTS docker_metrics_hourly")
|
|
op.execute("DROP TABLE IF EXISTS docker_metrics")
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.create_table(
|
|
"docker_metrics",
|
|
sa.Column("id", sa.String(36), primary_key=True),
|
|
sa.Column("host_id", sa.String(36), sa.ForeignKey("hosts.id", ondelete="CASCADE"),
|
|
nullable=False, index=True),
|
|
sa.Column("container_name", sa.String(255), nullable=False, index=True),
|
|
sa.Column("scraped_at", sa.DateTime(timezone=True), nullable=False, index=True),
|
|
sa.Column("cpu_pct", sa.Float, nullable=False),
|
|
sa.Column("mem_pct", sa.Float, nullable=False),
|
|
sa.Column("mem_usage_bytes", sa.BigInteger, nullable=False),
|
|
)
|
|
op.create_index("ix_docker_metrics_host_container_time", "docker_metrics",
|
|
["host_id", "container_name", "scraped_at"])
|
|
op.create_table(
|
|
"docker_metrics_hourly",
|
|
sa.Column("id", sa.String(36), primary_key=True),
|
|
sa.Column("host_id", sa.String(36), sa.ForeignKey("hosts.id", ondelete="CASCADE"),
|
|
nullable=False),
|
|
sa.Column("container_name", sa.String(255), nullable=False),
|
|
sa.Column("bucket", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("cpu_pct", sa.Float, nullable=False),
|
|
sa.Column("mem_pct", sa.Float, nullable=False),
|
|
sa.Column("mem_usage_bytes", sa.BigInteger, nullable=False),
|
|
sa.Column("sample_count", sa.Integer, nullable=False),
|
|
sa.UniqueConstraint("host_id", "container_name", "bucket",
|
|
name="uq_docker_metrics_hourly_bucket"),
|
|
)
|
|
op.create_index("ix_docker_metrics_hourly_bucket", "docker_metrics_hourly", ["bucket"])
|