Queries Module
const queries = require('@arangodb/aql/queries')
The query module provides the infrastructure for working with currently running AQL queries via arangosh.
Properties
queries.properties()
Returns the servers current query tracking configuration; we change the slow query threshold to get better results:
arangosh> var queries = require("@arangodb/aql/queries");
arangosh> queries.properties();
{
"code" : 200,
"enabled" : true,
"trackSlowQueries" : true,
"maxSlowQueries" : 64,
"slowQueryThreshold" : 10,
"maxQueryStringLength" : 4096
}
arangosh> queries.properties({slowQueryThreshold: 1});
{
"code" : 200,
"enabled" : true,
"trackSlowQueries" : true,
"maxSlowQueries" : 64,
"slowQueryThreshold" : 1,
"maxQueryStringLength" : 4096
}
arangosh> var queries = require("@arangodb/aql/queries");
arangosh> queries.properties();
arangosh> queries.properties({slowQueryThreshold: 1});
Currently running queries
We create a task that spawns queries, so we have nice output. Since this task
uses resources, you may want to increase period
(and not forget to remove it... afterwards):
arangosh> var theQuery = 'FOR sleepLoooong IN 1..5 LET sleepLoooonger = SLEEP(1000) RETURN sleepLoooong';
arangosh> var tasks = require("@arangodb/tasks");
arangosh> tasks.register({
........> id: "mytask-1",
........> name: "this is a sample task to spawn a slow aql query",
........> command: "require('@arangodb').db._query('" + theQuery + "');"
........> });
{
"id" : "mytask-1",
"name" : "this is a sample task to spawn a slow aql query",
"created" : 1500501019.795586,
"type" : "timed",
"offset" : 0,
"command" : "(function (params) { require('@arangodb').db._query('FOR sleepLoooong IN 1..5 LET sleepLoooonger = SLEEP(1000) RETURN sleepLoooong'); } )(params);",
"database" : "_system",
"code" : 200
}
arangosh> queries.current();
[
{
"id" : "250",
"query" : "FOR sleepLoooong IN 1..5 LET sleepLoooonger = SLEEP(1000) RETURN sleepLoooong",
"bindVars" : {
},
"started" : "2017-07-19T21:50:19Z",
"runTime" : 1.053999900817871,
"state" : "executing"
}
]
arangosh> var theQuery = 'FOR sleepLoooong IN 1..5 LET sleepLoooonger = SLEEP(1000) RETURN sleepLoooong';
arangosh> var tasks = require("@arangodb/tasks");
arangosh> tasks.register({
........> id: "mytask-1",
........> name: "this is a sample task to spawn a slow aql query",
........> command: "require('@arangodb').db._query('" + theQuery + "');"
........> });
arangosh> queries.current();
The function returns the currently running AQL queries as an array.
Slow queries
The function returns the last AQL queries that exceeded the slow query threshold as an array:
arangosh> queries.slow(); [ ]
Clear slow queries
Clear the list of slow AQL queries:
arangosh> queries.clearSlow();
{
"code" : 200
}
arangosh> queries.slow();
[ ]
Kill
Kill a running AQL query:
arangosh> var runningQueries = queries.current().filter(function(query) {
........> return query.query === theQuery;
........> });
arangosh> queries.kill(runningQueries[0].id);
{
"code" : 200
}