Builds a serializable map from the running and cached query maps to be returned to a caller. @return A map for serialization
()
| 396 | * @return A map for serialization |
| 397 | */ |
| 398 | public static Map<String, Object> getRunningAndCompleteStats() { |
| 399 | Map<String, Object> root = new TreeMap<String, Object>(); |
| 400 | |
| 401 | if (running_queries.isEmpty()) { |
| 402 | root.put("running", Collections.emptyList()); |
| 403 | } else { |
| 404 | final List<Object> running = new ArrayList<Object>(running_queries.size()); |
| 405 | root.put("running", running); |
| 406 | |
| 407 | // don't need to lock the map beyond what the iterator will do implicitly |
| 408 | for (final QueryStats stats : running_queries.values()) { |
| 409 | final Map<String, Object> obj = new HashMap<String, Object>(10); |
| 410 | obj.put("query", stats.query); |
| 411 | obj.put("remote", stats.remote_address); |
| 412 | obj.put("user", stats.user); |
| 413 | obj.put("headers", stats.headers); |
| 414 | obj.put("queryStart", stats.query_start_ms); |
| 415 | obj.put("elapsed", DateTime.msFromNanoDiff(DateTime.nanoTime(), |
| 416 | stats.query_start_ns)); |
| 417 | running.add(obj); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | final Map<Integer, QueryStats> completed = completed_queries.asMap(); |
| 422 | if (completed.isEmpty()) { |
| 423 | root.put("completed", Collections.emptyList()); |
| 424 | } else { |
| 425 | root.put("completed", completed.values()); |
| 426 | } |
| 427 | |
| 428 | return root; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * Fetches data about the running queries and status of queries in the cache |