<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic api for extract state of monitoring process in Dynatrace API</title>
    <link>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295471#M3939</link>
    <description>&lt;P&gt;&lt;BR /&gt;hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in the community i have downloaded this runbook very helpful,&lt;BR /&gt;but i need to exract only the process that have monitoring state different from "ok".&lt;/P&gt;
&lt;P&gt;How can change the code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*&lt;BR /&gt;* This function will run in the DYNATRACE JavaScript runtime.&lt;BR /&gt;* For information visit &lt;A href="https://dt-url.net/functions-help" target="_blank" rel="noopener"&gt;https://dt-url.net/functions-help&lt;/A&gt;&lt;BR /&gt;*/&lt;BR /&gt;import { monitoredEntitiesMonitoringStateClient } from "@dynatrace-sdk/client-classic-environment-v2";&lt;BR /&gt;import { queryExecutionClient } from "@dynatrace-sdk/client-query";&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;// **** Dynatrace API ****&lt;BR /&gt;async function fetchAllMonitoringStates(pgID) {&lt;BR /&gt;const pgID_string = `${pgID.map(id =&amp;gt; `"${id}"`).join(",")}`;&lt;BR /&gt;let nextPageKey = null;&lt;BR /&gt;const monitoringStates = [];&lt;BR /&gt;do {&lt;BR /&gt;const params = nextPageKey&lt;BR /&gt;? { nextPageKey }&lt;BR /&gt;: { entitySelector: `entityId(${pgID_string})`};&lt;BR /&gt;const result = await monitoredEntitiesMonitoringStateClient.getStates(params);&lt;BR /&gt;monitoringStates.push(...result.monitoringStates);&lt;BR /&gt;nextPageKey = result.nextPageKey;&lt;BR /&gt;} while (nextPageKey);&lt;BR /&gt;return monitoringStates&lt;BR /&gt;}&lt;BR /&gt;export default async function () {&lt;BR /&gt;const now = new Date();&lt;BR /&gt;const twentyMinutesAgo = new Date(now.getTime() - 20 * 60 * 1000);&lt;BR /&gt;const formatDate = (date) =&amp;gt; date.toISOString();&lt;BR /&gt;const $dt_timeframe_from = formatDate(twentyMinutesAgo);&lt;BR /&gt;const $dt_timeframe_to = formatDate(now);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;// **** DQL Query ****&lt;BR /&gt;const dqlQuery = `&lt;BR /&gt;fetch dt.entity.process_group_instance&lt;BR /&gt;| fieldsAdd host.id=belongs_to[dt.entity.host], pg_id=instance_of[dt.entity.process_group], cgi_id=(belongs_to[dt.entity.container_group_instance])&lt;BR /&gt;| lookup [fetch dt.entity.host], sourceField:host.id, lookupField:id, fields:{host.name=entity.name, host.hostGroupName=hostGroupName}&lt;BR /&gt;| lookup [fetch dt.entity.process_group], sourceField:pg_id, lookupField:id, fields:{process.name=entity.name}&lt;BR /&gt;| lookup [fetch dt.entity.container_group_instance&lt;BR /&gt;| fieldsAdd pod_id=belongs_to[dt.entity.cloud_application_instance], namespace_id=belongs_to[dt.entity.cloud_application_namespace], node_id=belongs_to[dt.entity.host]&lt;BR /&gt;| lookup [fetch dt.entity.cloud_application_instance], sourceField:pod_id, lookupField:id, fields:{pod_name=entity.name}&lt;BR /&gt;| lookup [fetch dt.entity.cloud_application_namespace], sourceField:namespace_id, lookupField:id, fields:{namespace=entity.name}&lt;BR /&gt;| lookup [fetch dt.entity.host], sourceField:node_id, lookupField:id, fields:{node_name=entity.name}], sourceField:cgi_id, lookupField:id, fields:{pod_name, namespace, node_name}&lt;BR /&gt;| fields managementZones, host.id, host.name, host.hostGroupName, process.name, pod_name, namespace, node_name, id&lt;BR /&gt;| sort process.name desc&lt;BR /&gt;//| filter host.hostGroupName == "bet-booker"&lt;BR /&gt;`;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;// **** Execution Performance Limits ****&lt;BR /&gt;// const queryExecution = await queryExecutionClient.queryExecute({ body: { query: dqlQuery } });&lt;BR /&gt;const queryExecution = await queryExecutionClient.queryExecute({ body: {&lt;BR /&gt;query: dqlQuery,&lt;BR /&gt;scanLimitGBytes: -1&lt;BR /&gt;// fetchTimeoutSeconds:5000,&lt;BR /&gt;// defalutScanLimitsGbytes: 500000,&lt;BR /&gt;// maxResultsBytes: 100000000,&lt;BR /&gt;// maxResultsRecords: 300000000&lt;BR /&gt;} });&lt;BR /&gt;let dqlResults = [];&lt;BR /&gt;while (true) {&lt;BR /&gt;const queryPollResult = await queryExecutionClient.queryPoll({ requestToken: queryExecution.requestToken });&lt;BR /&gt;if (queryPollResult.state !== "RUNNING") {&lt;BR /&gt;dqlResults = queryPollResult.result.records;&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;let pgID = dqlResults.map(item =&amp;gt; item.id);&lt;BR /&gt;const processAllChunks = async () =&amp;gt; {&lt;BR /&gt;const allMonitoringStates = [];&lt;BR /&gt;for (let i = 0; i &amp;lt; pgID.length; i += 50) {&lt;BR /&gt;const chunk = pgID.slice(i, i + 50);&lt;BR /&gt;const chunkStates = await fetchAllMonitoringStates(chunk);&lt;BR /&gt;allMonitoringStates.push(...chunkStates);&lt;BR /&gt;}&lt;BR /&gt;return allMonitoringStates;&lt;BR /&gt;};&lt;BR /&gt;const monitoringStates = await processAllChunks();&lt;BR /&gt;const mergedResults = dqlResults.map(dqlItem =&amp;gt; {&lt;BR /&gt;const match = monitoringStates.find(apiItem =&amp;gt; apiItem.entityId === dqlItem.id);&lt;BR /&gt;return match ? { ...dqlItem, severity: match.severity, state: match.state } : dqlItem;&lt;BR /&gt;});&lt;BR /&gt;return mergedResults&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Mon, 02 Mar 2026 13:13:37 GMT</pubDate>
    <dc:creator>gasperetta</dc:creator>
    <dc:date>2026-03-02T13:13:37Z</dc:date>
    <item>
      <title>api for extract state of monitoring process</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295471#M3939</link>
      <description>&lt;P&gt;&lt;BR /&gt;hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in the community i have downloaded this runbook very helpful,&lt;BR /&gt;but i need to exract only the process that have monitoring state different from "ok".&lt;/P&gt;
&lt;P&gt;How can change the code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*&lt;BR /&gt;* This function will run in the DYNATRACE JavaScript runtime.&lt;BR /&gt;* For information visit &lt;A href="https://dt-url.net/functions-help" target="_blank" rel="noopener"&gt;https://dt-url.net/functions-help&lt;/A&gt;&lt;BR /&gt;*/&lt;BR /&gt;import { monitoredEntitiesMonitoringStateClient } from "@dynatrace-sdk/client-classic-environment-v2";&lt;BR /&gt;import { queryExecutionClient } from "@dynatrace-sdk/client-query";&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;// **** Dynatrace API ****&lt;BR /&gt;async function fetchAllMonitoringStates(pgID) {&lt;BR /&gt;const pgID_string = `${pgID.map(id =&amp;gt; `"${id}"`).join(",")}`;&lt;BR /&gt;let nextPageKey = null;&lt;BR /&gt;const monitoringStates = [];&lt;BR /&gt;do {&lt;BR /&gt;const params = nextPageKey&lt;BR /&gt;? { nextPageKey }&lt;BR /&gt;: { entitySelector: `entityId(${pgID_string})`};&lt;BR /&gt;const result = await monitoredEntitiesMonitoringStateClient.getStates(params);&lt;BR /&gt;monitoringStates.push(...result.monitoringStates);&lt;BR /&gt;nextPageKey = result.nextPageKey;&lt;BR /&gt;} while (nextPageKey);&lt;BR /&gt;return monitoringStates&lt;BR /&gt;}&lt;BR /&gt;export default async function () {&lt;BR /&gt;const now = new Date();&lt;BR /&gt;const twentyMinutesAgo = new Date(now.getTime() - 20 * 60 * 1000);&lt;BR /&gt;const formatDate = (date) =&amp;gt; date.toISOString();&lt;BR /&gt;const $dt_timeframe_from = formatDate(twentyMinutesAgo);&lt;BR /&gt;const $dt_timeframe_to = formatDate(now);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;// **** DQL Query ****&lt;BR /&gt;const dqlQuery = `&lt;BR /&gt;fetch dt.entity.process_group_instance&lt;BR /&gt;| fieldsAdd host.id=belongs_to[dt.entity.host], pg_id=instance_of[dt.entity.process_group], cgi_id=(belongs_to[dt.entity.container_group_instance])&lt;BR /&gt;| lookup [fetch dt.entity.host], sourceField:host.id, lookupField:id, fields:{host.name=entity.name, host.hostGroupName=hostGroupName}&lt;BR /&gt;| lookup [fetch dt.entity.process_group], sourceField:pg_id, lookupField:id, fields:{process.name=entity.name}&lt;BR /&gt;| lookup [fetch dt.entity.container_group_instance&lt;BR /&gt;| fieldsAdd pod_id=belongs_to[dt.entity.cloud_application_instance], namespace_id=belongs_to[dt.entity.cloud_application_namespace], node_id=belongs_to[dt.entity.host]&lt;BR /&gt;| lookup [fetch dt.entity.cloud_application_instance], sourceField:pod_id, lookupField:id, fields:{pod_name=entity.name}&lt;BR /&gt;| lookup [fetch dt.entity.cloud_application_namespace], sourceField:namespace_id, lookupField:id, fields:{namespace=entity.name}&lt;BR /&gt;| lookup [fetch dt.entity.host], sourceField:node_id, lookupField:id, fields:{node_name=entity.name}], sourceField:cgi_id, lookupField:id, fields:{pod_name, namespace, node_name}&lt;BR /&gt;| fields managementZones, host.id, host.name, host.hostGroupName, process.name, pod_name, namespace, node_name, id&lt;BR /&gt;| sort process.name desc&lt;BR /&gt;//| filter host.hostGroupName == "bet-booker"&lt;BR /&gt;`;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;// **** Execution Performance Limits ****&lt;BR /&gt;// const queryExecution = await queryExecutionClient.queryExecute({ body: { query: dqlQuery } });&lt;BR /&gt;const queryExecution = await queryExecutionClient.queryExecute({ body: {&lt;BR /&gt;query: dqlQuery,&lt;BR /&gt;scanLimitGBytes: -1&lt;BR /&gt;// fetchTimeoutSeconds:5000,&lt;BR /&gt;// defalutScanLimitsGbytes: 500000,&lt;BR /&gt;// maxResultsBytes: 100000000,&lt;BR /&gt;// maxResultsRecords: 300000000&lt;BR /&gt;} });&lt;BR /&gt;let dqlResults = [];&lt;BR /&gt;while (true) {&lt;BR /&gt;const queryPollResult = await queryExecutionClient.queryPoll({ requestToken: queryExecution.requestToken });&lt;BR /&gt;if (queryPollResult.state !== "RUNNING") {&lt;BR /&gt;dqlResults = queryPollResult.result.records;&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;let pgID = dqlResults.map(item =&amp;gt; item.id);&lt;BR /&gt;const processAllChunks = async () =&amp;gt; {&lt;BR /&gt;const allMonitoringStates = [];&lt;BR /&gt;for (let i = 0; i &amp;lt; pgID.length; i += 50) {&lt;BR /&gt;const chunk = pgID.slice(i, i + 50);&lt;BR /&gt;const chunkStates = await fetchAllMonitoringStates(chunk);&lt;BR /&gt;allMonitoringStates.push(...chunkStates);&lt;BR /&gt;}&lt;BR /&gt;return allMonitoringStates;&lt;BR /&gt;};&lt;BR /&gt;const monitoringStates = await processAllChunks();&lt;BR /&gt;const mergedResults = dqlResults.map(dqlItem =&amp;gt; {&lt;BR /&gt;const match = monitoringStates.find(apiItem =&amp;gt; apiItem.entityId === dqlItem.id);&lt;BR /&gt;return match ? { ...dqlItem, severity: match.severity, state: match.state } : dqlItem;&lt;BR /&gt;});&lt;BR /&gt;return mergedResults&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 13:13:37 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295471#M3939</guid>
      <dc:creator>gasperetta</dc:creator>
      <dc:date>2026-03-02T13:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: api for extract state of monitoring process</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295478#M3941</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;try this:&lt;BR /&gt;Total number of calls over the selected time range (sum of all minutes)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timeseries calls_per_min = sum(dt.service.request.count, rate:1m),
  by:{endpoint.name, dt.entity.service, dt.host_group.id},
  interval: 1m
| fieldsAdd service_name = entityName(dt.entity.service)
| fieldsAdd endpoint_key = concat(service_name, " :: ", endpoint.name, " :: ", dt.host_group.id)
| filter in(endpoint_key,
  "CustomerFrontendREST :: Images :: et-large",
  "JourneyService :: findJourneys :: et-large"
)
| fieldsAdd total_calls_row = arraySum(calls_per_min)
| summarize total_calls = sum(total_calls_row)&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="comm1.jpg" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/32170i35210DD56955C936/image-size/large?v=v2&amp;amp;px=999" role="button" title="comm1.jpg" alt="comm1.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current total (last datapoint),&amp;nbsp; combined calls/min at the end of the chart&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timeseries calls_per_min = sum(dt.service.request.count, rate:1m),
  by:{endpoint.name, dt.entity.service, dt.host_group.id},
  interval: 1m
| fieldsAdd service_name = entityName(dt.entity.service)
| fieldsAdd endpoint_key = concat(service_name, " :: ", endpoint.name, " :: ", dt.host_group.id)
| filter in(endpoint_key,
  "CustomerFrontendREST :: Images :: et-large",
  "JourneyService :: findJourneys :: et-large"
)
| fieldsAdd last_cpm_row = arrayLast(calls_per_min)
| summarize last_cpm_total = sum(last_cpm_row)&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="comm2.jpg" style="width: 963px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/32171iC21A105FEA8D7C44/image-size/large?v=v2&amp;amp;px=999" role="button" title="comm2.jpg" alt="comm2.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 10:57:55 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295478#M3941</guid>
      <dc:creator>t_pawlak</dc:creator>
      <dc:date>2026-03-02T10:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: api for extract state of monitoring process</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295480#M3943</link>
      <description>&lt;P&gt;Sorry, wrong thread&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 11:00:05 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295480#M3943</guid>
      <dc:creator>t_pawlak</dc:creator>
      <dc:date>2026-03-02T11:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: api for extract state of monitoring process</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295481#M3944</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I don’t have a ton of experience with this, but it seems to me that you don’t touch the DQL, only after merging the results (DQL + Monitoring State API) you apply a filter to keep only the processes where state != "OK".&lt;BR /&gt;Change&amp;nbsp;return mergedResults to&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const mergedResults = dqlResults.map(dqlItem =&amp;gt; {
  const match = monitoringStates.find(apiItem =&amp;gt; apiItem.entityId === dqlItem.id);
  return match ? { ...dqlItem, severity: match.severity, state: match.state } : dqlItem;
});

//Only proccesses !== "OK"
const onlyNotOk = mergedResults.filter(item =&amp;gt; {
  // jeśli dla jakiegoś wpisu nie ma state (API nie zwróciło), to:
  if (!item.state) return true; 
  return item.state.toUpperCase() !== "OK";
});

return onlyNotOk;&lt;/LI-CODE&gt;&lt;P&gt;If you want to drop records with no state and keep only “real” non-OK ones:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;return mergedResults.filter(item =&amp;gt; item.state &amp;amp;&amp;amp; item.state.toUpperCase() !== "OK");&lt;/LI-CODE&gt;&lt;P&gt;That’s it. It’s best to filter by state after the merge, because state comes from monitoredEntitiesMonitoringStateClient.getStates()&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 11:17:14 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295481#M3944</guid>
      <dc:creator>t_pawlak</dc:creator>
      <dc:date>2026-03-02T11:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: api for extract state of monitoring process</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295483#M3945</link>
      <description>&lt;P&gt;is possible have timeseries? because, in this case i have only the last value and i can't use line widget.&lt;BR /&gt;&lt;BR /&gt;thanks a lot&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 11:23:54 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295483#M3945</guid>
      <dc:creator>gasperetta</dc:creator>
      <dc:date>2026-03-02T11:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: api for extract state of monitoring process</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295484#M3946</link>
      <description>&lt;P&gt;(-: is my request too&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 11:24:40 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295484#M3946</guid>
      <dc:creator>gasperetta</dc:creator>
      <dc:date>2026-03-02T11:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: api for extract state of monitoring process</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295488#M3947</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;IMO yes,&amp;nbsp;timeseries is possible, but not from getStates().&lt;BR /&gt;I am pretty sure, that&amp;nbsp;monitoredEntitiesMonitoringStateClient.getStates() returns a point-in-time snapshot. Like monitoring state. So you’ll always have only a single latest value.&lt;BR /&gt;Mabye chang state to number (OK=0, WARNING=1, ERROR=2) and send it as custom metric. Thanks to that you can show it in line widget&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 13:37:42 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/api-for-extract-state-of-monitoring-process/m-p/295488#M3947</guid>
      <dc:creator>t_pawlak</dc:creator>
      <dc:date>2026-03-02T13:37:42Z</dc:date>
    </item>
  </channel>
</rss>

