Add Buckets, Monitoring, Memberships, Networking, SSO, Announcements, Status page
Full set of admin surfaces on top of /platform/* and /admin/* endpoints,
plus a migration of /assistant onto @crema/llm-providers-ui.
Buckets (/buckets):
S3-level CRUD over /platform/buckets — list, create, delete (with the
6-digit confirmation flow the backend enforces), per-bucket configure
for versioning / CORS rules / policy JSON, plus an object browser
with FileGrid/FileList from @crema/file-ui and presigned-URL reveal.
Storage-config picker scopes the view to one credential at a time.
Monitoring (/monitoring):
Live dashboard. Service health board derived from indirect signals
(status-ui OverallStatus + ComponentRow). KPI tiles for sessions,
jobs, audit. Tabs: background jobs (Donut + BarChart + retry recent),
sessions (Sparkline of last 24h sign-ins), audit activity (BarChart
of severity / top resource types), infrastructure (DO summary +
WorldMapSvg coloured by droplet region + droplet list + Spaces),
rate limits. 30s auto-refresh.
Memberships (/memberships):
M:N glue between users and tenants over /admin/memberships. Add /
edit / suspend / activate / remove with role multi-select.
Networking (/networking):
Tabs over /platform/{firewalls,vpcs,domains,floating_ips}.
Read/delete on firewalls, read on VPCs, full DNS-record CRUD, and
inline assign/unassign for floating IPs.
SSO (/sso):
/sso/identity-providers CRUD with PEM cert as write-only field, plus
/sso/sessions list with destroy.
Announcements (/announcements):
/admin/announcements CRUD. Platform-wide vs per-tenant audience,
schedule windows, dismissible + active toggles.
Status page (/status-page):
/admin/status-page/{components,incidents,subscribers}. Components
CRUD, incidents with timeline + post-update + resolve flow,
subscriber list. Public preview at the top using StatusBoard +
IncidentTimeline from @crema/status-ui.
Assistant migration:
/assistant now uses @crema/llm-providers-ui (provider catalog +
vault key resolution) instead of ~/lib/llm-settings. Same async
buildAdapter() flow used by /ai. The legacy lib file is now
unreferenced and can be removed when ready.
New sibling libs wired (cloned from CremaUIStudio):
lib-file-ui, lib-card-ui, lib-dashboard-ui, lib-chart-ui,
lib-map-ui, lib-status-ui.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
199
app/lib/arcadia/monitoring.ts
Normal file
199
app/lib/arcadia/monitoring.ts
Normal file
@@ -0,0 +1,199 @@
|
||||
// Server stats / health helpers.
|
||||
// Wraps /api/v1/admin/monitoring/* + /api/v1/platform/* + a few observability
|
||||
// endpoints used by the monitoring dashboard.
|
||||
|
||||
import type { ArcadiaClient } from "@crema/arcadia-client"
|
||||
|
||||
// --- Rate limits ---------------------------------------------------------
|
||||
|
||||
export interface RateLimit {
|
||||
type: string
|
||||
max_requests: number
|
||||
window_seconds: number
|
||||
}
|
||||
|
||||
export async function getRateLimits(arcadia: ArcadiaClient): Promise<RateLimit[]> {
|
||||
const res = await arcadia.GET<{ data: { limits: RateLimit[] } }>(
|
||||
"/api/v1/admin/monitoring/rate-limits",
|
||||
)
|
||||
return res.data.limits ?? []
|
||||
}
|
||||
|
||||
// --- Active sessions ----------------------------------------------------
|
||||
|
||||
export interface ActiveSession {
|
||||
user_id: string
|
||||
email: string
|
||||
first_name: string | null
|
||||
last_name: string | null
|
||||
status: string
|
||||
user_type: string | null
|
||||
last_sign_in_at: string
|
||||
tenant_id: string
|
||||
two_factor_enabled: boolean
|
||||
}
|
||||
|
||||
export async function getActiveSessions(
|
||||
arcadia: ArcadiaClient,
|
||||
): Promise<{ sessions: ActiveSession[]; count: number }> {
|
||||
const res = await arcadia.GET<{ data: { sessions: ActiveSession[]; count: number } }>(
|
||||
"/api/v1/admin/monitoring/sessions",
|
||||
)
|
||||
return res.data
|
||||
}
|
||||
|
||||
// --- Background jobs (Oban) ---------------------------------------------
|
||||
|
||||
export type JobState =
|
||||
| "available"
|
||||
| "executing"
|
||||
| "scheduled"
|
||||
| "retryable"
|
||||
| "discarded"
|
||||
| "cancelled"
|
||||
| "completed"
|
||||
|
||||
export interface JobStats {
|
||||
counts: Record<JobState, number>
|
||||
by_queue: Record<string, Partial<Record<JobState, number>>>
|
||||
queues: string[]
|
||||
}
|
||||
|
||||
export interface ObanJob {
|
||||
id: number
|
||||
queue: string
|
||||
state: JobState
|
||||
worker: string
|
||||
attempt: number
|
||||
max_attempts: number
|
||||
inserted_at: string
|
||||
attempted_at: string | null
|
||||
completed_at: string | null
|
||||
scheduled_at: string | null
|
||||
errors: Array<{ at?: string; attempt?: number; error?: string }> | null
|
||||
}
|
||||
|
||||
export async function getJobStats(arcadia: ArcadiaClient): Promise<JobStats> {
|
||||
const res = await arcadia.GET<{ data: JobStats }>(
|
||||
"/api/v1/admin/monitoring/jobs/stats",
|
||||
)
|
||||
return res.data
|
||||
}
|
||||
|
||||
export async function getRecentJobs(
|
||||
arcadia: ArcadiaClient,
|
||||
params?: { limit?: number; state?: JobState; queue?: string },
|
||||
): Promise<ObanJob[]> {
|
||||
const res = await arcadia.GET<{ data: { jobs: ObanJob[]; count: number } }>(
|
||||
"/api/v1/admin/monitoring/jobs",
|
||||
{ params: params as Record<string, string | number | undefined> },
|
||||
)
|
||||
return res.data.jobs ?? []
|
||||
}
|
||||
|
||||
export async function retryJob(arcadia: ArcadiaClient, id: number): Promise<void> {
|
||||
await arcadia.POST(`/api/v1/admin/monitoring/jobs/${id}/retry`)
|
||||
}
|
||||
|
||||
// --- Platform infrastructure (DigitalOcean) -----------------------------
|
||||
|
||||
/** Provider returns whatever it returns; admin UI surfaces it loosely. */
|
||||
export type InfrastructureSummary = Record<string, unknown>
|
||||
export type Space = Record<string, unknown>
|
||||
|
||||
export async function getInfrastructureSummary(
|
||||
arcadia: ArcadiaClient,
|
||||
): Promise<InfrastructureSummary | null> {
|
||||
try {
|
||||
const res = await arcadia.GET<{ data: InfrastructureSummary }>(
|
||||
"/api/v1/platform/infrastructure/summary",
|
||||
)
|
||||
return res.data
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function getSpaces(arcadia: ArcadiaClient): Promise<Space[]> {
|
||||
try {
|
||||
const res = await arcadia.GET<{ data: Space[] }>(
|
||||
"/api/v1/platform/infrastructure/spaces",
|
||||
)
|
||||
return res.data ?? []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
// --- Droplets ------------------------------------------------------------
|
||||
|
||||
export interface Droplet {
|
||||
id: number | string
|
||||
name: string
|
||||
status: string
|
||||
region?: { slug?: string; name?: string } | string
|
||||
size_slug?: string
|
||||
vcpus?: number
|
||||
memory?: number
|
||||
disk?: number
|
||||
created_at?: string
|
||||
networks?: unknown
|
||||
/** Provider-specific fields surface verbatim. */
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export interface DropletMetrics {
|
||||
cpu?: Array<{ time: string; value: number }>
|
||||
memory?: Array<{ time: string; value: number }>
|
||||
disk?: Array<{ time: string; value: number }>
|
||||
bandwidth?: Array<{ time: string; value: number }>
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export async function listDroplets(arcadia: ArcadiaClient): Promise<Droplet[]> {
|
||||
try {
|
||||
const res = await arcadia.GET<{ droplets?: Droplet[]; data?: Droplet[] }>(
|
||||
"/api/v1/platform/droplets",
|
||||
)
|
||||
return res.droplets ?? res.data ?? []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDropletMetrics(
|
||||
arcadia: ArcadiaClient,
|
||||
id: number | string,
|
||||
): Promise<DropletMetrics | null> {
|
||||
try {
|
||||
const res = await arcadia.GET<{ data: DropletMetrics }>(
|
||||
`/api/v1/platform/droplets/${id}/metrics`,
|
||||
)
|
||||
return res.data
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// --- Audit stats (already used by /activity, exposed here for the dashboard) ---
|
||||
|
||||
export interface AuditStats {
|
||||
total: number
|
||||
by_action?: Record<string, number>
|
||||
by_severity?: Record<string, number>
|
||||
by_resource_type?: Record<string, number>
|
||||
/** When backend supports it: { period: ISO, total: number }[] */
|
||||
over_time?: Array<{ period: string; total: number }>
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export async function getAuditStats(
|
||||
arcadia: ArcadiaClient,
|
||||
params?: { from?: string; to?: string },
|
||||
): Promise<AuditStats> {
|
||||
const res = await arcadia.GET<{ data: AuditStats }>(
|
||||
"/api/v1/observability/audit_stats",
|
||||
{ params: params as Record<string, string | undefined> },
|
||||
)
|
||||
return res.data
|
||||
}
|
||||
Reference in New Issue
Block a user