# at.happyproto.server.getScriptMetrics

> How one of the caller's own instances' scripts ran in a window: every script that ran, or with trigger, one script's series. Customers only.

- Kind: query
- Authority: server.happyproto.at
- Lexicon: 1
- Published by [happyproto.at](https://lexicon.garden/identity/did:plc:mo7vq4jbioxwafy5zkcc3eux), the NSID's authority

## Links

- [Documentation](https://lexicon.garden/lexicon/did:plc:mo7vq4jbioxwafy5zkcc3eux/at.happyproto.server.getScriptMetrics)
- [Schema JSON](https://lexicon.garden/lexicon/did:plc:mo7vq4jbioxwafy5zkcc3eux/at.happyproto.server.getScriptMetrics/schema.json)
- [Analytics](https://lexicon.garden/lexicon/did:plc:mo7vq4jbioxwafy5zkcc3eux/at.happyproto.server.getScriptMetrics/analytics)

## Query (`at.happyproto.server.getScriptMetrics`)

Type: query · GET

### Parameters (query string)

- `id` (string, required): The instance's UUID.
- `step` (string): With trigger: how wide each point is. 1m and 30m suit 1h and 24h; 1h and 1d suit 7d and 30d. Defaults to the window's own.
  - Constraints: knownValues: 1m | 30m | 1h | 1d
- `trigger` (string): One script's trigger, such as xrpc.query:com.example.getThing, at most 400 characters. With it, the reply is that script's series; without it, every script that ran.
- `window` (string): How far back to read. 1h and 24h come from the instance's memory; 7d and 30d from what it stored, as far back as it keeps.
  - Constraints: default: "1h", knownValues: 1h | 24h | 7d | 30d

### Output (application/json)

- `enabled` (boolean, required): Whether the instance is recording metrics at all.
- `points` (array): With trigger: the window in steps, oldest first.
  - `items` (ref)
    - Reference: `#point`
- `retentionDays` (integer): On 7d and 30d: how many days the instance keeps, so a longer window covers only that.
- `script` (ref): With trigger: the script, over the whole window.
  - Reference: `#seriesScript`
- `scripts` (array): Without trigger: every script that ran in the window.
  - `items` (ref)
    - Reference: `#script`
- `step` (string): With trigger: how wide each point is.
  - Constraints: knownValues: 1m | 30m | 1h | 1d
- `window` (string, required)
  - Constraints: knownValues: 1h | 24h | 7d | 30d

### Errors

- `InvalidRequest`: The id is not a UUID, or the window, step or trigger is not one this method takes.
- `NotFound`: No such instance, or it is not the caller's. These are indistinguishable.
- `ScriptNotRun`: With trigger: that script has not run in the window.
- `MetricsUnavailable`: The instance is not running, or its host cannot be reached.
- `MetricsBusy`: Too many metrics reads are running for this instance or its host. Try again shortly.
- `MetricsTimeout`: The instance's HappyView did not answer in time. Try again shortly.
- `NotSupported`: The instance runs a HappyView too old to report its metrics. Upgrading it fixes this.
- `AuthRequired`: This endpoint requires an authenticated caller.
- `Forbidden`: The caller is not a HappyProto customer, or the provisioner refused them.
- `InvalidSlug`: Passed through from the provisioner.
- `SlugTaken`: Passed through from the provisioner.
- `NotEntitled`: Passed through from the provisioner.
- `InstanceLimit`: Passed through from the provisioner.
- `NoCapacity`: Passed through from the provisioner.
- `OperationInProgress`: Passed through from the provisioner.
- `Upstream`: The provisioner is unreachable, not configured, or answered with an error it does not explain to callers.

## #outcomes (`at.happyproto.server.getScriptMetrics#outcomes`)

Type: object

How the runs ended, by outcome. Every outcome is present, 0 when none ended that way.

### Properties

- `error` (integer, required)
- `memory` (integer, required)
- `missingHandle` (integer, required)
- `noInterpreter` (integer, required)
- `ok` (integer, required)
- `runtime` (integer, required)
- `syntax` (integer, required)
- `timeout` (integer, required)
- `trap` (integer, required)

## #percentiles (`at.happyproto.server.getScriptMetrics#percentiles`)

Type: object

Durations in whole microseconds. A value nothing measured is absent; a point carries only p50, p95 and max.

### Properties

- `max` (integer)
- `mean` (integer)
- `p50` (integer)
- `p95` (integer)
- `p99` (integer)

## #point (`at.happyproto.server.getScriptMetrics#point`)

Type: object

### Properties

- `outcomes` (ref, required)
  - Reference: `#outcomes`
- `runs` (integer, required)
- `start` (string · datetime, required)
- `wallUs` (ref, required)
  - Reference: `#percentiles`

## #script (`at.happyproto.server.getScriptMetrics#script`)

Type: object

### Properties

- `kind` (string, required): What fired it, such as xrpc_query, record_event or job.
- `layer` (string, required): Where the script came from, such as project or dashboard.
- `memoryPeakBytes` (integer): The most memory one run used. Absent when no run measured it.
- `outcomes` (ref, required)
  - Reference: `#outcomes`
- `runs` (integer, required)
- `trigger` (string, required)
- `wallUs` (ref, required): Each run's wall time, start to finish.
  - Reference: `#percentiles`

## #seriesScript (`at.happyproto.server.getScriptMetrics#seriesScript`)

Type: object

### Properties

- `kind` (string, required)
- `outcomes` (ref, required)
  - Reference: `#outcomes`
- `runs` (integer, required)
- `trigger` (string, required)
- `wallUs` (ref, required)
  - Reference: `#percentiles`

## Schema

```json
{
  "$type": "com.atproto.lexicon.schema",
  "defs": {
    "main": {
      "description": "How one of the caller's own instances' scripts ran in a window: every script that ran, or with trigger, one script's series. Customers only.",
      "errors": [
        {
          "description": "The id is not a UUID, or the window, step or trigger is not one this method takes.",
          "name": "InvalidRequest"
        },
        {
          "description": "No such instance, or it is not the caller's. These are indistinguishable.",
          "name": "NotFound"
        },
        {
          "description": "With trigger: that script has not run in the window.",
          "name": "ScriptNotRun"
        },
        {
          "description": "The instance is not running, or its host cannot be reached.",
          "name": "MetricsUnavailable"
        },
        {
          "description": "Too many metrics reads are running for this instance or its host. Try again shortly.",
          "name": "MetricsBusy"
        },
        {
          "description": "The instance's HappyView did not answer in time. Try again shortly.",
          "name": "MetricsTimeout"
        },
        {
          "description": "The instance runs a HappyView too old to report its metrics. Upgrading it fixes this.",
          "name": "NotSupported"
        },
        {
          "description": "This endpoint requires an authenticated caller.",
          "name": "AuthRequired"
        },
        {
          "description": "The caller is not a HappyProto customer, or the provisioner refused them.",
          "name": "Forbidden"
        },
        {
          "description": "Passed through from the provisioner.",
          "name": "InvalidSlug"
        },
        {
          "description": "Passed through from the provisioner.",
          "name": "SlugTaken"
        },
        {
          "description": "Passed through from the provisioner.",
          "name": "NotEntitled"
        },
        {
          "description": "Passed through from the provisioner.",
          "name": "InstanceLimit"
        },
        {
          "description": "Passed through from the provisioner.",
          "name": "NoCapacity"
        },
        {
          "description": "Passed through from the provisioner.",
          "name": "OperationInProgress"
        },
        {
          "description": "The provisioner is unreachable, not configured, or answered with an error it does not explain to callers.",
          "name": "Upstream"
        }
      ],
      "output": {
        "encoding": "application/json",
        "schema": {
          "description": "Without trigger, window, enabled and scripts. With it, window, step, enabled, script and points.",
          "properties": {
            "enabled": {
              "description": "Whether the instance is recording metrics at all.",
              "type": "boolean"
            },
            "points": {
              "description": "With trigger: the window in steps, oldest first.",
              "items": {
                "ref": "#point",
                "type": "ref"
              },
              "type": "array"
            },
            "retentionDays": {
              "description": "On 7d and 30d: how many days the instance keeps, so a longer window covers only that.",
              "type": "integer"
            },
            "script": {
              "description": "With trigger: the script, over the whole window.",
              "ref": "#seriesScript",
              "type": "ref"
            },
            "scripts": {
              "description": "Without trigger: every script that ran in the window.",
              "items": {
                "ref": "#script",
                "type": "ref"
              },
              "type": "array"
            },
            "step": {
              "description": "With trigger: how wide each point is.",
              "knownValues": [
                "1m",
                "30m",
                "1h",
                "1d"
              ],
              "type": "string"
            },
            "window": {
              "knownValues": [
                "1h",
                "24h",
                "7d",
                "30d"
              ],
              "type": "string"
            }
          },
          "required": [
            "window",
            "enabled"
          ],
          "type": "object"
        }
      },
      "parameters": {
        "properties": {
          "id": {
            "description": "The instance's UUID.",
            "type": "string"
          },
          "step": {
            "description": "With trigger: how wide each point is. 1m and 30m suit 1h and 24h; 1h and 1d suit 7d and 30d. Defaults to the window's own.",
            "knownValues": [
              "1m",
              "30m",
              "1h",
              "1d"
            ],
            "type": "string"
          },
          "trigger": {
            "description": "One script's trigger, such as xrpc.query:com.example.getThing, at most 400 characters. With it, the reply is that script's series; without it, every script that ran.",
            "type": "string"
          },
          "window": {
            "default": "1h",
            "description": "How far back to read. 1h and 24h come from the instance's memory; 7d and 30d from what it stored, as far back as it keeps.",
            "knownValues": [
              "1h",
              "24h",
              "7d",
              "30d"
            ],
            "type": "string"
          }
        },
        "required": [
          "id"
        ],
        "type": "params"
      },
      "type": "query"
    },
    "outcomes": {
      "description": "How the runs ended, by outcome. Every outcome is present, 0 when none ended that way.",
      "properties": {
        "error": {
          "type": "integer"
        },
        "memory": {
          "type": "integer"
        },
        "missingHandle": {
          "type": "integer"
        },
        "noInterpreter": {
          "type": "integer"
        },
        "ok": {
          "type": "integer"
        },
        "runtime": {
          "type": "integer"
        },
        "syntax": {
          "type": "integer"
        },
        "timeout": {
          "type": "integer"
        },
        "trap": {
          "type": "integer"
        }
      },
      "required": [
        "ok",
        "syntax",
        "runtime",
        "missingHandle",
        "timeout",
        "memory",
        "trap",
        "noInterpreter",
        "error"
      ],
      "type": "object"
    },
    "percentiles": {
      "description": "Durations in whole microseconds. A value nothing measured is absent; a point carries only p50, p95 and max.",
      "properties": {
        "max": {
          "type": "integer"
        },
        "mean": {
          "type": "integer"
        },
        "p50": {
          "type": "integer"
        },
        "p95": {
          "type": "integer"
        },
        "p99": {
          "type": "integer"
        }
      },
      "type": "object"
    },
    "point": {
      "properties": {
        "outcomes": {
          "ref": "#outcomes",
          "type": "ref"
        },
        "runs": {
          "type": "integer"
        },
        "start": {
          "format": "datetime",
          "type": "string"
        },
        "wallUs": {
          "ref": "#percentiles",
          "type": "ref"
        }
      },
      "required": [
        "start",
        "runs",
        "outcomes",
        "wallUs"
      ],
      "type": "object"
    },
    "script": {
      "properties": {
        "kind": {
          "description": "What fired it, such as xrpc_query, record_event or job.",
          "type": "string"
        },
        "layer": {
          "description": "Where the script came from, such as project or dashboard.",
          "type": "string"
        },
        "memoryPeakBytes": {
          "description": "The most memory one run used. Absent when no run measured it.",
          "type": "integer"
        },
        "outcomes": {
          "ref": "#outcomes",
          "type": "ref"
        },
        "runs": {
          "type": "integer"
        },
        "trigger": {
          "type": "string"
        },
        "wallUs": {
          "description": "Each run's wall time, start to finish.",
          "ref": "#percentiles",
          "type": "ref"
        }
      },
      "required": [
        "trigger",
        "kind",
        "layer",
        "runs",
        "outcomes",
        "wallUs"
      ],
      "type": "object"
    },
    "seriesScript": {
      "properties": {
        "kind": {
          "type": "string"
        },
        "outcomes": {
          "ref": "#outcomes",
          "type": "ref"
        },
        "runs": {
          "type": "integer"
        },
        "trigger": {
          "type": "string"
        },
        "wallUs": {
          "ref": "#percentiles",
          "type": "ref"
        }
      },
      "required": [
        "trigger",
        "kind",
        "runs",
        "outcomes",
        "wallUs"
      ],
      "type": "object"
    }
  },
  "id": "at.happyproto.server.getScriptMetrics",
  "lexicon": 1
}
```
