<p>I need to get the usage metrics (CPU and RAM) for my Kubernetes pods, but since other components of my app use this data, I need to query for it through Node.js rather than use the Metrics explorer dropdown on the GCP console to just see the data visualized in a chart. I have tried the API at <a href="https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/query" rel="nofollow noreferrer">https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/query</a> which seems most like what I'm looking for. However, after testing on my project, I got an empty response, even though the same query in the Metrics Explorer displayed data on the charts. If anyone has tips on how to use this API properly, I'd appreciate it.</p>

AC34
<p>I have reproduced your use-case and successfully executed the query and got the Cumulative amount of consumed CPU time on all cores in nanoseconds with <strong>200 OK response</strong>.</p>
<ol>
<li><p>After creating the GKE Cluster, navigate to metrics explorer and select the metric, <code>metric.type=&quot;kubernetes.io/container/cpu/core_usage_time&quot;</code> and you can see the data in the chart for the cluster. Now click the &quot;MQL&quot; button to get the same query in MQL syntax.</p>
</li>
<li><p>Now to get the same data by calling the <code>projects.timeSeries.query</code>, try in the <strong><a href="https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/query?apix_params=%7B%22name%22%3A%22projects%2Fmy-project-979197%22%2C%22resource%22%3A%7B%22query%22%3A%22fetch%20k8s_container%3A%3Akubernetes.io%2Fcontainer%2Fcpu%2Fcore_usage_time%7C%20within%201m%22%7D%7D#path-parameters" rel="nofollow noreferrer">“Try this API”</a></strong> box in API Explorer  by entering the project's ID using the format <code>projects/[PROJECT_ID]</code> in the name parameter. Make sure to replace <strong>[PROJECT_ID]</strong> with your project's ID.</p>
</li>
<li><p>In the request body add the query as<br />
<code>&quot;query&quot;: &quot;fetch k8s_container::kubernetes.io/container/cpu/core_usage_time| within 5m&quot;</code></p>
</li>
</ol>
<p>Syntax for Request Body:</p>
<p>{</p>
<pre><code> &quot;query&quot;: &quot;fetch k8s_container::kubernetes.io/container/cpu/core_usage_time| within 5m&quot;
  
</code></pre>
<p>}</p>
<p>Now, click on the <strong>Execute</strong> button to get the Cumulative amount of consumed CPU time on all cores  with 200 OK response.</p>
<p>Refer to the <a href="https://cloud.google.com/monitoring/mql/qn-from-api?authuser=1#ql-timeseries-query" rel="nofollow noreferrer">link</a> for more information on retrieving data with timeseries.query.</p>
