Files
cairnobs/scripts/fleet/ibmi.go
T
jcoffey-dev 95965ed5e8
ci / postgres (pull_request) Successful in 3m14s
ci / check (pull_request) Successful in 8m22s
Demo: hosts named for their site and role, collectors on their own
Things that gave the simulator away (#40):

- hosts were fleet-0000 to fleet-0119. Now they're named for their site
  and what they do: phx1-gw01, phx1-lb01, phx1-app05, phx1-db03,
  phx1-cache02, iad1-lb02, lon1-kvm01 (collectors.go);
- fleet-0041 was a Redis cache, a KVM host, the IBM i collector and the
  HMC reader at once, so IBM i alerts read as if PROD2 ran on it. The
  agents that read storage, IBM i and virtualization are small hosts of
  their own now: phx1-stor01 (the Pure arrays), phx1-ibmi01 (the
  partitions and the HMC), phx1-virt01 (vCenter, Proxmox, Nutanix).
  fleet config writes their agents;
- libvirt runs only on app servers, not on a load balancer or a cache;
- RHEL hosts' units are sshd and chronyd, as RHEL names them;
- Akamai's CP codes no longer have round counts.

Varied disks and jittered readings came with #39 (load.go).
2026-11-15 23:20:21 -07:00

99 lines
4.6 KiB
Go

package main
import (
"fmt"
"math"
"math/rand/v2"
"strings"
"time"
"github.com/cairnobs/cairnobs/internal/ibmi"
"github.com/cairnobs/cairnobs/internal/report"
)
// IBM i partitions, as a host agent with an ibmi: section sends them
// (docs/ibmi.md): phx1-ibmi01's agent reads them, each a source of its own.
// The records are the reader's own, made from snapshots as the views
// would answer.
// ibmiPartitions are the partitions, in the order -ibmi N takes them.
var ibmiPartitions = []string{"prod1", "prod2", "ha1", "dev1"}
// newIBMi is the k'th partition: prod1 busy, its nightly batch stuck on a
// question now and then; prod2's ORDERS subsystem ended for a while now
// and then, its job queue filling meanwhile (scenario.go); ha1 the
// PowerHA standby, its independent ASP varied off; dev1 on 7.4 without
// the authority to read its Technology Refresh.
func newIBMi(name, token string, k int) *fakeCluster {
part := ibmiPartitions[k]
c := &fakeCluster{name: name, token: token, recs: map[string]report.Workload{}, changed: map[string]bool{}, noUsage: true, source: part}
units := []float64{4, 3, 2, 1}[k]
c.usageFn = func(now time.Time) []report.Usage {
day := 0.5 + 0.5*math.Sin(2*math.Pi*(float64(now.Hour()*60+now.Minute())/1440-0.3))
base := []float64{68, 52, 6, 12}[k]
if k == 0 && now.Hour() >= 1 && now.Hour() < 4 {
base = 95 // the nightly batch
}
pct := min(100, base*(0.6+0.4*day)*(0.9+0.2*rand.Float64()))
return []report.Usage{{ID: report.ClusterSelf, CPU: math.Round(pct*units) / 100, CPUOf: units}}
}
sysUsed := []float64{84.6, 72.8, 64.1, 48.0}[k]
snap := func(bad bool) *ibmi.Snapshot {
s := &ibmi.Snapshot{Name: part, Release: "7.5", TR: 6, At: time.Now(),
System: ibmi.System{HostName: "S" + part, PartitionName: strings.ToUpper(part), PartitionID: k + 2, Partitions: 6, MachineType: "9105", MachineModel: "42A",
Serial: "78ABC12", CPUs: int(units * 2), Capacity: units, MainStorageKB: int64(units*64) << 20, SystemASPMB: 2_400_000,
SystemASPUsed: sysUsed, TempMB: 38_000, Jobs: []int{18204, 14550, 6120, 3307}[k], MaxJobs: 163520,
ActiveJobs: []int{612, 488, 201, 97}[k], Threads: []int{2870, 2210, 890, 402}[k]},
ASPs: []ibmi.ASP{{Number: 1, State: "NONE", Type: "SYSTEM", Units: 8, Present: "ALL", TotalMB: 2_400_000,
FreeMB: int64(2_400_000 * (100 - sysUsed) / 100), Threshold: 90}}}
switch part {
case "prod1", "ha1":
ia := ibmi.ASP{Number: 33, Name: "PRODIASP", State: "AVAILABLE", Type: "PRIMARY", Units: 6, Present: "ALL", TotalMB: 3_600_000, FreeMB: 1_440_000, Threshold: 90}
if part == "ha1" {
ia.State = "VARIED OFF"
}
s.ASPs = append(s.ASPs, ia)
case "dev1":
s.Release, s.TR = "7.4", 0
}
sbs := func(lib, name, status string, jobs int) ibmi.Subsystem {
return ibmi.Subsystem{Library: lib, Name: name, Status: status, Jobs: jobs, Controlling: name == "QCTL"}
}
s.Subsys = []ibmi.Subsystem{sbs("QSYS", "QCTL", "ACTIVE", 3), sbs("QSYS", "QINTER", "ACTIVE", 20+k*7), sbs("QSYS", "QBATCH", "ACTIVE", 6+k),
sbs("QSYS", "QUSRWRK", "ACTIVE", 60+k*9), sbs("QSYS", "QSERVER", "ACTIVE", 14), sbs("QSYS", "QSYSWRK", "ACTIVE", 110), sbs("QSYS", "QSPL", "ACTIVE", 4),
sbs("QSYS", "QHTTPSVR", "ACTIVE", 9), sbs("QSYS", "QSNADS", "INACTIVE", 0), sbs("QSYS", "QCMN", "ACTIVE", 2), sbs("ORDLIB", "ORDERS", "ACTIVE", 12)}
s.Ifaces = []ibmi.Interface{{Address: fmt.Sprintf("10.0.4.%d", 20+k), Prefix: 24, Line: "ETHLINE", Status: "ACTIVE", Autostart: true},
{Address: fmt.Sprintf("10.0.9.%d", 20+k), Prefix: 24, Line: "ETHBKP", Status: "ACTIVE", Autostart: true}}
switch {
case part == "prod1" && bad:
s.Inquiries = []ibmi.Message{{Key: "0001A2F0", ID: "CPA0701", Inquiry: true, Severity: 99, Job: "418276/BATCH/NIGHTLY", User: "BATCH",
Text: "MCH1211 received by procedure ORDPOST. (C D I R)", Age: 7 * time.Minute}}
s.Unanswered = 1
case part == "prod2" && bad:
s.Subsys[len(s.Subsys)-1].Status, s.Subsys[len(s.Subsys)-1].Jobs = "INACTIVE", 0 // ORDERS: ended, not started again
s.JobQueues = []ibmi.JobQueue{{Library: "ORDLIB", Name: "ORDERSQ", Waiting: 14}} // ORDERS isn't there to take them
case part == "ha1":
s.Subsys = s.Subsys[:len(s.Subsys)-1] // ORDERS runs on the active node only
}
return s
}
now := time.Now()
recs := func(bad bool) []report.Workload {
out := ibmi.Records(snap(bad))
for i := range out {
out[i].Since = now.Add(-time.Duration(40+k*7) * 24 * time.Hour)
}
return out
}
for _, r := range recs(false) {
c.recs[r.ID] = r
}
switch part {
case "prod1":
c.flapSet(spellInquiry, recs(false), recs(true))
case "prod2":
c.flapSet(spellOrdersDown, recs(false), recs(true))
}
return c
}