| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- """expand_host_metrics_advanced
- Revision ID: a68acea9f536
- Revises: 7ff254c24bb5
- Create Date: 2025-12-29 02:02:00.000000+00:00
- """
- from typing import Sequence, Union
- from alembic import op
- import sqlalchemy as sa
- from sqlalchemy.dialects import postgresql
- # revision identifiers, used by Alembic.
- revision: str = 'a68acea9f536'
- down_revision: Union[str, None] = '7ff254c24bb5'
- branch_labels: Union[str, Sequence[str], None] = None
- depends_on: Union[str, Sequence[str], None] = None
- def upgrade() -> None:
- # Add new CPU columns
- op.add_column('host_metrics', sa.Column('cpu_per_core', postgresql.JSON(astext_type=sa.Text()), nullable=True))
- op.add_column('host_metrics', sa.Column('cpu_steal', sa.Float(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('context_switches_per_sec', sa.Integer(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('interrupts_per_sec', sa.Integer(), nullable=False, server_default='0'))
- # Add new Memory columns
- op.add_column('host_metrics', sa.Column('memory_available', sa.BigInteger(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('memory_buffers', sa.BigInteger(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('memory_cached', sa.BigInteger(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('swap_total', sa.BigInteger(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('swap_used', sa.BigInteger(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('swap_percent', sa.Float(), nullable=False, server_default='0'))
- # Add new Disk I/O columns
- op.add_column('host_metrics', sa.Column('disk_read_iops', sa.Integer(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('disk_write_iops', sa.Integer(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('disk_read_mbps', sa.Float(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('disk_write_mbps', sa.Float(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('disk_io_time_ms', sa.BigInteger(), nullable=False, server_default='0'))
- # Add new Network columns
- op.add_column('host_metrics', sa.Column('net_in_mbps', sa.Float(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('net_out_mbps', sa.Float(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('net_packets_in_per_sec', sa.Integer(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('net_packets_out_per_sec', sa.Integer(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('net_errors_in', sa.BigInteger(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('net_errors_out', sa.BigInteger(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('net_drops_in', sa.BigInteger(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('net_drops_out', sa.BigInteger(), nullable=False, server_default='0'))
- # Add Process columns
- op.add_column('host_metrics', sa.Column('process_count', sa.Integer(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('thread_count', sa.Integer(), nullable=False, server_default='0'))
- op.add_column('host_metrics', sa.Column('top_cpu_processes', postgresql.JSON(astext_type=sa.Text()), nullable=True))
- op.add_column('host_metrics', sa.Column('top_mem_processes', postgresql.JSON(astext_type=sa.Text()), nullable=True))
- def downgrade() -> None:
- # Remove added columns
- op.drop_column('host_metrics', 'top_mem_processes')
- op.drop_column('host_metrics', 'top_cpu_processes')
- op.drop_column('host_metrics', 'thread_count')
- op.drop_column('host_metrics', 'process_count')
- op.drop_column('host_metrics', 'net_drops_out')
- op.drop_column('host_metrics', 'net_drops_in')
- op.drop_column('host_metrics', 'net_errors_out')
- op.drop_column('host_metrics', 'net_errors_in')
- op.drop_column('host_metrics', 'net_packets_out_per_sec')
- op.drop_column('host_metrics', 'net_packets_in_per_sec')
- op.drop_column('host_metrics', 'net_out_mbps')
- op.drop_column('host_metrics', 'net_in_mbps')
- op.drop_column('host_metrics', 'disk_io_time_ms')
- op.drop_column('host_metrics', 'disk_write_mbps')
- op.drop_column('host_metrics', 'disk_read_mbps')
- op.drop_column('host_metrics', 'disk_write_iops')
- op.drop_column('host_metrics', 'disk_read_iops')
- op.drop_column('host_metrics', 'swap_percent')
- op.drop_column('host_metrics', 'swap_used')
- op.drop_column('host_metrics', 'swap_total')
- op.drop_column('host_metrics', 'memory_cached')
- op.drop_column('host_metrics', 'memory_buffers')
- op.drop_column('host_metrics', 'memory_available')
- op.drop_column('host_metrics', 'interrupts_per_sec')
- op.drop_column('host_metrics', 'context_switches_per_sec')
- op.drop_column('host_metrics', 'cpu_steal')
- op.drop_column('host_metrics', 'cpu_per_core')
|