Ok great I have it working well enough now so that I can revisit the queries and see some specifics.
For anyone wondering how to do the same thing, this is a function I call from a gateway message handler:
"""
These scripts can ONLY be run on the gateway context.
"""
from com.inductiveautomation.ignition.gateway import IgnitionGateway
import system.util
logger = system.util.getLogger("gateway.query")
LIMIT = 100
def getLongQueries():
"""
Note:
query.duration is a long, measuring milliseconds
query.startTime is the unix-time
"""
context = IgnitionGateway.get()
logger.info("Got context")
name = 'myDatasource'
queries = context.getDatasourceManager().getDatasource(name).getMetrics().getExpensiveQueries()
for query in queries:
if query.duration > LIMIT:
logger.info("Query: " + str(query.getQuery()))
logger.info("Length of query: " + str(query.duration))
logger.info("Start time: " + str(query.startTime))