SPB Git

Repository Public

seed.sql 8.7 KB 85 lines sql

1-- Synthetic rows for the iOS test databases ONLY (mcc_ios_test_*): aliases `ios-test-node-NN`, environment `test`,2-- documentation IP ranges (192.0.2.0/24). Written straight into the tables the API reads, in the shape the agents3-- and the ingest service produce. Idempotent. Never run this against a real database.4\set ON_ERROR_STOP on56insert into nodes(id, hardware_uuid, alias, kind, hostname, site, role, environment, tags, model, chip, arch, cpu_cores, cpu_levels, gpu_cores, mem_bytes, storage_bytes, os_name, os_version, os_build, primary_ip, registered_via, inventory, inventory_at, last_seen_at) values7  ('105e0000-0000-7000-8000-000000000001', '105E0000-0000-0000-0000-000000000001', 'ios-test-node-01', 'mac', 'ios-test-node-01.test', 'ios-lab', 'worker', 'test', '{ios-test,synthetic}', 'Mac18,5', 'Apple M6', 'arm64', 12,8    '[{"name":"Super","cores":2},{"name":"Performance","cores":4},{"name":"Efficiency","cores":6}]', 12, 25769803776, 493921239040, 'macOS', '27.0', '27A000', '192.0.2.11', 'agent',9    '{"interfaces":[{"name":"en0","kind":"ethernet","mac":"02:00:00:10:5e:01","addrs":["192.0.2.11"],"media":"1000baseT","up":true,"default":true}]}', now(), now()),10  ('105e0000-0000-7000-8000-000000000002', '105E0000-0000-0000-0000-000000000002', 'ios-test-node-02', 'mac', 'ios-test-node-02.test', 'ios-lab', 'worker', 'test', '{ios-test}', 'Mac16,9', 'Apple M4 Max', 'arm64', 16,11    '[{"name":"Performance","cores":12},{"name":"Efficiency","cores":4}]', 40, 68719476736, 994662584320, 'macOS', '27.0', '27A000', '192.0.2.12', 'agent', '{}', now(), now()),12  ('105e0000-0000-7000-8000-000000000003', '105E0000-0000-0000-0000-000000000003', 'ios-test-node-03', 'mac', 'ios-test-node-03.test', 'ios-lab', 'gateway', 'test', '{ios-test}', 'Mac16,10', 'Apple M4', 'arm64', 10,13    '[{"name":"Performance","cores":4},{"name":"Efficiency","cores":6}]', 10, 17179869184, 245107195904, 'macOS', '26.7', '26H000', '192.0.2.13', 'agent', '{}', now(), now() - interval '60 seconds'),14  ('105e0000-0000-7000-8000-000000000004', null, 'ios-test-node-04', 'linux', '', 'ios-edge', 'gateway', 'test', '{ios-test}', null, null, null, null, null, null, null, null, null, null, null, null, 'manual', '{}', null, null)15on conflict (id) do nothing;1617insert into agents(id, node_id, cert_serial, cert_fingerprint, cert_not_after, version, os, capabilities, last_seen_at, overhead) values18  ('105e0000-0000-7000-8000-0000000000c1', '105e0000-0000-7000-8000-000000000001', 'ios-test-serial-01', decode(repeat('ab', 32), 'hex'), now() + interval '30 days', '1.0.0-test', 'darwin/arm64',19   '{inventory.refresh,diagnostic.run,service.health_check,service.logs.tail,service.restart}', now(), '{"cpu_pct":0.4,"rss_bytes":31457280}'),20  ('105e0000-0000-7000-8000-0000000000c2', '105e0000-0000-7000-8000-000000000002', 'ios-test-serial-02', decode(repeat('cd', 32), 'hex'), now() + interval '30 days', '1.0.0-test', 'darwin/arm64',21   '{inventory.refresh}', now(), '{"cpu_pct":0.3,"rss_bytes":29360128}')22on conflict (id) do nothing;2324insert into node_state(node_id, ts, received_at, values, availability, processes, processes_at) values25  ('105e0000-0000-7000-8000-000000000001', now(), now(),26   '{"cpu.usage":43.5,"cpu.user":30.1,"cpu.system":13.4,"load.1":2.25,"load.5":2.0,"load.15":1.8,"mem.used":9663676416,"mem.total":25769803776,"mem.wired":2147483648,"mem.compressed":1073741824,"mem.pressure.level":1,"mem.available.percent":62,"swap.used":0,"disk.used{/}":128849018880,"disk.total{/}":493921239040,"net.rx{en0}":125000,"net.tx{en0}":48000,"gpu.usage":7,"uptime":432000,"procs.count":512}',27   '{"thermal.temp":"unsupported","power.draw":"unsupported","battery.charge":"unsupported"}',28   '[{"pid":4242,"name":"ios-test-worker","user":"test","cpu":37.5,"rss":536870912},{"pid":4243,"name":"ios-test-idle","user":"test","cpu":0.4,"rss":67108864}]', now()),29  ('105e0000-0000-7000-8000-000000000002', now(), now(),30   '{"cpu.usage":71.0,"cpu.user":60.0,"cpu.system":11.0,"load.1":9.5,"load.5":8.1,"load.15":7.7,"mem.used":41231686041,"mem.total":68719476736,"mem.pressure.level":1,"swap.used":0,"disk.used{/}":397284474880,"disk.total{/}":994662584320,"uptime":86400,"procs.count":640}',31   '{"thermal.temp":"unsupported","power.draw":"permission_denied"}', null, null),32  ('105e0000-0000-7000-8000-000000000003', now() - interval '60 seconds', now() - interval '60 seconds', '{"cpu.usage":12.0,"load.1":0.5}', '{}', null, null)33on conflict (node_id) do nothing;3435do $$36declare d date;37begin38  for d in select generate_series((now() at time zone 'utc')::date - 1, (now() at time zone 'utc')::date + 1, interval '1 day')::date loop39    execute format('create table if not exists samples_raw_p%s partition of samples_raw for values from (%L) to (%L)', to_char(d, 'YYYYMMDD'), d::text || ' 00:00:00+00', (d + 1)::text || ' 00:00:00+00');40  end loop;41end $$;4243-- cpu.usage (1), load.1 (4) and mem.used (10) every 10 s over the last 50 minutes; node 01 has a 6-minute hole.44insert into samples_raw(node_id, metric_id, label, ts, value)45  select '105e0000-0000-7000-8000-000000000001', m.id, '', t,46         case m.id when 1 then 40 + 25 * sin(extract(epoch from t) / 300.0) when 4 then 2 + sin(extract(epoch from t) / 500.0) else 9663676416 + 1073741824 * sin(extract(epoch from t) / 700.0) end47  from generate_series(date_trunc('second', now()) - interval '50 minutes', date_trunc('second', now()), interval '10 seconds') t, (values (1), (4), (10)) m(id)48  where t not between now() - interval '26 minutes' and now() - interval '20 minutes'49on conflict do nothing;50insert into samples_raw(node_id, metric_id, label, ts, value)51  select '105e0000-0000-7000-8000-000000000002', m.id, '', t,52         case m.id when 1 then 65 + 20 * cos(extract(epoch from t) / 240.0) when 4 then 9 + cos(extract(epoch from t) / 400.0) else 41231686041 + 2147483648 * cos(extract(epoch from t) / 600.0) end53  from generate_series(date_trunc('second', now()) - interval '50 minutes', date_trunc('second', now()), interval '10 seconds') t, (values (1), (4), (10)) m(id)54on conflict do nothing;5556insert into services(id, node_id, manager, name, state, pid, restarts, mem_bytes, cpu_pct, uptime_s, version, ports, app, public_url, health, managed, last_seen_at) values57  ('105e0000-0000-7000-8000-0000000000a1', '105e0000-0000-7000-8000-000000000001', 'pm2', 'ios-test-api', 'online', 5001, 3, 209715200, 2.5, 86400, '1.2.3', '{8700}', 'ios-test-app', 'https://ios-test-app.example.test', '{"status":"ok","latency_ms":12,"checked_at":"2026-11-18T00:00:00Z"}', true, now()),58  ('105e0000-0000-7000-8000-0000000000a2', '105e0000-0000-7000-8000-000000000001', 'launchd', 'test.ios.agentd', 'errored', null, 17, null, null, null, null, '{}', null, null, null, false, now())59on conflict (id) do nothing;6061insert into inference_servers(id, node_id, kind, port, model, quantization, pid, rss_bytes, uptime_s, disk_bytes, health, health_at, health_latency_ms, listed_models, last_seen_at) values62  ('105e0000-0000-7000-8000-0000000000b1', '105e0000-0000-7000-8000-000000000002', 'mlx_lm', 8081, 'ios-test-org/Test-Model-7B-4bit', '4bit', 6001, 5368709120, 7200, 4294967296, 'ok', now(), 35, '["ios-test-org/Test-Model-7B-4bit"]', now())63on conflict (id) do nothing;6465insert into volumes(id, node_id, mount, device, fs, kind, total_bytes, used_bytes, smart_status, last_seen_at) values66  ('105e0000-0000-7000-8000-0000000000d1', '105e0000-0000-7000-8000-000000000001', '/', 'disk3s1', 'apfs', 'internal', 493921239040, 128849018880, 'Verified', now()),67  ('105e0000-0000-7000-8000-0000000000d2', '105e0000-0000-7000-8000-000000000001', '/Volumes/ios-test-ssd', 'disk5s1', 'apfs', 'external', 994662584320, 966367641600, null, now()),68  ('105e0000-0000-7000-8000-0000000000d3', '105e0000-0000-7000-8000-000000000002', '/', 'disk3s1', 'apfs', 'internal', 994662584320, 397284474880, 'Verified', now())69on conflict (id) do nothing;7071insert into nas_targets(id, name, host, share, protocol, note, state, state_at) values72  ('105e0000-0000-7000-8000-0000000000e1', 'ios-test-nas', '192.0.2.173', 'test', 'smb', 'synthetic test target', 'offline', now())73on conflict (id) do nothing;7475insert into backups(id, name, node_id, kind, last_status, detail) values76  ('105e0000-0000-7000-8000-0000000000f1', 'ios-test-backup', '105e0000-0000-7000-8000-000000000001', 'app', 'unknown', 'never observed')77on conflict (id) do nothing;7879-- One firing alert on node 01 (built-in rule), for the acknowledge scenario.80insert into alerts(id, rule_id, node_id, label, fingerprint, state, severity, summary, last_value, started_at, fired_at, last_eval_at)81  select '105e0000-0000-7000-8000-0000000a1e47', r.id, '105e0000-0000-7000-8000-000000000001', '', 'ios-test-fingerprint-1', 'firing', 'critical',82         'ios-test synthetic alert: CPU saturated', 97.5, now() - interval '10 minutes', now() - interval '5 minutes', now()83  from alert_rules r where r.name = 'CPU saturated'84on conflict (id) do nothing;85
Files main
Menu

Theme