|
|
|
|
-- Fresh-install Agent metric and traffic schema. Agents expose current signed
|
|
|
|
|
-- counters; PHP owns sampling, billing totals, chart retention and all writes.
|
|
|
|
|
CREATE TABLE cloud_vm_metric_samples (
|
|
|
|
|
host_scope CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
vm_uuid CHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
host_id VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NULL,
|
|
|
|
|
user_id BIGINT UNSIGNED NULL,
|
|
|
|
|
sampled_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
cpu_percent DOUBLE NULL,
|
|
|
|
|
memory_used_mib DOUBLE NULL,
|
|
|
|
|
memory_total_mib DOUBLE NULL,
|
|
|
|
|
disk_read_bps DOUBLE NULL,
|
|
|
|
|
disk_write_bps DOUBLE NULL,
|
|
|
|
|
network_rx_bps DOUBLE NULL,
|
|
|
|
|
network_tx_bps DOUBLE NULL,
|
|
|
|
|
network_rx_bytes BIGINT UNSIGNED NULL,
|
|
|
|
|
network_tx_bytes BIGINT UNSIGNED NULL,
|
|
|
|
|
PRIMARY KEY (host_scope, vm_uuid, sampled_at),
|
|
|
|
|
KEY vm_metric_retention (sampled_at),
|
|
|
|
|
KEY vm_metric_owner (user_id, host_id, sampled_at)
|
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
|
|
|
|
|
|
CREATE TABLE cloud_vm_traffic_totals (
|
|
|
|
|
host_scope CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
vm_uuid CHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
host_id VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NULL,
|
|
|
|
|
user_id BIGINT UNSIGNED NULL,
|
|
|
|
|
last_observed_at BIGINT UNSIGNED NULL,
|
|
|
|
|
network_signature CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
network_baseline_json JSON NOT NULL,
|
|
|
|
|
download_rx_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
upload_tx_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
PRIMARY KEY (host_scope, vm_uuid),
|
|
|
|
|
KEY vm_traffic_owner (user_id, host_id),
|
|
|
|
|
KEY vm_traffic_host (host_id, vm_uuid)
|
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
|
|
|
|
|
|
-- Compact, durable billing ledger. Chart samples below are pruned after 30
|
|
|
|
|
-- days; the first cumulative counter observed in every hour is not.
|
|
|
|
|
CREATE TABLE cloud_vm_traffic_checkpoints (
|
|
|
|
|
host_scope CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
vm_uuid CHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
checkpoint_hour BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
host_id VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NULL,
|
|
|
|
|
user_id BIGINT UNSIGNED NULL,
|
|
|
|
|
first_observed_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
download_rx_bytes BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
upload_tx_bytes BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
PRIMARY KEY (host_scope, vm_uuid, checkpoint_hour),
|
|
|
|
|
KEY vm_traffic_checkpoint_owner (user_id, host_id, first_observed_at)
|
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
|
|
|
|
|
|
-- Logical-instance daily traffic survives maintenance migration because its
|
|
|
|
|
-- identity does not depend on the current host or libvirt UUID. The cursor is
|
|
|
|
|
-- retained beyond the 30-day chart window so an old cumulative total can
|
|
|
|
|
-- never be charged into a new day after pruning.
|
|
|
|
|
CREATE TABLE cloud_vm_daily_traffic_cursors (
|
|
|
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
last_observed_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
download_total_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
upload_total_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
PRIMARY KEY (instance_id),
|
|
|
|
|
KEY cloud_daily_traffic_cursor_owner (user_id, updated_at)
|
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
|
|
|
|
|
|
CREATE TABLE cloud_vm_daily_traffic (
|
|
|
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
day_start BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
download_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
upload_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
sample_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
first_observed_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
last_observed_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
PRIMARY KEY (instance_id, day_start),
|
|
|
|
|
KEY cloud_daily_traffic_retention (day_start),
|
|
|
|
|
KEY cloud_daily_traffic_owner (user_id, day_start)
|
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|