Skip to main content

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

FieldTypeDescription
resolvers[ResolverMetric!]List of resolver performance metrics
queries[QueryMetric!]List of database query performance metrics
cacheCacheMetricsCache performance metrics
configPerformanceConfigCurrent performance monitoring configuration

ResolverMetric

FieldTypeDescription
nameString!Name of the resolver function
countInt!Number of times the resolver has been called
avgTimeFloat!Average execution time in seconds
medianTimeFloat!Median execution time in seconds
minTimeFloat!Minimum execution time in seconds
maxTimeFloat!Maximum execution time in seconds
totalTimeFloat!Total execution time across all calls in seconds
lastExecutionTimeFloatExecution time of the most recent call in seconds
lastExecutionDateTimeTimestamp of the most recent call

QueryMetric

FieldTypeDescription
nameString!Name of the query (derived from query type and table name)
countInt!Number of times the query has been executed
avgTimeFloat!Average execution time in seconds
medianTimeFloat!Median execution time in seconds
minTimeFloat!Minimum execution time in seconds
maxTimeFloat!Maximum execution time in seconds
totalTimeFloat!Total execution time across all executions in seconds
lastExecutionTimeFloatExecution time of the most recent execution in seconds
lastExecutionDateTimeTimestamp of the most recent execution

CacheMetrics

FieldTypeDescription
hitsInt!Number of cache hits
missesInt!Number of cache misses
hitRateFloat!Percentage of cache hits (0.0 to 1.0)
missRateFloat!Percentage of cache misses (0.0 to 1.0)
avgHitTimeFloat!Average time to retrieve an item from cache in seconds
avgMissTimeFloat!Average time to determine a cache miss in seconds
totalHitsTimeFloat!Total time spent on cache hits in seconds
totalMissesTimeFloat!Total time spent on cache misses in seconds

PerformanceConfig

FieldTypeDescription
enabledBoolean!Whether performance monitoring is enabled
includeInResponseBoolean!Whether to include performance data in GraphQL responses
logAllMetricsBoolean!Whether to log all metrics or only slow ones
slowQueryThresholdFloat!Threshold in seconds for identifying slow queries
slowResolverThresholdFloat!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 _performanceMetrics query should be restricted to administrative users
  • Performance data may expose information about your application's internal structure
  • Consider disabling includeInResponse in production environments to prevent leaking performance data to regular users