Skip to Content

SQL Queries

APXY stores all traffic in a SQLite database. You can run arbitrary read-only SQL queries for advanced analysis that goes beyond what the search and filter tools provide.

Web UI

SQL queries are available through the CLI. The Web UI does not have a SQL console.

CLI

apxy sql query "SELECT host, COUNT(*) as cnt FROM traffic_logs GROUP BY host ORDER BY cnt DESC LIMIT 10"

Available Tables

traffic_logs

ColumnTypeDescription
idTEXTRecord ID
timestampTEXTISO 8601 timestamp
methodTEXTHTTP method
urlTEXTFull URL
hostTEXTHost header
pathTEXTURL path
status_codeINTEGERResponse status
duration_msINTEGERResponse time in ms
tlsINTEGER1 if HTTPS
mockedINTEGER1 if mocked
request_headersTEXTJSON object
response_headersTEXTJSON object
request_bodyBLOBRaw request body
response_bodyBLOBRaw response body
request_content_typeTEXTRequest Content-Type
response_content_typeTEXTResponse Content-Type

mock_rules

ColumnTypeDescription
idTEXTRule ID
nameTEXTRule name
priorityINTEGERPriority (lower = higher)
activeINTEGER1 if active
url_patternTEXTURL match pattern
match_typeTEXTexact, wildcard, regex
methodTEXTHTTP method filter
response_statusINTEGERMock response status
response_headersTEXTJSON object
response_bodyTEXTMock response body
delay_msINTEGERResponse delay

Example Queries

Top hosts by request count

SELECT host, COUNT(*) as cnt FROM traffic_logs GROUP BY host ORDER BY cnt DESC LIMIT 10

Find slow requests

SELECT method, url, duration_ms FROM traffic_logs WHERE duration_ms > 2000 ORDER BY duration_ms DESC LIMIT 10

Error rate by host

SELECT host, COUNT(*) as total, SUM(CASE WHEN status_code >= 400 THEN 1 ELSE 0 END) as errors, ROUND(100.0 * SUM(CASE WHEN status_code >= 400 THEN 1 ELSE 0 END) / COUNT(*), 1) as error_pct FROM traffic_logs GROUP BY host ORDER BY errors DESC

5xx errors in the last hour

SELECT host, COUNT(*) as errors FROM traffic_logs WHERE status_code >= 500 AND timestamp > datetime('now', '-1 hour') GROUP BY host ORDER BY errors DESC

Mocked vs real traffic

SELECT CASE WHEN mocked = 1 THEN 'mocked' ELSE 'real' END as type, COUNT(*) as count FROM traffic_logs GROUP BY mocked

Average response time by endpoint

SELECT method, path, COUNT(*) as requests, ROUND(AVG(duration_ms), 0) as avg_ms, MAX(duration_ms) as max_ms FROM traffic_logs GROUP BY method, path ORDER BY avg_ms DESC LIMIT 10
Last updated on