Metric programs: define, query, watch
The Metric Verbs define, query, watch as MCP do programs, with inputs, result, refusals and an example.
Reference for Metric, one group of Metric programs.
Metric.define
Define compiles a Metric’s query against the Startup’s Events and Entries and lists every Event it reads. Verb page.
do: return await $.Metric.define(input)Emits Metric.defined.
Inputs
| Input | Type | Required | Description |
|---|---|---|---|
name | string | required | The Metric’s name. |
query | text | required | The query, over Events and Entries. |
unit | string | required | What one unit of it is. |
Returns
| Output | Type | Required | Description |
|---|---|---|---|
metric | Metric | required | The defined Metric. |
Refuses when
| Check | Error | Fix | Then call |
|---|---|---|---|
| The key is valid, but its scopes do not allow this operation. | forbidden | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
Example
{
"name": "do",
"arguments": {
"code": "return await $.Metric.define({ name: 'Leaseline', query: 'Example query', unit: 'Example unit' })"
}
}Metric.query
Query reads Metrics or Events as a trend, funnel, retention curve, path or lifecycle, broken down by any property. Verb page.
do: return await $.Metric.query(input)Emits Metric.queried.
Inputs
| Input | Type | Required | Description |
|---|---|---|---|
metric | Metric | The Metric to read; omitted, the query names Events directly. | |
shape | string | required | The analysis to run. |
breakdown | string | The property to split by, such as an Organization or a Motion. | |
window | string | The time range, such as 30d. |
Returns
| Output | Type | Required | Description |
|---|---|---|---|
rows | json | required | The result rows, each number with its readability. |
metric | Metric | required | The Metric read. |
Refuses when
| Check | Error | Fix | Then call |
|---|---|---|---|
| The key is valid, but its scopes do not allow this operation. | forbidden | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
Example
{
"name": "do",
"arguments": {
"code": "return await $.Metric.query({ shape: 'trend' })"
}
}Metric.watch
Watch alerts the owner of a Metric when it crosses a threshold, by a Task or a Message. Verb page.
do: return await $.Metric.watch(input)Emits Metric.watched.
Inputs
| Input | Type | Required | Description |
|---|---|---|---|
metric | Metric | required | The Metric to watch. |
threshold | number | required | The value that trips it. |
direction | string | required | Trip when the Metric goes above or below the threshold. |
Returns
| Output | Type | Required | Description |
|---|---|---|---|
watch | Watch | required | The Watch that checks it. |
metric | Metric | required | The Metric now watched. |
Refuses when
| Check | Error | Fix | Then call |
|---|---|---|---|
| The key is valid, but its scopes do not allow this operation. | forbidden | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
Example
{
"name": "do",
"arguments": {
"code": "return await $.Metric.watch({ metric: 'metric_GXFHAlK100', threshold: 1, direction: 'above' })"
}
}