You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/sql/cloud_log.sql

53 lines
2.5 KiB
MySQL

-- Fresh-install Agent metric and traffic schema. Agents expose current signed
-- counters; PHP owns sampling, billing totals, chart retention and all writes.
CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS 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 IF NOT EXISTS 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;