Skip to content

Commit

Permalink
Datadogpy metric query support
Browse files Browse the repository at this point in the history
  • Loading branch information
yannmh committed May 20, 2015
1 parent ef90fe3 commit cff788a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 48 deletions.
3 changes: 1 addition & 2 deletions code_snippets/api-query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/python
from datadog import initialize, api
from datadog.api.base import HTTPClient
import time

options = {
Expand All @@ -15,5 +14,5 @@
# query for idle CPU for all machines tagged with speed:4000
query = 'system.cpu.idle{*}by{host}'

results = HTTPClient.request('GET', '/query', **{'from': start, 'to': end, 'query': query})
results = api.Metric.query(start=start - 3600, end=end, query=query)
print results
90 changes: 44 additions & 46 deletions content/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ <h1><%= @item[:title] %> </h1>
<a class="btn" href="#hosts">Hosts</a>
<a class="btn" href="#tags">Tags</a>
<a class="btn" href="#search">Search</a>
<a class="btn" href="#query">Query</a>
<a class="btn" href="#comments">Comments</a>
<a class="btn" href="#users">Users</a>
<a class="btn" href="#graphs">Graphs</a>
Expand Down Expand Up @@ -147,8 +146,17 @@ <h3 id="metrics">Metrics</h3>
<div class="row-fluid">
<%= left_side_div %>
<p>
The metrics end-point allows you to post metrics data so it can
be graphed on Datadog's dashboards.
The metrics end-point allows you to:
</p>
<li>
<ul>Post metrics data so it can be graphed on Datadog's dashboards</ul>
<ul>Query metrics from any time period</ul>
</li>
<p>
As occurs within the Datadog UI, a graph can only contain a set number of points and as the timeframe over which a metric is viewed increases, aggregation between points will occur to stay below that set number.
</p>
<p>
Thus, if you are querying for larger timeframes of data, the points returned will be more aggregated. The max granularity within Datadog is one point per second, so if you had submitted points at that interval and requested a very small interval from the query API (in this case, probably less than 100 seconds), you could end up getting all of those points back. Otherwise, our algorithm tries to return about 150 points per any given time window, so you'll see coarser and coarser granularity as the amount of time requested increases. We do this time aggregation via averages.
</p>
</div>
</div>
Expand All @@ -171,7 +179,7 @@ <h5>Arguments</h5>
<code>[[POSIX_timestamp, numeric_value], ...]</code>
</div>
Note that the timestamp must be current.
</div>
</div>but fin
</li>
<%= argument('host', 'The name of the host that produced the metric.', :default => 'None' ) %>
<%= argument('tags', 'A list of tags associated with the metric.', :default => 'None' ) %>
Expand All @@ -190,6 +198,38 @@ <h5>Example Request</h5>
<% end %>
</div>
</div>
<h4 id="metrics-query">Query time series points</h4>
<div class="row-fluid">
<%= left_side_div %>
<p>
This end point allows you to query for metrics from any time period.
</p>

<h5>Arguments</h5>
<ul class="arguments">
<%= argument("from", "seconds since the unix epoch", :lang => 'console') %>
<%= argument("to", "seconds since the unix epoch", :lang => 'console') %>
<%= argument("start", "seconds since the unix epoch", :lang => 'python') %>
<%= argument("end", "seconds since the unix epoch", :lang => 'python') %>
<%= argument("query", "The query string") %>
</ul>
<h5>Query Language</h5>
<p>
Any query used for a graph can be used here. See <a href="/graphing/">here</a> for more details. The time between from and to should be less than 24 hours. If it is longer, you will receive points with less granularity.
</p>

</div>
<%= right_side_div %>
<h5>Signature</h5>
<code>GET https://app.datadoghq.com/api/v1/query</code>
<h5>Example Request</h5>
<%= snippet_code_block "api-query.py" %>
<%= snippet_code_block "api-query.sh" %>
<h5>Example Response</h5>
<%= snippet_result_code_block "api-query.py" %>
<%= snippet_result_code_block "api-query.sh" %>
</div>
</div>

<!--
=====================================================================
Expand Down Expand Up @@ -1449,48 +1489,6 @@ <h5>Example Response</h5>
</div>
</div>


<!--
=====================================================================
Query
====================================================================
-->

<h3 id="query">Query</h3>
<div class="row-fluid">
<%= left_side_div %>
<p>
This end point allows you to query for metrics from any time period.
</p>
<p>
As occurs within the Datadog UI, a graph can only contain a set number of points and as the timeframe over which a metric is viewed increases, aggregation between points will occur to stay below that set number.
</p>
<p>
Thus, if you are querying for larger timeframes of data, the points returned will be more aggregated. The max granularity within Datadog is one point per second, so if you had submitted points at that interval and requested a very small interval from the query API (in this case, probably less than 100 seconds), you could end up getting all of those points back. Otherwise, our algorithm tries to return about 150 points per any given time window, so you'll see coarser and coarser granularity as the amount of time requested increases. We do this time aggregation via averages.
</p>
<h5>Arguments</h5>
<ul class="arguments">
<%= argument("from", "seconds since the unix epoch") %>
<%= argument("to", "seconds since the unix epoch") %>
<%= argument("query", "The query string") %>
</ul>
<h5>Query Language</h5>
<p>
Any query used for a graph can be used here. See <a href="/graphing/">here</a> for more details. The time between from and to should be less than 24 hours. If it is longer, you will receive points with less granularity.
</p>

</div>
<%= right_side_div %>
<h5>Signature</h5>
<code>GET https://app.datadoghq.com/api/v1/query</code>
<h5>Example Request</h5>
<%= snippet_code_block "api-query.py" %>
<%= snippet_code_block "api-query.sh" %>
<h5>Example Response</h5>
<%= snippet_result_code_block "api-query.py" %>
<%= snippet_result_code_block "api-query.sh" %>
</div>
</div>
<!--
=====================================================================
Comments
Expand Down

0 comments on commit cff788a

Please sign in to comment.