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.
65 lines
3.2 KiB
SQL
65 lines
3.2 KiB
SQL
-- Same DDL as the engine-owned metric/traffic schemas and migrations.
|
|
-- Engine owns collection, retention and writes; PHP initializes the empty log database.
|
|
CREATE TABLE IF NOT EXISTS engine_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 engine_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 engine_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;
|
|
|
|
-- Idempotent MariaDB migration for installations created before byte accounting.
|
|
ALTER TABLE engine_vm_metric_samples ADD COLUMN IF NOT EXISTS
|
|
host_id VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NULL AFTER vm_uuid;
|
|
ALTER TABLE engine_vm_metric_samples ADD COLUMN IF NOT EXISTS
|
|
user_id BIGINT UNSIGNED NULL AFTER host_id;
|
|
ALTER TABLE engine_vm_metric_samples ADD COLUMN IF NOT EXISTS
|
|
network_rx_bytes BIGINT UNSIGNED NULL AFTER network_tx_bps;
|
|
ALTER TABLE engine_vm_metric_samples ADD COLUMN IF NOT EXISTS
|
|
network_tx_bytes BIGINT UNSIGNED NULL AFTER network_rx_bytes;
|
|
ALTER TABLE engine_vm_metric_samples ADD INDEX IF NOT EXISTS
|
|
vm_metric_owner (user_id, host_id, sampled_at);
|