railway-metrics
关于
This skill queries Railway service metrics including CPU, memory, network, and disk usage to monitor performance and debug issues. It's triggered when developers ask about resource utilization or service performance, and requires environment and service IDs from the Railway CLI. The skill provides actionable insights through Bash commands that fetch real-time analytics data.
快速安装
Claude Code
推荐/plugin add https://github.com/davila7/claude-code-templatesgit clone https://github.com/davila7/claude-code-templates.git ~/.claude/skills/railway-metrics在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Railway Service Metrics
Query resource usage metrics for Railway services.
When to Use
- User asks "how much memory is my service using?"
- User asks about CPU usage, network traffic, disk usage
- User wants to debug performance issues
- User asks "is my service healthy?" (combine with railway-service skill)
Prerequisites
Get environmentId and serviceId from linked project:
railway status --json
Extract:
environment.id→ environmentIdservice.id→ serviceId (optional - omit to get all services)
MetricMeasurement Values
| Measurement | Description |
|---|---|
| CPU_USAGE | CPU usage (cores) |
| CPU_LIMIT | CPU limit (cores) |
| MEMORY_USAGE_GB | Memory usage in GB |
| MEMORY_LIMIT_GB | Memory limit in GB |
| NETWORK_RX_GB | Network received in GB |
| NETWORK_TX_GB | Network transmitted in GB |
| DISK_USAGE_GB | Disk usage in GB |
| EPHEMERAL_DISK_USAGE_GB | Ephemeral disk usage in GB |
| BACKUP_USAGE_GB | Backup usage in GB |
MetricTag Values (for groupBy)
| Tag | Description |
|---|---|
| DEPLOYMENT_ID | Group by deployment |
| DEPLOYMENT_INSTANCE_ID | Group by instance |
| REGION | Group by region |
| SERVICE_ID | Group by service |
Query
query metrics(
$environmentId: String!
$serviceId: String
$startDate: DateTime!
$endDate: DateTime
$sampleRateSeconds: Int
$averagingWindowSeconds: Int
$groupBy: [MetricTag!]
$measurements: [MetricMeasurement!]!
) {
metrics(
environmentId: $environmentId
serviceId: $serviceId
startDate: $startDate
endDate: $endDate
sampleRateSeconds: $sampleRateSeconds
averagingWindowSeconds: $averagingWindowSeconds
groupBy: $groupBy
measurements: $measurements
) {
measurement
tags {
deploymentInstanceId
deploymentId
serviceId
region
}
values {
ts
value
}
}
}
Example: Last Hour CPU and Memory
Use heredoc to avoid shell escaping issues:
bash <<'SCRIPT'
START_DATE=$(date -u -v-1H +"%Y-%m-%dT%H:%M:%SZ" 2>/dev/null || date -u -d "1 hour ago" +"%Y-%m-%dT%H:%M:%SZ")
ENV_ID="your-environment-id"
SERVICE_ID="your-service-id"
VARS=$(jq -n \
--arg env "$ENV_ID" \
--arg svc "$SERVICE_ID" \
--arg start "$START_DATE" \
'{environmentId: $env, serviceId: $svc, startDate: $start, measurements: ["CPU_USAGE", "MEMORY_USAGE_GB"]}')
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'query metrics($environmentId: String!, $serviceId: String, $startDate: DateTime!, $measurements: [MetricMeasurement!]!) {
metrics(environmentId: $environmentId, serviceId: $serviceId, startDate: $startDate, measurements: $measurements) {
measurement
tags { deploymentId region serviceId }
values { ts value }
}
}' \
"$VARS"
SCRIPT
Example: All Services in Environment
Omit serviceId and use groupBy to get metrics for all services:
bash <<'SCRIPT'
START_DATE=$(date -u -v-1H +"%Y-%m-%dT%H:%M:%SZ" 2>/dev/null || date -u -d "1 hour ago" +"%Y-%m-%dT%H:%M:%SZ")
ENV_ID="your-environment-id"
VARS=$(jq -n \
--arg env "$ENV_ID" \
--arg start "$START_DATE" \
'{environmentId: $env, startDate: $start, measurements: ["CPU_USAGE", "MEMORY_USAGE_GB"], groupBy: ["SERVICE_ID"]}')
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'query metrics($environmentId: String!, $startDate: DateTime!, $measurements: [MetricMeasurement!]!, $groupBy: [MetricTag!]) {
metrics(environmentId: $environmentId, startDate: $startDate, measurements: $measurements, groupBy: $groupBy) {
measurement
tags { serviceId region }
values { ts value }
}
}' \
"$VARS"
SCRIPT
Time Parameters
| Parameter | Description |
|---|---|
| startDate | Required. ISO 8601 format (e.g., 2024-01-01T00:00:00Z) |
| endDate | Optional. Defaults to now |
| sampleRateSeconds | Sample interval (e.g., 60 for 1-minute samples) |
| averagingWindowSeconds | Averaging window for smoothing |
Tip: For last hour, calculate startDate as now - 1 hour in ISO format.
Output Interpretation
{
"data": {
"metrics": [
{
"measurement": "CPU_USAGE",
"tags": { "deploymentId": "...", "serviceId": "...", "region": "us-west1" },
"values": [
{ "ts": "2024-01-01T00:00:00Z", "value": 0.25 },
{ "ts": "2024-01-01T00:01:00Z", "value": 0.30 }
]
}
]
}
}
ts- timestamp in ISO formatvalue- metric value (cores for CPU, GB for memory/disk/network)
Composability
- Get IDs: Use railway-status skill or
railway status --json - Check service health: Use railway-service skill for deployment status
- View logs: Use railway-deployment skill if metrics show issues
- Scale service: Use railway-environment skill to adjust resources
Error Handling
Empty/Null Metrics
Services without active deployments return empty metrics arrays. When processing with jq, handle nulls:
# Safe iteration - skip nulls
jq -r '.data.metrics[]? | select(.values != null and (.values | length) > 0) | ...'
# Check if metrics exist before processing
jq -e '.data.metrics | length > 0' response.json && echo "has metrics"
No Metrics Data
Service may be new or have no traffic. Check:
- Service has active deployment (stopped services have no metrics)
- Time range includes deployment period
Invalid Service/Environment ID
Verify IDs with railway status --json.
Permission Denied
User needs access to the project to query metrics.
GitHub 仓库
相关推荐技能
railway-database
元这个Skill用于在Railway平台快速添加官方数据库服务(Postgres、Redis、MySQL、MongoDB)。当开发者需要为应用添加数据库或连接数据库时,可以通过简单的自然语言指令触发。它使用预配置的Railway模板自动设置存储卷、网络和连接变量,简化数据库部署流程。
railway-new
元该Skill用于在Railway平台创建项目和部署服务,支持从零开始初始化项目或在现有项目中添加新服务。它能根据用户指令自动判断执行新项目创建或服务部署,并处理GitHub仓库连接等配置。特别适合需要快速在Railway部署应用或管理多服务项目的开发者。
railway-deployment
元这个Claude Skill用于管理Railway部署的完整生命周期,包括查看日志、重新部署、重启或移除部署。它特别适合部署可见性(列表、状态、历史记录)和故障排除(日志、错误、故障排查)。注意:此技能仅用于部署管理,要完全删除服务需使用railway-environment技能。
railway-status
元该Skill用于检查当前目录下Railway项目的实时状态,包括部署状态、运行情况和可用性。当开发者询问"railway status"、"is it running"或"what's deployed"等部署状态问题时自动触发。它通过railway-cli获取项目信息,但配置查询需使用专门的railway-environment skill处理。
