Disambiguates the Phoenix/auth client lib from lib-arcadia-agents-client. Dir lib-arcadia-client → lib-arcadia-core-client; alias updated in tsconfig paths, vite config, app.css @source, imports, CI and docs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
200 lines
5.3 KiB
TypeScript
200 lines
5.3 KiB
TypeScript
// 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-core-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
|
|
}
|