# Metrics

> Metrics declared with defineMetric over a table (count, sum or avg per time bucket and dimension), rolled up into metric_points or read from the table, with metric_series and metric_value checked against a permission in the tenant.

- Category: Admin & compliance
- Module: `metrics`
- Modes: `managed`, `custom`
- Docs: https://bettersupabase.com/docs/blocks/metrics
- Page: https://bettersupabase.com/blocks/metrics

## Install

```bash
npx better-supabase add metrics
```

The command also installs `updated-at`, `memberships`, `permissions`.

## Configure

Add the block to `better-supabase.config.ts`:

```ts
import { defineConfig } from "better-supabase/config";

export default defineConfig({
  blocks: {
    // Required by metrics; add installs them too.
    "updated-at": {},
    memberships: {},
    permissions: {},
    // Modes: "managed", "custom". The default is "managed".
    metrics: { mode: "managed" },
  },
});
```

## Client

The block has no React entry yet. Its server-side TypeScript is in `better-supabase/blocks/metrics`.

## Related blocks

Requires: [memberships](https://bettersupabase.com/blocks/memberships.md), [permissions](https://bettersupabase.com/blocks/permissions.md)

Works with: [usage](https://bettersupabase.com/blocks/usage.md), [queue](https://bettersupabase.com/blocks/queue.md)

## Recipes

- [Metrics dashboard](https://bettersupabase.com/recipes/metrics-dashboard.md): A card per metric: the 30-day total against the 30 days before, with daily bars.
