constqueuedAge=Number((db.prepare("SELECT COALESCE(MAX(strftime('%s','now')-strftime('%s',created_at)),0) AS age FROM sync_jobs WHERE status='queued'").get()as{age: number}).age);
constsigned=count("SELECT count(*) AS count FROM sources WHERE is_enabled=1 AND webhook_mode='signed'");constrecentWebhook=count("SELECT count(*) AS count FROM sources WHERE is_enabled=1 AND webhook_mode='signed' AND last_webhook_at>=datetime('now','-24 hours')");
constcacheRows=db.prepare("SELECT attachments_json FROM posts").all()as{attachments_json: string}[];letcacheBytes=0;for(constrowofcacheRows){try{cacheBytes+=(JSON.parse(row.attachments_json)as{url?: string;size?: number}[]).filter((item)=>item.url?.startsWith("/uploads/cache/")).reduce((sum,item)=>sum+Number(item.size||0),0);}catch{}}
return["# HELP mebbling_sources_enabled Number of enabled sources","# TYPE mebbling_sources_enabled gauge",line("mebbling_sources_enabled",count("SELECT count(*) AS count FROM sources WHERE is_enabled=1")),"# HELP mebbling_posts_public Number of visible public posts","# TYPE mebbling_posts_public gauge",line("mebbling_posts_public",count("SELECT count(*) AS count FROM posts WHERE visibility='PUBLIC' AND hidden=0")),"# HELP mebbling_sync_jobs Number of sync jobs by status","# TYPE mebbling_sync_jobs gauge",...jobs.map((job)=>line("mebbling_sync_jobs",job.count,`status=\"${job.status.replaceAll('"','')}\"`)),"# HELP mebbling_alert_deliveries Alert deliveries by status","# TYPE mebbling_alert_deliveries gauge",...alerts.map((alert)=>line("mebbling_alert_deliveries",alert.count,`status=\"${alert.status.replaceAll('"','')}\"`)),line("mebbling_sync_queue_oldest_seconds",queuedAge),line("mebbling_signed_webhooks",signed),line("mebbling_signed_webhooks_recent_24h",recentWebhook),line("mebbling_attachment_cache_bytes",cacheBytes)].join("\n")+"\n";