Cache Metrics
Cache hits can be determined via the log_attributes['response.headers.cf_cache_status'] key in the logs. Any value that corresponds to either HIT, STALE, REVALIDATED, or UPDATING is categorized as a cache hit.
The following example query will show the top cache misses from the edge_logs:
1select2 log_attributes['request.path'] as path,3 log_attributes['request.search'] as search,4 count() as count5from logs6where source = 'edge_logs'7 and startsWith(log_attributes['request.path'], '/storage/v1/object')8 and log_attributes['request.method'] = 'GET'9 and log_attributes['response.headers.cf_cache_status'] in ('MISS', 'NONE/UNKNOWN', 'EXPIRED', 'BYPASS', 'DYNAMIC')10group by path, search11order by count desc12limit 50;Try out this query in the SQL Editor.
Your cache hit ratio over time can then be determined using the following query:
1select2 toStartOfHour(timestamp) as timestamp,3 countIf(log_attributes['response.headers.cf_cache_status'] in ('HIT', 'STALE', 'REVALIDATED', 'UPDATING')) / count() as ratio4from logs5where source = 'edge_logs'6 and startsWith(log_attributes['request.path'], '/storage/v1/object')7 and log_attributes['request.method'] = 'GET'8group by timestamp9order by timestamp desc10limit 100;Try out this query in the SQL Editor.