Metric routes: define, query, watch
The Metric Verbs define, query, watch as api.sb routes, with inputs, result, refusals and an example.
Reference for Metric, one group of Metric routes.
Metric.define
Define compiles a Metric’s query against the Startup’s Events and Entries and lists every Event it reads. Verb page.
POST /{namespace}/ metrics/ defineBody, as JSON: the inputs. 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
curl -X POST https: //api.sb/ leaseline.app/ metrics/ define \
-H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
-H "Content-Type: application/ json" \
-d '{"name": "Leaseline", "query": "Example query", "unit": "Example unit"}'{
"api": "https: //api.sb/ leaseline.app",
"metric": {
"$id": "https: //api.sb/ leaseline.app/ metrics/ metric_GXFHAlK100",
"$type": "Metric",
"query": "Example query",
"status": "draft"
},
"action": {
"$id": "https: //api.sb/ leaseline.app/ actions/ act_br07HsG8MG",
"operation": "Metric.define",
"status": "done"
},
"links": {
"self": "https: //api.sb/ leaseline.app/ actions/ act_br07HsG8MG"
}
}Metric.query
Query reads Metrics or Events as a trend, funnel, retention curve, path or lifecycle, broken down by any property. Verb page.
POST /{namespace}/ metrics/ queryBody, as JSON: the inputs. 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
curl -X POST https: //api.sb/ leaseline.app/ metrics/ query \
-H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
-H "Content-Type: application/ json" \
-d '{"shape": "trend"}'{
"api": "https: //api.sb/ leaseline.app",
"rows": {},
"metric": {
"$id": "https: //api.sb/ leaseline.app/ metrics/ metric_GXFHAlK100",
"$type": "Metric",
"query": "Example query",
"status": "draft"
},
"action": {
"$id": "https: //api.sb/ leaseline.app/ actions/ act_br07HsG8MG",
"operation": "Metric.query",
"status": "done"
},
"links": {
"self": "https: //api.sb/ leaseline.app/ actions/ act_br07HsG8MG"
}
}Metric.watch
Watch alerts the owner of a Metric when it crosses a threshold, by a Task or a Message. Verb page.
POST /{namespace}/ metrics/ {metric}/ watchPath: metric. Body, as JSON: the other inputs. 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
curl -X POST https: //api.sb/ leaseline.app/ metrics/ metric_GXFHAlK100/ watch \
-H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
-H "Content-Type: application/ json" \
-d '{"threshold": 1, "direction": "above"}'{
"api": "https: //api.sb/ leaseline.app",
"watch": {
"$id": "https: //api.sb/ leaseline.app/ watches/ watch_9o4vCuR17L",
"$type": "Watch",
"selector": "Example selector",
"url": "https: //leaseline.app"
},
"metric": {
"$id": "https: //api.sb/ leaseline.app/ metrics/ metric_GXFHAlK100",
"$type": "Metric",
"query": "Example query",
"status": "draft"
},
"action": {
"$id": "https: //api.sb/ leaseline.app/ actions/ act_br07HsG8MG",
"operation": "Metric.watch",
"status": "done"
},
"links": {
"self": "https: //api.sb/ leaseline.app/ actions/ act_br07HsG8MG"
}
}