Performance Metrics
The _performanceMetrics query provides detailed information about the application's performance, including resolver execution times, database query performance, and cache statistics.
Query
query {
_performanceMetrics {
resolvers {
name
count
avgTime
medianTime
minTime
maxTime
totalTime
lastExecutionTime
lastExecution
}
queries {
name
count
avgTime
medianTime
minTime
maxTime
totalTime
lastExecutionTime
lastExecution
}
cache {
hits
misses
hitRate
missRate
avgHitTime
avgMissTime
totalHitsTime
totalMissesTime
}
config {
enabled
includeInResponse
logAllMetrics
slowQueryThreshold
slowResolverThreshold
}
}
}
Response
{
"data": {
"_performanceMetrics": {
"resolvers": [
{
"name": "resolve_recent_location_history_query",
"count": 2,
"avgTime": 0.01697540283203125,
"medianTime": 0.01697540283203125,
"minTime": 0.0005447864532470703,
"maxTime": 0.03340601921081543,
"totalTime": 0.0339508056640625,
"lastExecutionTime": 0.0005447864532470703,
"lastExecution": "2025-05-04T16:51:50.674423"
}
],
"queries": [],
"cache": {
"hits": 1,
"misses": 1,
"hitRate": 0.5,
"missRate": 0.5,
"avgHitTime": 0.0002760887145996094,
"avgMissTime": 0.00013136863708496094,
"totalHitsTime": 0.0002760887145996094,
"totalMissesTime": 0.00013136863708496094
},
"config": {
"enabled": true,
"includeInResponse": true,
"logAllMetrics": true,
"slowQueryThreshold": 0.5,
"slowResolverThreshold": 1
}
}
}
}
Return Type
The query returns a PerformanceMetrics object with the following structure:
PerformanceMetrics
| Field | Type | Description |
|---|---|---|
resolvers | [ResolverMetric!] | List of resolver performance metrics |
queries | [QueryMetric!] | List of database query performance metrics |
cache | CacheMetrics | Cache performance metrics |
config | PerformanceConfig | Current performance monitoring configuration |
ResolverMetric
| Field | Type | Description |
|---|---|---|
name | String! | Name of the resolver function |
count | Int! | Number of times the resolver has been called |
avgTime | Float! | Average execution time in seconds |
medianTime | Float! | Median execution time in seconds |
minTime | Float! | Minimum execution time in seconds |
maxTime | Float! | Maximum execution time in seconds |
totalTime | Float! | Total execution time across all calls in seconds |
lastExecutionTime | Float | Execution time of the most recent call in seconds |
lastExecution | DateTime | Timestamp of the most recent call |
QueryMetric
| Field | Type | Description |
|---|---|---|
name | String! | Name of the query (derived from query type and table name) |
count | Int! | Number of times the query has been executed |
avgTime | Float! | Average execution time in seconds |
medianTime | Float! | Median execution time in seconds |
minTime | Float! | Minimum execution time in seconds |
maxTime | Float! | Maximum execution time in seconds |
totalTime | Float! | Total execution time across all executions in seconds |
lastExecutionTime | Float | Execution time of the most recent execution in seconds |
lastExecution | DateTime | Timestamp of the most recent execution |
CacheMetrics
| Field | Type | Description |
|---|---|---|
hits | Int! | Number of cache hits |
misses | Int! | Number of cache misses |
hitRate | Float! | Percentage of cache hits (0.0 to 1.0) |
missRate | Float! | Percentage of cache misses (0.0 to 1.0) |
avgHitTime | Float! | Average time to retrieve an item from cache in seconds |
avgMissTime | Float! | Average time to determine a cache miss in seconds |
totalHitsTime | Float! | Total time spent on cache hits in seconds |
totalMissesTime | Float! | Total time spent on cache misses in seconds |
PerformanceConfig
| Field | Type | Description |
|---|---|---|
enabled | Boolean! | Whether performance monitoring is enabled |
includeInResponse | Boolean! | Whether to include performance data in GraphQL responses |
logAllMetrics | Boolean! | Whether to log all metrics or only slow ones |
slowQueryThreshold | Float! | Threshold in seconds for identifying slow queries |
slowResolverThreshold | Float! | Threshold in seconds for identifying slow resolvers |
Usage Notes
- This query is primarily intended for administrators and developers
- The metrics are stored in memory with a configurable retention period (default: 1 hour)
- Metrics are reset when the application restarts
- For more information on interpreting and using these metrics, see the Performance Monitoring Guide
Example: Filtering for Specific Resolvers
You can use GraphQL's field selection to focus on specific parts of the performance metrics:
query {
_performanceMetrics {
resolvers {
name
avgTime
maxTime
count
}
config {
slowResolverThreshold
}
}
}
This returns a more focused set of metrics:
{
"data": {
"_performanceMetrics": {
"resolvers": [
{
"name": "resolve_recent_location_history_query",
"avgTime": 0.01697540283203125,
"maxTime": 0.03340601921081543,
"count": 2
}
],
"config": {
"slowResolverThreshold": 1
}
}
}
}
Security Considerations
- The
_performanceMetricsquery should be restricted to administrative users - Performance data may expose information about your application's internal structure
- Consider disabling
includeInResponsein production environments to prevent leaking performance data to regular users