cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trying to convert a session query into a custom metric. First time.

runatyr
Organizer

Hello:

I am trying to convert a session query into custom metric. 

At the end of the day. I want to be able to show in a bar char the amount of user session every 15 minutes.

I need to change this into an API call since we will be using the API to export the data into another system.

In the graph below (in Dynatrace) I have this being done for the last 12 hours. However, when I click on "Create Custom Metric"

I get the following errors/alerts that it can not convert.

How can the query above be converted so that it is custom metric friendly?

See the error and images below.

This is the query and alerts associated when changing to a custom metric.

--> 

SELECT DISTINCT DATETIME(starttime, 'E/dd--HH:mm', '15m'), COUNT (*) FROM usersession WHERE startTime >= $NOW - DURATION("12h") AND endTime <= $NOW and browserFamily !="Synthetic monitor"

-->

Screenshot 2025-06-25 080249.pngScreenshot 2025-06-25 080321.png

 

2 REPLIES 2

radek_jasinski
DynaMight Guru
DynaMight Guru

Hi,

If you want to count the number of user sessions every 15 minutes and expose this data via the API, you can’t directly convert a USQL query using DATETIME and DISTINCT into a custom metric. Dynatrace does not support this when creating custom metrics. Instead, you should use the Settings API and the builtin:custom-metrics schema to define your own COUNTER-type metric, which will automatically count closed user sessions. You can add a filter, for example, to exclude synthetic sessions (browserFamily != "Synthetic monitor"). Once the metric is created, the data will be collected automatically and will be available through the Metrics API. There, you can apply time aggregation, such as rollup(sum,15m), to get the number of sessions in 15-minute intervals.

https://docs.dynatrace.com/docs/shortlink/rum-custom-metrics-user-sessions#create-metrics-via-API

Radek

Have a nice day!

I was able to make the metric under the settings-->user session custom metrics--> Add item 

(See below)

Would this accomplish the same thing as the "Settings" API method?

I should be able to go in an query this from metrics now...correct?

Screenshot 2025-06-25 111619.png

Featured Posts