Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

1.0 KB
Raw Blame
import { z } from "zod";

import type { StatsProvider } from "../types";

const nonNegativeFiniteNumberSchema = z.number().finite().nonnegative();

const statusSchema = z
  .object({
    numActiveSessions: nonNegativeFiniteNumberSchema,
    numConnections: nonNegativeFiniteNumberSchema,
    bytesProxied: nonNegativeFiniteNumberSchema,
  })
  .passthrough();

export const syncthingRelayStatsProvider = {
  getHttpAuthentication: () => ({ headers: {} }),
  metrics: [
    { key: "numActiveSessions", label: "Active sessions", unit: "count" },
    { key: "numConnections", label: "Connections", unit: "count" },
    { key: "bytesProxied", label: "Bytes proxied", unit: "bytes" },
  ],
  async fetchAsync(context) {
    const response = await context.requestAsync("/status", { signal: context.signal });
    const status = statusSchema.parse(response);

    return {
      numActiveSessions: status.numActiveSessions,
      numConnections: status.numConnections,
      bytesProxied: status.bytesProxied,
    };
  },
} satisfies StatsProvider;