监控路线
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助基于路由的监控,您可以从 Cloud Logging 中汇总后端日志,并整理这些日志,以便显示 Web 应用中不同路由的不同指标。
基于路线的监控的使用场景
基于路由的指标可让您深入了解 Web 应用路由的性能和行为。通过监控和分析这些指标,您可以优化路线、排查问题并提升应用的用户体验。
优势
- 性能问题排查:找出延迟时间(第 75 百分位)或错误率较高的特定路线,以便有针对性地开展优化工作。
- 流量分析:了解不同路线的请求量,有助于确定资源优先级并识别热门功能。
- 错误跟踪:监控各个路由上的 4xx 和 5xx 错误,以便快速检测和解决影响应用特定部分的问题。
用例
- API 性能优化:API 提供方可以使用基于路由的指标来识别速度缓慢或容易出错的端点,并优化其性能。这有助于缩短响应时间、提高可靠性并改善开发者体验。
- Web 应用性能监控:通过监控基于路由的指标,开发者可以找出性能瓶颈并优化特定网页或功能。这有助于提供更快速、更流畅的用户体验。
- 电子商务转化优化:电子商务企业可以使用基于路线的指标来跟踪不同商品页面和结账流程的成效。这些数据可用于优化用户体验并提高转化率。
启用基于路线的监控
如需选择启用基于路线的监控,请执行以下操作:
- 在 Firebase 控制台的 App Hosting 页面中选择您的后端。
- 在路线中,选择注册路线以启用基于路线的监控。
启用此功能后,您可以在应用中添加您感兴趣的监控路线。请务必了解使用此功能可能带来的费用影响。
注册路由
对于您的应用发送的每个网络请求,App Hosting 会将该请求映射到与其网址最匹配的特定路由格式。格式匹配只会影响未来的请求;以前的请求中的匹配项和数据不会受到新自定义网址格式输入的影响。
以自定义网址格式输入路线。先创建主机名,然后再创建路径段。主机名必须包含有效网域,并且可以选择包含子网域。使用以下路径段语法可创建可与网址匹配的格式。
- 纯文本 - 与精确的路径匹配
- * - 与第一个子网域片段或单个路径片段中的任何字符串匹配
- ** - 与任意路径后缀匹配
下表介绍了一些可能的自定义网址格式匹配。
如需匹配… |
创建自定义网址格式,例如… |
与此网址格式匹配的示例 |
精确网址 |
/foo/baz |
example.com/foo/baz |
任意单个路径段 (* ) |
/*/baz |
example.com/foo/baz
example.com/bar/baz
|
/*/*/baz |
example.com/foo/bar/baz
example.com/bah/qux/baz
|
/foo/* |
example.com/foo/baz
example.com/foo/bar
注意:此格式与 example.com/foo 不匹配。
|
任意路径后缀 (** ) |
/foo/** |
example.com/foo
example.com/foo/baz
example.com/foo/baz/more/segments
|
请注意基于路由的监控的以下边缘行为:
- 对于自定义网址格式,Firebase 不支持
*.[file extension]
等语法,例如 *.png
或 *.css
。
- 网址格式的网域可以还包含 * 作为其第一个片段:
*.example.com/*/fruits/**
。
- 系统会统计所有与网址格式匹配的请求。
example.com/foo/baz
将同时计入 example.com/*
和 example.com/foo/*
您最多可以注册 20 个要监控的路线。
监控指标
对于每条已注册的路线,系统会提供以下指标:
- 请求数量
- 错误数(5xx 和 4xx)
- p75 延迟时间
所有指标均针对概览标签页顶部所选的时间段显示。
价格
基于路由的监控指标需要使用 Cloud Logging 的基于日志的指标功能。大多数项目的费用不会增加,但请务必注意,选择启用基于路线的监控功能可能会导致 Cloud Logging 使用量增加。
如需详细了解 Cloud Logging 价格并估算费用,请参阅Cloud Logging 价格。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-08。
[null,null,["最后更新时间 (UTC):2025-08-08。"],[],[],null,["\u003cbr /\u003e\n\nRoute-based Monitoring lets you aggregate your backend's logs from Cloud Logging\nand organize them to show you different metrics for different routes in your web\napp.\n\nUse cases for route-based monitoring\n\nRoute-based metrics provide insights into the performance and behavior of your\nweb app routes. By monitoring and analyzing these metrics, you can optimize\nroutes, troubleshoot issues, and enhance your app's user experience.\n\nBenefits\n\n- **Performance Troubleshooting:** Identify specific routes experiencing high latency (p75) or error rates, enabling targeted optimization efforts.\n- **Traffic Analysis:** Understand the volume of requests for different routes, helping to prioritize resources and identify popular features.\n- **Error Tracking:** Monitor 4xx and 5xx errors on individual routes, allowing for rapid detection and resolution of issues affecting specific parts of the application.\n\nUse Cases\n\n- **API Performance Optimization:** API providers can use route-based metrics to identify slow or error-prone endpoints and optimize their performance. This leads to faster response times, improved reliability, and a better developer experience.\n- **Web App Performance Monitoring:** By monitoring route-based metrics, developers can pinpoint performance bottlenecks and optimize specific pages or features. This results in a faster and smoother user experience.\n- **Ecommerce Conversion Optimization:** Ecommerce businesses can use route-based metrics to track the performance of different product pages and checkout flows. This data can be used to optimize the user experience and increase conversion rates.\n\nEnable route-based monitoring\n\nTo opt in and enable route-based monitoring:\n\n1. Select your backend in the [App Hosting page](https://console.firebase.google.com/project/_/apphosting) of the Firebase console.\n2. In **Routes** , select **Register routes** to enable route-based monitoring.\n\nOnce you have opted in, you can add routes in your app that you are interested\nin monitoring. Make sure you are aware of the potential [cost impact](#pricing)\nof using this feature.\n\nRegister routes\n\nFor each network request sent from your app, App Hosting maps the request to\nthe most specific route pattern that matches the request's URL. The pattern\nmatching only affects future requests; matches and data from previous requests\nwon't be affected by a new custom URL pattern input.\n\nInput routes as custom URL patterns. Start with a hostname, followed by path\nsegments. The hostname must include a valid domain, and can optionally include\nthe subdomain. Use the following path segment syntax to create a pattern that\ncan match URLs.\n\n- plain text --- matches an exact path\n- \\* --- matches the first subdomain segment, or any string in a single path segment\n- \\*\\* --- matches an arbitrary path suffix\n\nThe following table describes some potential custom URL pattern matching.\n\n| **To match...** | **Create a custom URL pattern like...** | **Example matches to this URL pattern** |\n|---------------------------------|-----------------------------------------|----------------------------------------------------------------------------------------------|\n| An exact URL | `/foo/baz` | `example.com/foo/baz` |\n| Any single path segment (`*`) | `/*/baz` | `example.com/foo/baz` `example.com/bar/baz` |\n| Any single path segment (`*`) | `/*/*/baz` | `example.com/foo/bar/baz` `example.com/bah/qux/baz` |\n| Any single path segment (`*`) | `/foo/*` | `example.com/foo/baz` `example.com/foo/bar` Note:This pattern won't match `example.com/foo`. |\n| An arbitrary path suffix (`**`) | `/foo/**` | `example.com/foo` `example.com/foo/baz` `example.com/foo/baz/more/segments` |\n| An arbitrary path suffix (`**`) |\n\nNote this edge behavior of route-based monitoring:\n\n- For custom URL patterns, Firebase **does not** support syntax such as `*.[file extension]`, such as `*.png` or `*.css`.\n- The domain for a URL pattern **can** also contain \\* as its first segment: `*.example.com/*/fruits/**`.\n- Requests are counted for all URL pattern matches. `example.com/foo/baz` will count for both `example.com/*` and `example.com/foo/*`\n\nYou can register up to 20 routes to monitor.\n\nMonitor metrics\n\nThe following metrics are available for each registered route:\n\n- Number of requests\n- Errors (5xx \\& 4xx)\n- p75 latency\n\nAll metrics are displayed for the time period selected at the top of the\noverview tab.\n\nPricing\n\nThe [log-based metrics](https://cloud.google.com/stackdriver/pricing#log-based-metrics)\nfeature of\n[Cloud Logging](https://cloud.google.com/logging) is required for route-based\nmonitoring metrics. Most projects won't see an increase in cost, but it's important to\nnote that opting into our route based monitoring may result in\nincreased Cloud Logging usage.\n\nFor more information on Cloud Logging pricing and to estimate your costs, see\n[Cloud Logging pricing](https://cloud.google.com/logging)."]]