如何在Datadog中创建单图表展示API所有端点的TPS?
Got it, let's walk through how to build that combined TPS chart for all 10 of your API endpoints in Datadog. I’ve been through similar setups with IIS logs, so here’s a step-by-step breakdown that should get you sorted:
1. Fix Log Parsing to Extract Endpoints First
The key issue here is that Datadog needs to recognize each unique endpoint from your IIS logs. You’ll need to update your Datadog Agent’s IIS configuration to extract the endpoint as a custom attribute:
- Locate your Agent’s IIS config file: On Windows, this is usually at
C:\ProgramData\Datadog\conf.d\iis.d\conf.yaml - Open it and add a processing rule to extract the
endpointfrom the IIScs-uri-stemfield (this is the request path in IIS logs). Adjust the regex to match your API’s endpoint structure:logs: - type: file path: C:\inetpub\logs\LogFiles\W3SVC1\u_ex*.log # Update to your actual log path service: "your-api-service-name" # Give your API a meaningful service name source: iis sourcecategory: http_web_access processing_rules: - type: extract source: cs-uri-stem name: endpoint regex: "^/api/(?P<endpoint>[^/?]+)" # Example: extracts "contract1" from "/api/contract1?param=1" - Save the file and restart the Datadog Agent: Run
datadog-agent restartin an elevated command prompt.
2. Verify the Endpoint Attribute is Working
Head over to Datadog’s Log Explorer and search for logs from your API service. Check if each log entry has an endpoint tag/attribute with the correct value (like contract1, contract2, etc.). If not, tweak the regex in your config to match your actual endpoint paths.
3. Build the TPS Chart
Now that endpoints are being parsed correctly, create the chart:
- Go to Datadog’s Dashboards > New Dashboard > Timeboard
- Add a new Line Chart (or Area Chart for better visibility of overlapping TPS)
- In the Metrics tab, use this query to calculate TPS per endpoint (adjust the service name to match yours):
sum:logs.count{service:your-api-service-name,source:iis}.as_rate() by {endpoint}sum:logs.countcounts all incoming requests.as_rate()converts the count to requests per second (TPS)by {endpoint}splits the data by each unique endpoint
- Adjust the time range (e.g., Last 1 Hour) and check if all 10 endpoints appear as separate lines in the chart.
- Optional: Use the "Alias" feature to rename long endpoint names to something cleaner (e.g., alias
/api/contract1to "Contract 1").
Quick Note on Your Code Snippet
That import time from datetime import datetime snippet you mentioned isn’t necessary here—we can achieve everything using Datadog’s built-in log parsing and metrics queries, no custom scripts required.
If you run into issues with missing endpoints, double-check that:
- Your IIS logs are being ingested correctly (check the Agent status with
datadog-agent status) - The regex in your processing rule accurately captures your endpoint paths
- The service name in your query matches what you set in the Agent config
内容的提问来源于stack exchange,提问作者user2768132

