package cloud.lunarsky.store; import java.io.IOException; import java.nio.file.Files; import java.nio.file.FileStore; import java.util.List; import static cloud.lunarsky.store.AdminConsole.PATH; import static cloud.lunarsky.store.AdminLayout.*; final class AdminStatusPages { private AdminStatusPages() { } static String overviewPage(String mode, String status, long maxObject, long maxTotal, List buckets, boolean bucketListAvailable, String csrf) { StringBuilder content = new StringBuilder(consoleHeader(csrf) + "

Overview

Service status and configured limits

" + "" + status + "
" + "
Storage mode" + mode + "Buckets" + (bucketListAvailable ? buckets.size() : "Unavailable") + "Maximum object" + formatBytes(maxObject) + "" + "Total storage limit" + formatBytes(maxTotal) + "

Buckets

" + "

First 25 buckets. Browse all buckets

"); if (!bucketListAvailable || buckets.isEmpty()) { content.append("
") .append(bucketListAvailable ? "No buckets yet." : "Bucket list unavailable.") .append("
"); } else { content.append("
" + ""); for (ObjectStorage.Bucket bucket : buckets.stream().limit(25).toList()) { String versioning = bucket.versioning() == ObjectStorage.VersioningState.NEVER ? "Off" : bucket.versioning().name().toLowerCase(java.util.Locale.ROOT); String ownership = switch (bucket.ownership()) { case BUCKET_OWNER_ENFORCED -> "Owner enforced"; case BUCKET_OWNER_PREFERRED -> "Owner preferred"; case OBJECT_WRITER -> "Object writer"; }; content.append(""); } content.append("
BucketVersioningOwnership
").append(escape(bucket.name())).append("") .append(versioning).append("").append(ownership).append("
"); } content.append("
"); return page(content.toString(), true); } static String performancePage(String csrf) { StringBuilder content = new StringBuilder(consoleHeader(csrf)); content.append("

Performance

") .append("

Live S3 traffic and process health

") .append("Live
") .append("

Live samples arrive about once a second while this tab is visible. ") .append("Traffic excludes admin pages and health checks. Charts keep only the last 60 samples ") .append("in this browser tab.

") .append("") .append("

Collecting samples…

") .append("
") .append(perfCard("Requests / second", "perf-rps")) .append(perfCard("Average latency", "perf-latency")) .append(perfCard("Inbound / second", "perf-inbound")) .append(perfCard("Outbound / second", "perf-outbound")) .append(perfCard("Average CPU · recent", "perf-cpu")) .append(perfCard("Process RAM (RSS)", "perf-ram")) .append(perfCard("GC collections", "perf-gc")) .append(perfCard("In flight", "perf-inflight")) .append("

Inbound and outbound measure HTTP body bytes, including ") .append("S3 metadata responses. CPU is the process share of available cores. ") .append("GC counts reset when the service restarts.

"); return page(content.toString(), true, true); } static String healthPage(DiskStore diskStore, ObjectStorage store, String csrf) { boolean ready = store.ready(); String mode = diskStore == null ? "Cluster" : "Disk"; StringBuilder content = new StringBuilder(consoleHeader(csrf) + "

Health & recovery

" + "

Current service and storage state

" + (ready ? "Ready" : "Unavailable") + "
" + "Storage mode" + mode + ""); if (diskStore != null) { long used = diskStore.usedBytes(); long quota = store.limits().maxTotalBytes(); content.append("Quota used") .append(formatBytes(used)).append(" / ").append(formatBytes(quota)) .append("Current objects") .append(diskStore.objectCount()).append(""); try { FileStore volume = Files.getFileStore(diskStore.root()); long free = volume.getUsableSpace(); content.append("Filesystem available") .append(formatBytes(free)).append(""); if (free < Math.max(0, quota - used)) content.append("

Filesystem free space is below the remaining configured quota. " + "The volume can fill before the quota is reached.

"); } catch (IOException unavailable) { content.append("Filesystem availableUnavailable" + ""); } } else { content.append("Storage nodesNot measured here" + ""); } content.append("

Recovery readiness

" + "
Latest off-site backupNot reported
" + "
Latest restore testNot reported
" + "

ObjectStore cannot verify external backups or restores. Check your backup jobs " + "and perform a restore drill before relying on this service for important data.

" + "Recovery documentation" + "
"); return page(content.toString(), true); } static String diagnosticsPage(RequestDiagnostics diagnostics, String csrf) { RequestDiagnostics current = diagnostics; RequestDiagnostics.Snapshot snapshot = current == null ? null : current.snapshot(); StringBuilder content = new StringBuilder(consoleHeader(csrf) + "

Request diagnostics

" + "

Recent S3 requests on this gateway

" + "

Five-minute rolling window. Latency percentiles are histogram upper bounds. " + "Admin requests and health checks are excluded. Refresh to update.

"); if (snapshot == null) { content.append("

Request diagnostics are unavailable.

"); } else { content.append("
Requests") .append(snapshot.requests()).append("") .append("4xx / 5xx") .append(snapshot.clientErrors()).append(" / ").append(snapshot.serverErrors()) .append("") .append("p50 / p95") .append(latencyLabel(snapshot.p50Millis())).append(" / ") .append(latencyLabel(snapshot.p95Millis())).append("") .append("p99") .append(latencyLabel(snapshot.p99Millis())).append("
") .append("

Recent errors

Most recent 64 errors; " + "bucket names and request IDs only. Object keys and credentials are not retained.

"); if (snapshot.recentFailures().isEmpty()) { content.append("
No errors in this window.
"); } else { content.append("
" + ""); for (RequestDiagnostics.Failure failure : snapshot.recentFailures()) { content.append(""); } content.append("
Time (UTC)StatusOperationBucketRequest ID
").append(java.time.Instant.ofEpochMilli(failure.timeMillis())) .append("").append(failure.status()).append("") .append(escape(failure.operation())).append("") .append(escape(failure.bucket())).append("") .append(escape(failure.requestId())).append("
"); } content.append("
"); } content.append("

Connection probe

" + "

Download 1 MiB from the admin listener to measure browser-to-gateway timing. " + "This does not measure object reads, disks, or storage nodes.

" + " " + "
"); return page(content.toString(), true); } static String latencyLabel(long upperMillis) { return upperMillis < 0 ? ">10 s" : upperMillis + " ms"; } static String perfCard(String label, String id) { return "" + label + "" + ""; } }