When something breaks in production, do you wait for users to complain, or let metrics come to you? CloudBase CLI ≥ v3.5.8 brings monitoring and alerting into the terminal — one command to check the health of 12 resource types, one line of config to broadcast anomalies automatically. This post walks you from troubleshooting to automated inspection.
Why it's worth using
- Fast: one command pulls real-time metrics for cloud functions / database / Cloud Run and 12 resource types in total — no more clicking through console layers.
- Scriptable: commands drop straight into scripts, scheduled inspections and CI pipelines, with anomalies broadcast automatically.
- Safety net: out-of-bound metrics trigger automatic alerts, so quality risks reach you proactively instead of waiting for user complaints.
1. Monitoring queries (tcb monitor) — resource health at a glance
A unified entry point covering cloud functions / database / MySQL / Cloud Run / static hosting / authentication / LLM / knowledge base / gateway / login / DB Connector / environment QPS — 12 resource types.
Typical scenarios
- Troubleshooting: function errors, sudden latency spikes? Pull the error count and latency curves in one go.
- Inspection / weekly reports:
--jsonoutput feeds straight into scripts to generate resource-level reports automatically. - Free time window:
--last 7d/--last 24hto look back, with precise metric names.
# error count for a function over the last 7 days
tcb monitor function --name helloWorld --metric-name FunctionError --last 7d
# latency over the last 24 hours, structured output for scripts
tcb monitor function --name helloWorld --metric-name FunctionDuration --last 24h --json
Common parameters:
- Relative time window:
--last 7d/--last 24h - Precise metric:
--metric-name FunctionError - Structured output:
--json(for script consumption) - Metric list:
tcb monitor schema <resource-type>
2. Alert policies (tcb api monitor) — let risks find you
Scenario: alert on function errors. When any cloud function version reports errors, push a notification to WeCom / email / SMS immediately — a safety net for production quality.
tcb api monitor CreateAlarmPolicy --api-version 2018-07-24 --body '{
"Module": "monitor",
"PolicyName": "云函数版本错误数告警",
"MonitorType": "MT_QCE",
"Namespace": "SCF",
"ProjectId": 0,
"Enable": 1,
"Condition": {
"IsUnionRule": 1,
"Rules": [
{ "MetricName": "Error", "Period": 60, "Operator": "gt",
"Value": "0", "ContinuePeriod": 1, "NoticeFrequency": 3600, "IsPowerNotice": 0 }
]
},
"NoticeIds": ["notice-xxxxxxxx"]
}'
Key points:
- Creating it covers all function versions under that namespace — no per-instance binding.
- It returns a
PolicyIdyou can use later to delete or bind to specific instances precisely. NoticeIdsis the notification template ID; remove the line if you don't need it.
3. Upgrade to a supported version
npm i -g @cloudbase/cli@latest
tcb -v # confirm ≥ 3.5.8
Reference docs
- Monitoring: https://docs.cloudbase.net/cli-v1/monitor/management
- Alerting: https://docs.cloudbase.net/cli-v1/monitor/alert
- Observability platform API: https://cloud.tencent.com/document/api/248/87588

