add queued gateway admission and finish admin monitoring
This commit is contained in:
1 parent
8f75ebdf96
commit
0e6fca81b3
12 files changed
+288
-35
No files matched your search
@@ -94,6 +94,56 @@ public class UsageAuditService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Small, read-only aggregate used by the admin dashboard. Keeping these
|
||||
* counters in the control plane means the dashboard no longer presents
|
||||
* placeholder dashes while the detailed usage table remains paginated.
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Map<String, Object> adminSummary(String token, AuthService auth) {
|
||||
auth.requireAdmin(token);
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("callsToday", count("SELECT COUNT(*) FROM usage_events WHERE deleted_at IS NULL AND event_kind = 'call' AND created_at >= CURRENT_DATE"));
|
||||
result.put("callsThisMonth", count("SELECT COUNT(*) FROM usage_events WHERE deleted_at IS NULL AND event_kind = 'call' AND created_at >= date_trunc('month', now())"));
|
||||
result.put("waiting", count("SELECT COUNT(*) FROM usage_events WHERE deleted_at IS NULL AND status IN ('queued','running')"));
|
||||
result.put("costToday", decimal("SELECT COALESCE(SUM(cost_amount),0) FROM usage_events WHERE deleted_at IS NULL AND status = 'succeeded' AND created_at >= CURRENT_DATE"));
|
||||
result.put("costThisMonth", decimal("SELECT COALESCE(SUM(cost_amount),0) FROM usage_events WHERE deleted_at IS NULL AND status = 'succeeded' AND created_at >= date_trunc('month', now())"));
|
||||
result.put("series", jdbc.query(
|
||||
"SELECT to_char(day, 'YYYY-MM-DD') AS day, COUNT(ue.id) AS count " +
|
||||
"FROM generate_series(CURRENT_DATE - INTERVAL '6 days', CURRENT_DATE, INTERVAL '1 day') day " +
|
||||
"LEFT JOIN usage_events ue ON ue.deleted_at IS NULL AND ue.created_at >= day AND ue.created_at < day + INTERVAL '1 day' " +
|
||||
"GROUP BY day ORDER BY day",
|
||||
(rs, row) -> Map.of("date", rs.getString("day"), "count", rs.getLong("count"))));
|
||||
result.put("capacityGroups", jdbc.query(
|
||||
"SELECT m.id, m.public_name, COALESCE(m.max_concurrency, 0) AS max_concurrency, " +
|
||||
"COUNT(*) FILTER (WHERE ue.status = 'running') AS running, " +
|
||||
"COUNT(*) FILTER (WHERE ue.status IN ('queued','running')) AS queued " +
|
||||
"FROM model_catalog m LEFT JOIN usage_events ue ON ue.model_id = m.id " +
|
||||
"AND ue.deleted_at IS NULL AND ue.created_at >= now() - INTERVAL '10 minutes' " +
|
||||
"WHERE m.deleted_at IS NULL AND m.status = 'active' " +
|
||||
"GROUP BY m.id, m.public_name, m.max_concurrency ORDER BY m.public_name LIMIT 100",
|
||||
(rs, row) -> {
|
||||
Map<String, Object> group = new LinkedHashMap<>();
|
||||
group.put("id", rs.getString("id"));
|
||||
group.put("name", rs.getString("public_name"));
|
||||
group.put("limit", rs.getInt("max_concurrency"));
|
||||
group.put("running", rs.getLong("running"));
|
||||
group.put("queued", rs.getLong("queued"));
|
||||
return group;
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
|
||||
private long count(String sql) {
|
||||
Number value = jdbc.queryForObject(sql, Number.class);
|
||||
return value == null ? 0L : value.longValue();
|
||||
}
|
||||
|
||||
private java.math.BigDecimal decimal(String sql) {
|
||||
java.math.BigDecimal value = jdbc.queryForObject(sql, java.math.BigDecimal.class);
|
||||
return value == null ? java.math.BigDecimal.ZERO : value;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Map<String, Object> detail(String token, String id, AuthService auth) {
|
||||
auth.requireAdmin(token);
|
||||
|
||||
Reference in new issue
Block a user