Fetching Top Metrics

To get the top 10 queries for a host or set of hosts we can mimic the calls being made in the Profiler page of Database Performance Monitor. You will need an API token, represented in each example as <API_TOKEN>.

The Profiler works by first fetching the top metrics for a given metric (time, count, etc.), and then looking up the query associated with each metric. This request will fetch the top 10 queries ranked by total time:

curl 'https://app.vividcortex.com/api/v2/metrics/series?from=1467209359&host=203&limit=10&metrics=host.queries.*.*.time_us&rank=1&samplesize=2085&separateHosts=0&until=1467814159'
-H 'Authorization: Bearer <API_TOKEN>' \
-H 'Accept: application/json’

The response looks something like this:

"data": [
      "elements": [
          "metric": "host.queries.q.64fbec4e9e5f30d6.time_us",
          "series": [
            1.134587336799346e+06, ...

The parameters in the request above specify the following:

  • from / until: The exact unix timestamps to fetch metrics for. Only exact time-ranges are accepted, unlike other endpoints which accept relative times.
  • host: A list of host IDs to fetch. This can be one or many hosts.
  • limit: How many metrics to fetch. The absolute limit is 200.
  • metrics: This is specifying a list of explicit metrics, or a pattern for fetching metrics. In the example above we fetch host.queries.*.*.time_us, which is the pattern for getting total time for each query.
  • rank: Set to 1 to get the top-N (up to the limit, above) ranked metrics.
  • samplesize: This tells the API to represent N points as a single point in the returned series for each metric.