Skip to content

Send counts for unit cost

Unit cost divides each tenant’s cost by a count. Every source gives Seylo the same four things and nothing else:

tenant, unit, day (or hour), count

Source Where the counts live Good for
A query on your database, run in your cluster Your cluster’s metrics store Counts that sit in a database, and an organisation that wants them to stay in its own account
Your application publishes them Your cluster’s metrics store An application that already exposes the numbers
A push Seylo, counts only A system outside the cluster, or a nightly export from a warehouse
A CSV Seylo, counts only A quick start, or a one-off backfill

Reading counts straight from a data warehouse (BigQuery, Redshift, Synapse, Snowflake) is not available. To use warehouse data, run the query in the warehouse and push the result.

Use a tenant’s code, never a name or an identifier of a person. Days are UTC calendar days.

Seylo never connects to your database and never holds its password. Instead a CronJob in your own cluster runs one read-only query you write, checks that the result holds only counts, and writes them to your cluster’s metrics store. The password is a Secret you create; it is never a chart value and never leaves the cluster.

It needs the seylo-observability chart that includes the job (0.2.24), with the metrics store on. It is off by default.

  1. Create a view that returns only counts, and a database user that may read that view and nothing else. The page shows an example for your engine and your industry. For Postgres:

    CREATE OR REPLACE VIEW seylo_unit_counts AS
    SELECT store_code AS tenant, 'order' AS unit,
    (completed_at AT TIME ZONE 'UTC')::date AS day, count(*) AS count
    FROM orders
    WHERE completed_at >= (now() AT TIME ZONE 'UTC')::date - 35
    GROUP BY 1, 2, 3;
    CREATE ROLE seylo_counts LOGIN PASSWORD '<choose a password>';
    GRANT CONNECT ON DATABASE <your database> TO seylo_counts;
    GRANT USAGE ON SCHEMA public TO seylo_counts;
    GRANT SELECT ON public.seylo_unit_counts TO seylo_counts;
    ALTER ROLE seylo_counts SET default_transaction_read_only = on;
    ALTER ROLE seylo_counts SET statement_timeout = '60s';

    A distinct count such as count(DISTINCT customer_id) reads the identifier inside your database. Only the number leaves it. The MySQL, MariaDB and SQL Server examples on the page use their own CREATE USER and GRANT SELECT on the same view.

  2. Create the Secret, with the password read from your terminal:

    Terminal window
    read -rs DB_PASSWORD
    kubectl create secret generic seylo-unit-metrics-db --namespace seylo-observability \
    --from-literal=host=<database host> \
    --from-literal=port=5432 \
    --from-literal=database=<database name> \
    --from-literal=user=seylo_counts \
    --from-literal=password="$DB_PASSWORD"
  3. Turn the job on with the values the page shows, and upgrade the chart:

    unitMetrics:
    enabled: true
    engine: postgres
    existingSecret: seylo-unit-metrics-db
    schedule: "15 0 * * *" # daily at 00:15 UTC; hourly: "5 * * * *"
    units: [order, customer]
    query: |
    SELECT tenant, unit, day, count FROM seylo_unit_counts
    WHERE day >= (now() AT TIME ZONE 'UTC')::date - 1
    Terminal window
    helm upgrade seylo-observability oci://ghcr.io/seylo-inc/charts/seylo-observability \
    --namespace seylo-observability --reset-then-reuse-values \
    --version 0.2.24 -f unit-metrics.yaml
  4. Press Check on FinOps → Unit cost. To run the job now instead of waiting for its schedule:

    Terminal window
    kubectl create job --from=cronjob/seylo-unit-metrics seylo-unit-metrics-now -n seylo-observability

Return yesterday and today on every run, so a late result for yesterday is picked up by the next one. With the hourly schedule, today’s count is “today so far”, refreshed each hour. The page still shows complete days only.

Engines. postgres, mysql and mariadb run the database’s own client from a pinned image. For SQL Server, set unitMetrics.sqlserver.image to an image of yours that has sqlcmd: Microsoft publishes no maintained sqlcmd-only image, so the chart pins none. For Oracle, and anything else, use engine: custom with your own image and a command that writes the result, tab-separated with its header line, to /work/result.tsv. The Secret’s keys reach it as DB_HOST, DB_PORT, DB_NAME, DB_USER and DB_PASSWORD, and the query is at /query/query.sql. The same guard checks it.

A second container in the same pod never sees the password. It checks the result and refuses the whole result if anything is wrong. Nothing is written, and the refusal names a code and a row number, never a value.

The result must be Refusal code
A header first, then exactly the columns tenant, unit, day, count (any order, any case) no-header, columns, fields
A tenant code of letters, digits, ., _ or -, up to 63 characters, or _all tenant
A unit named in unitMetrics.units unit
A real UTC date, not in the future, no older than maxAgeDays (35) day
A whole number of at most 12 digits count
One row per tenant, unit and day duplicate
At most maxRows rows (50,000) too-many-rows

db-failed means the query itself failed, and guard-failed that the guard could not run. Both say so on Check. A refused result keeps the previous counts, and the page shows how old they are.

The query container’s log holds the database client’s own error, and the guard prints one line per run. Both are in your log store like any pod’s log.

If your application already exposes the counts, no job is needed. It publishes one series per tenant and unit, whose value is the count for the current UTC day so far, reset at 00:00 UTC:

seylo_unit_count{tenant="north-store",unit="order"} 412
seylo_unit_count{tenant="north-store",unit="customer"} 230

Add prometheus.io/scrape: "true" to the pod and list its namespace under Applications that report their own counts on the page. Seylo accepts the series only from namespaces you list, matched on the pod’s own namespace.

Any system can post counts with a token that can write counts for this cluster and do nothing else. It cannot read anything.

  1. On FinOps → Unit cost → Sources → Push counts, create a token (admin). It is shown once; Seylo keeps only a hash and a four-character hint. You can revoke it from the same place.

  2. Post rows:

    Terminal window
    curl -sS -X POST https://<your Seylo address>/api/unit-counts/push \
    -H "Authorization: Bearer $SEYLO_COUNTS_TOKEN" -H "Content-Type: application/json" \
    -d '{"rows":[{"tenant":"north-store","unit":"order","day":"2026-11-12","count":412}]}'

A row has only tenant, unit, day or hour, and count; the body has only rows. A unit that is distinct is never sent by the hour, because hourly distinct counts do not add up to a day’s, and a day is never sent both whole and by the hour. The batch is all or nothing. A later push for the same tenant, unit and day (or hour) replaces the earlier one, which is how you correct a count.

Admins can upload a file on the same page:

tenant,unit,day,count
north-store,order,2026-11-12,412
north-store,customer,2026-11-12,230

It goes through the same checks as a push, is recorded in the audit log, and a later upload for the same day replaces it.

  • A query or your application: in your cluster’s own metrics store. Seylo reads them through the agent, like any other metric.
  • A push or a CSV: Seylo stores them, counts only: a tenant code, a unit, a day and a number. If counts must stay in your account, use a query or your application.

One source per tenant, unit and day. Two sources for the same one, for example the job and a push, are refused for that day and never added.

Check reports what Seylo sees, in sentences. The ones you meet most:

It says What to do
The job is not in the cluster Upgrade the seylo-observability chart with unitMetrics.enabled=true and the values above
The last run was refused, with a code Look the code up in what the guard refuses, fix the query or the view, and run the job again
The last run failed to connect or the query failed Read the query container’s log. The client’s own error is there
No count reported for a tenant on a day Nothing reported it. Seylo fills nothing in. The day is left out of the division
A code maps to no namespace Add a row to the mapping table, or use the namespace’s name as the code
Two sources report the same day Switch one off, or send the correction through the one you keep