Metrics
Report counters, gauges and timings, then query time-series aggregates (p50/p99/sum/avg) — StatsD/Prometheus-style metrics.
Overview
https://api.infrai.cc/v1/metricsAuthorization: Bearer $INFRAI_API_KEY# Call any /v1/metrics capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/metrics/... \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json"Methods
metrics.report
Report one or more metric points.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
name | string | Required | Metric name. |
value | number | Required | Numeric metric value. |
tags | Record<string, string> | Optional | Key/value tags for grouping. |
Returns
{ ok: boolean }Example
一次性前置(每个范例都假定已完成):
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."curl -X POST https://api.infrai.cc/v1/metrics/report \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "...", "value": 0, "type": "counter"}'import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/metrics/report",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'name': '...', 'value': 0, 'type': 'counter'},
)
resp.raise_for_status()
print(resp.json())const resp = await fetch(
"https://api.infrai.cc/v1/metrics/report",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"name": "...", "value": 0, "type": "counter"}),
},
);
console.log(await resp.json());const resp = await fetch(
"https://api.infrai.cc/v1/metrics/report",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"name": "...", "value": 0, "type": "counter"}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);metrics.batch
批量上报指标数据点
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
points | MetricPoint[] | Required | 指标数据点数组 |
idempotency_key | string | Optional | 幂等键,用于避免重复写入 |
Returns
MetricBatchResultExample
一次性前置(每个范例都假定已完成):
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."curl -X POST https://api.infrai.cc/v1/metrics/batch \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"points": []}'import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/metrics/batch",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'points': []},
)
resp.raise_for_status()
print(resp.json())const resp = await fetch(
"https://api.infrai.cc/v1/metrics/batch",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"points": []}),
},
);
console.log(await resp.json());const resp = await fetch(
"https://api.infrai.cc/v1/metrics/batch",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"points": []}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);metrics.query
查询指标时间序列
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
name | string | Required | 指标名称 |
agg | 'p50' | 'p99' | 'sum' | 'avg' | 'count' | Required | 聚合方式:p50/p99/sum/avg/count |
tags | Record<string, string> | Optional | 按标签过滤 |
window | string | Optional | 聚合时间窗,如 5m、1h |
since | string | Optional | 起始时间 |
until | string | Optional | 结束时间 |
Returns
MetricSeriesExample
一次性前置(每个范例都假定已完成):
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."curl -X GET https://api.infrai.cc/v1/metrics/query \
-H "Authorization: Bearer $INFRAI_API_KEY"import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/metrics/query",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())const resp = await fetch(
"https://api.infrai.cc/v1/metrics/query",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());const resp = await fetch(
"https://api.infrai.cc/v1/metrics/query",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);All capabilities
Every routed capability in this module — the complete public REST contract. The methods above are the guided walkthrough; this index is the full reference.
| Capability | Endpoint | Description |
|---|---|---|
metrics.batch | POST /v1/metrics/batch | Report a batch of metric data points. |
metrics.query | GET /v1/metrics/query | Query a metric time series with aggregation. |
metrics.report | POST /v1/metrics/report | Report a single metric point (counter, gauge, timing, or distribution) with tags and idempotency. |
End-to-end example
A production-style walkthrough of this module: configure once, then run the flow. It exercises most of the module's APIs.
A copy-paste-runnable single-file Python program (stdlib only, no SDK): set your INFRAI_API_KEY, run it, and walk this module's core flow with REAL billed calls — later steps reuse real fields returned by earlier ones. The 12-line helper is the entire integration.
#!/usr/bin/env python3
"""Infrai · metrics — runnable real-app example (single file, zero deps).
Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request
KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..." # <- your key
BASE = "https://api.infrai.cc"
# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
req = request.Request(
BASE + path, method=method,
data=json.dumps(body).encode() if body is not None else None,
headers={"Authorization": f"Bearer {KEY}",
"Content-Type": "application/json"})
try:
with request.urlopen(req, timeout=60) as r:
return json.loads(r.read())
except error.HTTPError as e:
return json.loads(e.read())
def show(label, resp):
print(f"\n== {label} ==")
print(json.dumps(resp, indent=2, ensure_ascii=False))
return resp
# 1) metrics.report — POST /v1/metrics/report · Report a single metric point (counter, gauge, timing, or distribution) with tags and idempotency.
r1 = show("metrics.report", infrai("POST", "/v1/metrics/report", {"name":"...","value":0,"type":"counter"}))
# 2) metrics.batch — POST /v1/metrics/batch · Report a batch of metric data points.
r2 = show("metrics.batch", infrai("POST", "/v1/metrics/batch", {"points":[]}))
# 3) metrics.query — GET /v1/metrics/query · Query a metric time series with aggregation.
r3 = show("metrics.query", infrai("GET", "/v1/metrics/query"))
一次性前置(每个范例都假定已完成):
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."# 1) Auth: every call is a raw HTTPS request to the Infrai gateway carrying
# only your project key. No SDK, no install.
# Get your key: sign in with Google/GitHub at https://infrai.cc/login for a
# project key + $2 free credit (email sign-in starts at $0). On 402
# INSUFFICIENT_CREDIT, add funds at https://infrai.cc/billing (or POST
# /v1/account/topup and open the returned checkout_url).
export INFRAI_API_KEY="ifr_..." # from https://infrai.cc/login
# 2) metrics.report
curl -X POST https://api.infrai.cc/v1/metrics/report \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "...", "value": 0, "type": "counter"}'
# 3) metrics.batch
curl -X POST https://api.infrai.cc/v1/metrics/batch \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"points": []}'
# 4) metrics.query
curl -X GET https://api.infrai.cc/v1/metrics/query \
-H "Authorization: Bearer $INFRAI_API_KEY"
# 1) Auth: every call is a raw HTTPS request carrying only your project key.
# No SDK to install — just the `requests` library.
import os, requests
BASE = "https://api.infrai.cc"
HEADERS = {
"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}",
"Content-Type": "application/json",
}
# 2) metrics.report
import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/metrics/report",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'name': '...', 'value': 0, 'type': 'counter'},
)
resp.raise_for_status()
print(resp.json())
# 3) metrics.batch
import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/metrics/batch",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'points': []},
)
resp.raise_for_status()
print(resp.json())
# 4) metrics.query
import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/metrics/query",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())
// 1) Auth: every call is a raw HTTPS request carrying only your project key.
// No SDK to install — just the built-in fetch().
const BASE = "https://api.infrai.cc";
const HEADERS = {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
};
// 2) metrics.report
const resp = await fetch(
"https://api.infrai.cc/v1/metrics/report",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"name": "...", "value": 0, "type": "counter"}),
},
);
console.log(await resp.json());
// 3) metrics.batch
const resp = await fetch(
"https://api.infrai.cc/v1/metrics/batch",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"points": []}),
},
);
console.log(await resp.json());
// 4) metrics.query
const resp = await fetch(
"https://api.infrai.cc/v1/metrics/query",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());
// 1) Auth: every call is a raw HTTPS request carrying only your project key.
// No SDK to install — just the built-in fetch(), typed.
const BASE = "https://api.infrai.cc";
const HEADERS: Record<string, string> = {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
};
// 2) metrics.report
const resp = await fetch(
"https://api.infrai.cc/v1/metrics/report",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"name": "...", "value": 0, "type": "counter"}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 3) metrics.batch
const resp = await fetch(
"https://api.infrai.cc/v1/metrics/batch",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"points": []}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 4) metrics.query
const resp = await fetch(
"https://api.infrai.cc/v1/metrics/query",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);