Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45337cd0dc |
No files matched your search
+2
-2
@@ -12,7 +12,7 @@ metadata:
|
||||
title: Courier
|
||||
description: Transaktionsmail für deine Apps über Amazon SES.
|
||||
icon: https://git.aimighty.olares.de/aimighty/courier/raw/branch/main/icon.png
|
||||
version: 26.11.6
|
||||
version: 26.11.7
|
||||
categories:
|
||||
- Applications
|
||||
|
||||
@@ -106,7 +106,7 @@ envs:
|
||||
default: "1000"
|
||||
|
||||
spec:
|
||||
versionName: '26.11.6'
|
||||
versionName: '26.11.7'
|
||||
fullDescription: |
|
||||
**Courier** ist ein kleiner Versanddienst für transaktionale E-Mails:
|
||||
eine Resend-kompatible HTTP-API, Warteschlange, Retry, Logs und
|
||||
|
||||
+5
-1
@@ -4,6 +4,7 @@ import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import {
|
||||
Ban,
|
||||
BarChart3,
|
||||
BookOpen,
|
||||
Globe,
|
||||
KeyRound,
|
||||
@@ -32,7 +33,10 @@ const groups: { title: string; items: Item[] }[] = [
|
||||
},
|
||||
{
|
||||
title: "Betrieb",
|
||||
items: [{ href: "/docs", label: "Dokumentation", icon: BookOpen }],
|
||||
items: [
|
||||
{ href: "/metrics", label: "Metriken", icon: BarChart3 },
|
||||
{ href: "/docs", label: "Dokumentation", icon: BookOpen },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { Globe } from "lucide-react";
|
||||
|
||||
import { CopyButton } from "@/app/copy-button";
|
||||
import { PageHeader } from "@/app/page-header";
|
||||
|
||||
@@ -872,3 +872,56 @@ body {
|
||||
.app-nav--mobile .app-nav__link {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.app-chart {
|
||||
padding: var(--ds-space-3);
|
||||
background: var(--ds-surface-sunken);
|
||||
border: var(--ds-border-thin) solid var(--ds-border);
|
||||
border-radius: var(--ds-radius-surface);
|
||||
}
|
||||
|
||||
.app-chart svg {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.app-chart__grid {
|
||||
stroke: var(--ds-border);
|
||||
stroke-dasharray: 4 4;
|
||||
}
|
||||
|
||||
.app-chart__line {
|
||||
fill: none;
|
||||
stroke: var(--ds-action-bg);
|
||||
stroke-width: 2;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
}
|
||||
|
||||
.app-chart__dot {
|
||||
fill: var(--ds-link);
|
||||
}
|
||||
|
||||
.app-chart__axis {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-top: var(--ds-space-2);
|
||||
color: var(--ds-text-muted);
|
||||
font-size: var(--ds-text-xs);
|
||||
}
|
||||
|
||||
.app-toolbar--compact {
|
||||
grid-template-columns: minmax(12rem, 1fr) auto;
|
||||
}
|
||||
|
||||
.app-toolbar--metrics {
|
||||
grid-template-columns: repeat(2, minmax(10rem, 14rem)) auto;
|
||||
}
|
||||
|
||||
@media (max-width: 63.99rem) {
|
||||
.app-toolbar--compact,
|
||||
.app-toolbar--metrics {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
import Link from "next/link";
|
||||
import { BarChart3 } from "lucide-react";
|
||||
|
||||
import { EmptyState } from "@/app/empty-state";
|
||||
import { PageHeader } from "@/app/page-header";
|
||||
import { datum } from "@/lib/format";
|
||||
import { dailyMetrics, listApiKeys } from "@/lib/queries";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const RANGES = [
|
||||
{ value: "7", label: "7 Tage" },
|
||||
{ value: "14", label: "14 Tage" },
|
||||
{ value: "30", label: "30 Tage" },
|
||||
];
|
||||
|
||||
function dayLabel(day: string): string {
|
||||
return new Intl.DateTimeFormat("de-DE", { day: "2-digit", month: "2-digit" }).format(
|
||||
new Date(`${day}T12:00:00`),
|
||||
);
|
||||
}
|
||||
|
||||
function percent(value: number, total: number): string {
|
||||
if (!total) return "–";
|
||||
return `${Math.round((value / total) * 1000) / 10} %`;
|
||||
}
|
||||
|
||||
export default async function Metrics({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ days?: string; key?: string }>;
|
||||
}) {
|
||||
const params = await searchParams;
|
||||
const days = Number(params.days ?? 14);
|
||||
const keyId = String(params.key ?? "");
|
||||
|
||||
let rows: Awaited<ReturnType<typeof dailyMetrics>> = [];
|
||||
let keys: Awaited<ReturnType<typeof listApiKeys>> = [];
|
||||
let error = "";
|
||||
try {
|
||||
[rows, keys] = await Promise.all([dailyMetrics(days, keyId), listApiKeys()]);
|
||||
} catch (cause) {
|
||||
error = cause instanceof Error ? cause.message : "Datenbank nicht erreichbar";
|
||||
}
|
||||
|
||||
const total = rows.reduce((sum, row) => sum + row.total, 0);
|
||||
const delivered = rows.reduce((sum, row) => sum + row.delivered, 0);
|
||||
const bounced = rows.reduce((sum, row) => sum + row.bounced, 0);
|
||||
const complained = rows.reduce((sum, row) => sum + row.complained, 0);
|
||||
const failed = rows.reduce((sum, row) => sum + row.failed, 0);
|
||||
const final = delivered + bounced + complained + failed;
|
||||
|
||||
const W = 760;
|
||||
const H = 220;
|
||||
const padX = 16;
|
||||
const padTop = 16;
|
||||
const padBottom = 28;
|
||||
const max = Math.max(...rows.map((row) => row.total), 1);
|
||||
const x = (index: number) => padX + (index * (W - 2 * padX)) / Math.max(rows.length - 1, 1);
|
||||
const y = (value: number) => H - padBottom - (value / max) * (H - padTop - padBottom);
|
||||
const line = rows.map((row, index) => `${index === 0 ? "M" : "L"}${x(index)},${y(row.total)}`).join(" ");
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title="Metriken"
|
||||
lead="Volumen, Zustellung und Fehler der letzten Tage. Tageswerte, keine Marketingzahlen."
|
||||
/>
|
||||
|
||||
<form className="app-toolbar app-toolbar--metrics" method="get">
|
||||
<div className="ds-field">
|
||||
<label className="ds-visually-hidden" htmlFor="days">
|
||||
Zeitraum
|
||||
</label>
|
||||
<select className="ds-select" id="days" name="days" defaultValue={String(days)}>
|
||||
{RANGES.map((range) => (
|
||||
<option key={range.value} value={range.value}>
|
||||
{range.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="ds-field">
|
||||
<label className="ds-visually-hidden" htmlFor="key">
|
||||
API-Key
|
||||
</label>
|
||||
<select className="ds-select" id="key" name="key" defaultValue={keyId}>
|
||||
<option value="">Alle API-Keys</option>
|
||||
{keys.map((key) => (
|
||||
<option key={key.id} value={key.id}>
|
||||
{key.app} · {key.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="app-toolbar__actions">
|
||||
<button className="ds-button" type="submit">
|
||||
Anzeigen
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{error ? (
|
||||
<div className="ds-alert ds-alert--danger" role="alert">
|
||||
<div>
|
||||
<p className="ds-alert__title">Datenbank nicht erreichbar</p>
|
||||
<p className="ds-alert__text">{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
) : total === 0 ? (
|
||||
<EmptyState
|
||||
icon={BarChart3}
|
||||
title="Noch keine Daten"
|
||||
text="Sobald Courier Mails verarbeitet, erscheinen hier Volumen und Zustellraten."
|
||||
action={
|
||||
<Link className="ds-button ds-button--sm" href="/docs">
|
||||
API ansehen
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<section className="app-stats" aria-label="Kennzahlen">
|
||||
<article className="ds-card app-stat">
|
||||
<span className="ds-stat__value">{total}</span>
|
||||
<span className="ds-stat__label">Mails</span>
|
||||
<span className="ds-stat__meta">{days} Tage</span>
|
||||
</article>
|
||||
<article className="ds-card app-stat">
|
||||
<span className="ds-stat__value">{percent(delivered, final)}</span>
|
||||
<span className="ds-stat__label">Zustellrate</span>
|
||||
<span className="ds-stat__meta">{delivered} zugestellt</span>
|
||||
</article>
|
||||
<article className="ds-card app-stat">
|
||||
<span className="ds-stat__value">{percent(bounced, final)}</span>
|
||||
<span className="ds-stat__label">Bounce-Rate</span>
|
||||
<span className="ds-stat__meta">{bounced} Bounces</span>
|
||||
</article>
|
||||
<article className="ds-card app-stat">
|
||||
<span className="ds-stat__value">{percent(complained, final)}</span>
|
||||
<span className="ds-stat__label">Complaint-Rate</span>
|
||||
<span className="ds-stat__meta">{complained} Beschwerden</span>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section className="ds-card app-panel" aria-labelledby="verlauf">
|
||||
<div className="app-panel__head">
|
||||
<h2 id="verlauf">Verlauf</h2>
|
||||
</div>
|
||||
<div className="app-chart">
|
||||
<svg
|
||||
viewBox={`0 0 ${W} ${H}`}
|
||||
role="img"
|
||||
aria-label={`Tägliches Mailvolumen der letzten ${days} Tage`}
|
||||
>
|
||||
<title>Mailvolumen pro Tag</title>
|
||||
{[0, 0.5, 1].map((fraction) => (
|
||||
<line
|
||||
key={fraction}
|
||||
x1={padX}
|
||||
x2={W - padX}
|
||||
y1={y(max * fraction)}
|
||||
y2={y(max * fraction)}
|
||||
className="app-chart__grid"
|
||||
/>
|
||||
))}
|
||||
<path d={line} className="app-chart__line" />
|
||||
{rows.map((row, index) => (
|
||||
<circle
|
||||
key={row.day}
|
||||
cx={x(index)}
|
||||
cy={y(row.total)}
|
||||
r={3}
|
||||
className="app-chart__dot"
|
||||
>
|
||||
<title>{`${dayLabel(row.day)}: ${row.total}`}</title>
|
||||
</circle>
|
||||
))}
|
||||
</svg>
|
||||
<div className="app-chart__axis">
|
||||
<span>{dayLabel(rows[0]?.day ?? "")}</span>
|
||||
<span>{dayLabel(rows[rows.length - 1]?.day ?? "")}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="app-table-scroll app-desktop-table app-section">
|
||||
<table className="ds-table">
|
||||
<caption className="ds-visually-hidden">Tageswerte</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tag</th>
|
||||
<th className="ds-table__num">Mails</th>
|
||||
<th className="ds-table__num">Zugestellt</th>
|
||||
<th className="ds-table__num">Bounce</th>
|
||||
<th className="ds-table__num">Beschwerde</th>
|
||||
<th className="ds-table__num">Fehler</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((row) => (
|
||||
<tr key={row.day}>
|
||||
<td>{dayLabel(row.day)}</td>
|
||||
<td className="ds-table__num">{row.total}</td>
|
||||
<td className="ds-table__num">{row.delivered}</td>
|
||||
<td className="ds-table__num">{row.bounced}</td>
|
||||
<td className="ds-table__num">{row.complained}</td>
|
||||
<td className="ds-table__num">{row.failed}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className="app-mobile-list">
|
||||
{rows.map((row) => (
|
||||
<article key={row.day} className="app-mobile-item">
|
||||
<div className="app-mobile-item__top">
|
||||
<span>{dayLabel(row.day)}</span>
|
||||
<span className="ds-badge">{row.total} Mails</span>
|
||||
</div>
|
||||
<div className="app-mobile-item__meta">
|
||||
<span>{row.delivered} zugestellt</span>
|
||||
<span>{row.bounced} Bounce</span>
|
||||
<span>{row.complained} Beschwerde</span>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<p className="app-muted app-section">
|
||||
Stand: {datum(new Date())}. Zustellrate = zugestellt / (zugestellt + Bounce +
|
||||
Beschwerde + Fehler).
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ export default async function Suppressions({
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<form className="app-toolbar" method="get" style={{ gridTemplateColumns: "minmax(12rem, 1fr) auto" }}>
|
||||
<form className="app-toolbar app-toolbar--compact" method="get">
|
||||
<div className="ds-field">
|
||||
<label className="ds-visually-hidden" htmlFor="q">
|
||||
Suche
|
||||
|
||||
@@ -145,3 +145,36 @@ export async function listSuppressions(q?: string, limit = 200) {
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
||||
export type DailyMetric = {
|
||||
day: string;
|
||||
total: number;
|
||||
delivered: number;
|
||||
bounced: number;
|
||||
complained: number;
|
||||
failed: number;
|
||||
};
|
||||
|
||||
export async function dailyMetrics(days = 14, keyId = ""): Promise<DailyMetric[]> {
|
||||
const span = Math.min(Math.max(days, 1), 90);
|
||||
const { rows } = await query<DailyMetric>(
|
||||
`with days as (
|
||||
select generate_series(current_date - ($1::int - 1), current_date, interval '1 day')::date as day
|
||||
)
|
||||
select to_char(d.day, 'YYYY-MM-DD') as day,
|
||||
count(m.id)::int as total,
|
||||
count(m.id) filter (where m.status = 'delivered')::int as delivered,
|
||||
count(m.id) filter (where m.status = 'bounced')::int as bounced,
|
||||
count(m.id) filter (where m.status = 'complained')::int as complained,
|
||||
count(m.id) filter (where m.status = 'failed')::int as failed
|
||||
from days d
|
||||
left join messages m
|
||||
on m.created_at >= d.day
|
||||
and m.created_at < d.day + interval '1 day'
|
||||
and ($2::uuid is null or m.api_key_id = $2)
|
||||
group by d.day
|
||||
order by d.day`,
|
||||
[span, keyId || null],
|
||||
);
|
||||
return rows;
|
||||
}
|
||||
+2
-2
@@ -2,7 +2,7 @@ apiVersion: v2
|
||||
name: courier
|
||||
description: Transaktionsmail-Gateway für hubsport.club über Amazon SES.
|
||||
type: application
|
||||
version: 26.11.6
|
||||
appVersion: "26.11.6"
|
||||
version: 26.11.7
|
||||
appVersion: "26.11.7"
|
||||
icon: https://git.aimighty.olares.de/aimighty/courier/raw/branch/main/icon.png
|
||||
home: https://git.aimighty.olares.de/aimighty/courier
|
||||
@@ -12,7 +12,7 @@ metadata:
|
||||
title: Courier
|
||||
description: Transaktionsmail für deine Apps über Amazon SES.
|
||||
icon: https://git.aimighty.olares.de/aimighty/courier/raw/branch/main/icon.png
|
||||
version: 26.11.6
|
||||
version: 26.11.7
|
||||
categories:
|
||||
- Applications
|
||||
|
||||
@@ -106,7 +106,7 @@ envs:
|
||||
default: "1000"
|
||||
|
||||
spec:
|
||||
versionName: '26.11.6'
|
||||
versionName: '26.11.7'
|
||||
fullDescription: |
|
||||
**Courier** ist ein kleiner Versanddienst für transaktionale E-Mails:
|
||||
eine Resend-kompatible HTTP-API, Warteschlange, Retry, Logs und
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "courier",
|
||||
"version": "26.11.6",
|
||||
"version": "26.11.7",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -H 0.0.0.0 -p 3400",
|
||||
|
||||
Reference in new issue
Block a user