Files
homelab-gitops/apps/immich-postgresql/metrics-view.sql
T

18 lines
646 B
SQL

CREATE OR REPLACE VIEW public.immich_monitoring_user_assets AS
SELECT
u.id::text AS user_guid,
count(a.id) FILTER (WHERE a.type = 'IMAGE')::bigint AS photos,
count(a.id) FILTER (WHERE a.type = 'VIDEO')::bigint AS videos,
coalesce(u."quotaUsageInBytes", 0)::bigint AS storage_bytes
FROM public."user" AS u
LEFT JOIN public.asset AS a
ON a."ownerId" = u.id
AND a."deletedAt" IS NULL
AND a.status = 'active'
WHERE u."deletedAt" IS NULL
AND u.status = 'active'
GROUP BY u.id, u."quotaUsageInBytes";
GRANT USAGE ON SCHEMA public TO cnpg_metrics_exporter;
GRANT SELECT ON public.immich_monitoring_user_assets TO cnpg_metrics_exporter;