# api for extract state of monitoring process

**URL:** <https://community.dynatrace.com/t/api-for-extract-state-of-monitoring-process/55150>\
**Category:** Dynatrace API\
**Tags:** dynatrace-api\
**Created:** [March 2, 2026, 9:50am UTC](https://community.dynatrace.com/t/api-for-extract-state-of-monitoring-process/55150 "2026-03-02T09:50:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gasperetta](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@gasperetta](https://community.dynatrace.com/u/gasperetta)\
**Post date:** [March 2, 2026, 9:50am UTC](https://community.dynatrace.com/t/api-for-extract-state-of-monitoring-process/55150/1 "2026-03-02T09:50:43Z")

</div>

hi,

in the community i have downloaded this runbook very helpful,  
but i need to exract only the process that have monitoring state different from “ok”.

How can change the code?

/\*  
\* This function will run in the DYNATRACE JavaScript runtime.  
\* For information visit [App functions | Dynatrace Developer](https://dt-url.net/functions-help)  
\*/  
import { monitoredEntitiesMonitoringStateClient } from “@dynatrace-sdk/client-classic-environment-v2”;  
import { queryExecutionClient } from “@dynatrace-sdk/client-query”;

// \*\*\*\* Dynatrace API \*\*\*\*  
async function fetchAllMonitoringStates(pgID) {  
const pgID\_string = `${pgID.map(id =\> `“${id}”`).join(“,”)}`;  
let nextPageKey = null;  
const monitoringStates = [];  
do {  
const params = nextPageKey  
? { nextPageKey }  
: { entitySelector: `entityId(${pgID_string})`};  
const result = await monitoredEntitiesMonitoringStateClient.getStates(params);  
monitoringStates.push(…result.monitoringStates);  
nextPageKey = result.nextPageKey;  
} while (nextPageKey);  
return monitoringStates  
}  
export default async function () {  
const now = new Date();  
const twentyMinutesAgo = new Date(now.getTime() - 20 \* 60 \* 1000);  
const formatDate = (date) =\> date.toISOString();  
const $dt\_timeframe\_from = formatDate(twentyMinutesAgo);  
const $dt\_timeframe\_to = formatDate(now);

// \*\*\*\* DQL Query \*\*\*\*  
const dqlQuery = `  
fetch dt.entity.process\_group\_instance  
| 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])  
| lookup [fetch dt.entity.host], sourceField:host.id, lookupField:id, fields:{host.name=entity.name, host.hostGroupName=hostGroupName}  
| lookup [fetch dt.entity.process\_group], sourceField:pg\_id, lookupField:id, fields:{process.name=entity.name}  
| lookup [fetch dt.entity.container\_group\_instance  
| 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]  
| lookup [fetch dt.entity.cloud\_application\_instance], sourceField:pod\_id, lookupField:id, fields:{pod\_name=entity.name}  
| lookup [fetch dt.entity.cloud\_application\_namespace], sourceField:namespace\_id, lookupField:id, fields:{namespace=entity.name}  
| 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}  
| fields managementZones, host.id, host.name, host.hostGroupName, process.name, pod\_name, namespace, node\_name, id  
| sort process.name desc  
//| filter host.hostGroupName == “bet-booker”  
`;

// \*\*\*\* Execution Performance Limits \*\*\*\*  
// const queryExecution = await queryExecutionClient.queryExecute({ body: { query: dqlQuery } });  
const queryExecution = await queryExecutionClient.queryExecute({ body: {  
query: dqlQuery,  
scanLimitGBytes: -1  
// fetchTimeoutSeconds:5000,  
// defalutScanLimitsGbytes: 500000,  
// maxResultsBytes: 100000000,  
// maxResultsRecords: 300000000  
} });  
let dqlResults = [];  
while (true) {  
const queryPollResult = await queryExecutionClient.queryPoll({ requestToken: queryExecution.requestToken });  
if (queryPollResult.state !== “RUNNING”) {  
dqlResults = queryPollResult.result.records;  
break;  
}  
}  
let pgID = dqlResults.map(item =\> item.id);  
const processAllChunks = async () =\> {  
const allMonitoringStates = [];  
for (let i = 0; i \< pgID.length; i += 50) {  
const chunk = pgID.slice(i, i + 50);  
const chunkStates = await fetchAllMonitoringStates(chunk);  
allMonitoringStates.push(…chunkStates);  
}  
return allMonitoringStates;  
};  
const monitoringStates = await processAllChunks();  
const mergedResults = dqlResults.map(dqlItem =\> {  
const match = monitoringStates.find(apiItem =\> apiItem.entityId === dqlItem.id);  
return match ? { …dqlItem, severity: match.severity, state: match.state } : dqlItem;  
});  
return mergedResults  
}

---

<div class="post-metadata">

**Author:** ![t\_pawlak](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/t_pawlak/32/14991_2.png) [@t\_pawlak](https://community.dynatrace.com/u/t_pawlak)\
**Post date:** [March 2, 2026, 10:57am UTC](https://community.dynatrace.com/t/api-for-extract-state-of-monitoring-process/55150/2 "2026-03-02T10:57:55Z")

</div>

Hi,  
try this:  
Total number of calls over the selected time range (sum of all minutes)

```markup
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)

```

 ![comm1.jpg](https://global.discourse-cdn.com/dynatrace/original/2X/4/41e43c5fd11cdb61c61c2fcfbd8850d919b06adf.jpeg)

Current total (last datapoint),&nbsp; combined calls/min at the end of the chart

```markup
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)

```

 ![comm2.jpg](https://global.discourse-cdn.com/dynatrace/original/2X/f/fd2951c4f3445acf4246604f7265a7360539f358.jpeg)

---

<div class="post-metadata">

**Author:** ![t\_pawlak](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/t_pawlak/32/14991_2.png) [@t\_pawlak](https://community.dynatrace.com/u/t_pawlak)\
**Post date:** [March 2, 2026, 11:00am UTC](https://community.dynatrace.com/t/api-for-extract-state-of-monitoring-process/55150/3 "2026-03-02T11:00:05Z")

</div>

Sorry, wrong thread

---

<div class="post-metadata">

**Author:** ![t\_pawlak](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/t_pawlak/32/14991_2.png) [@t\_pawlak](https://community.dynatrace.com/u/t_pawlak)\
**Post date:** [March 2, 2026, 11:17am UTC](https://community.dynatrace.com/t/api-for-extract-state-of-monitoring-process/55150/4 "2026-03-02T11:17:14Z")

</div>

Hi,

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”.  
Change&nbsp;return mergedResults to

```javascript
const mergedResults = dqlResults.map(dqlItem => {
  const match = monitoringStates.find(apiItem => apiItem.entityId === dqlItem.id);
  return match ? { ...dqlItem, severity: match.severity, state: match.state } : dqlItem;
});

//Only proccesses !== "OK"
const onlyNotOk = mergedResults.filter(item => {
  // 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;

```

If you want to drop records with no state and keep only “real” non-OK ones:

```javascript
return mergedResults.filter(item => item.state && item.state.toUpperCase() !== "OK");

```

That’s it. It’s best to filter by state after the merge, because state comes from monitoredEntitiesMonitoringStateClient.getStates()

---

<div class="post-metadata">

**Author:** ![gasperetta](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@gasperetta](https://community.dynatrace.com/u/gasperetta)\
**Post date:** [March 2, 2026, 11:23am UTC](https://community.dynatrace.com/t/api-for-extract-state-of-monitoring-process/55150/5 "2026-03-02T11:23:54Z")

</div>

is possible have timeseries? because, in this case i have only the last value and i can’t use line widget.

thanks a lot

---

<div class="post-metadata">

**Author:** ![gasperetta](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@gasperetta](https://community.dynatrace.com/u/gasperetta)\
**Post date:** [March 2, 2026, 11:24am UTC](https://community.dynatrace.com/t/api-for-extract-state-of-monitoring-process/55150/6 "2026-03-02T11:24:40Z")

</div>

(-: is my request too

---

<div class="post-metadata">

**Author:** ![t\_pawlak](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/t_pawlak/32/14991_2.png) [@t\_pawlak](https://community.dynatrace.com/u/t_pawlak)\
**Post date:** [March 2, 2026, 1:37pm UTC](https://community.dynatrace.com/t/api-for-extract-state-of-monitoring-process/55150/7 "2026-03-02T13:37:42Z")

</div>

Hi,  
IMO yes,&nbsp;timeseries is possible, but not from getStates().  
I am pretty sure, that&nbsp;monitoredEntitiesMonitoringStateClient.getStates() returns a point-in-time snapshot. Like monitoring state. So you’ll always have only a single latest value.  
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
