feat(monitoring): add stats counters API and public status page
Add GET /api/stats exposing cumulative counters (feeds created/deleted, emails received/rejected, recent date-times) plus live values (active feeds, active WebSub subscriptions). Counters persist in a stats:counters KV singleton and are incremented at the email-processing chokepoint and feed create/delete paths. Replace the / → /admin redirect with a public status page rendering these figures with a link to the admin. Co-Authored-By: Claude Opus 4.7 <[email protected]>
This commit is contained in:
1 parent
f4d5edda0e
commit
b534ce5bf8
15 files changed
+484
-6
No files matched your search
@@ -7,6 +7,7 @@ import {
|
||||
FeedMetadata,
|
||||
} from "../types";
|
||||
import { notifySubscribers } from "../utils/websub";
|
||||
import { bumpCounters } from "../utils/stats";
|
||||
import { logger } from "./logger";
|
||||
import { FEED_MAX_BYTES } from "../config/constants";
|
||||
|
||||
@@ -248,8 +249,15 @@ export async function processEmail(
|
||||
ctx?: ExecutionContext,
|
||||
): Promise<Response> {
|
||||
const validation = await validateEmail(input, env);
|
||||
if (!validation.ok) return validation.response;
|
||||
if (!validation.ok) {
|
||||
await bumpCounters(env.EMAIL_STORAGE, { emails_rejected: 1 });
|
||||
return validation.response;
|
||||
}
|
||||
|
||||
await storeEmail(validation.feedId, input, env, ctx);
|
||||
await bumpCounters(env.EMAIL_STORAGE, {
|
||||
emails_received: 1,
|
||||
last_email_at: new Date().toISOString(),
|
||||
});
|
||||
return new Response("Email processed successfully", { status: 200 });
|
||||
}
|
||||
Reference in new issue
Block a user