feat: add delta mode for counter metrics using ClickHouse lag()
Counter metrics like chunks.exported.count are monotonically increasing. Add mode=delta query parameter to the agent metrics API that computes per-bucket deltas server-side using ClickHouse lag() window function: max(value) per bucket, then greatest(0, current - previous) to get the increase per period with counter-reset handling. The chunks exported/dropped charts now show throughput per bucket instead of the ever-increasing cumulative total. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,15 +9,17 @@ export function useAgentMetrics(
|
||||
buckets = 60,
|
||||
from?: string,
|
||||
to?: string,
|
||||
mode: 'gauge' | 'delta' = 'gauge',
|
||||
) {
|
||||
const refetchInterval = useRefreshInterval(30_000);
|
||||
return useQuery({
|
||||
queryKey: ['agent-metrics', agentId, names.join(','), buckets, from, to],
|
||||
queryKey: ['agent-metrics', agentId, names.join(','), buckets, from, to, mode],
|
||||
queryFn: async () => {
|
||||
const token = useAuthStore.getState().accessToken;
|
||||
const params = new URLSearchParams({
|
||||
names: names.join(','),
|
||||
buckets: String(buckets),
|
||||
mode,
|
||||
});
|
||||
if (from) params.set('from', from);
|
||||
if (to) params.set('to', to);
|
||||
|
||||
@@ -75,7 +75,7 @@ export default function AgentInstance() {
|
||||
const { data: agentMetrics } = useAgentMetrics(
|
||||
agent?.instanceId || null,
|
||||
['cameleer.chunks.exported.count', 'cameleer.chunks.dropped.count'],
|
||||
60, timeFrom, timeTo,
|
||||
60, timeFrom, timeTo, 'delta',
|
||||
);
|
||||
|
||||
const feedEvents = useMemo<FeedEvent[]>(() => {
|
||||
|
||||
Reference in New Issue
Block a user