<?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 Re: Problem duration metric sorted by longest duration in Dynatrace Managed Q&amp;A</title>
    <link>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303754#M4858</link>
    <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/100771"&gt;@Khejazi&lt;/a&gt;&amp;nbsp;there is no other way of doing that in Managed when you need the data to be displayed on a Dynatrace dashboard.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Aug 2026 10:49:40 GMT</pubDate>
    <dc:creator>Julius_Loman</dc:creator>
    <dc:date>2026-08-25T10:49:40Z</dc:date>
    <item>
      <title>Problem duration metric sorted by longest duration</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303389#M4849</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create tile in dynatrace managed dashboard to show top list of problems with longest duration in a specitic time of period sorted descendingly&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any support how to do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to filter problems and sorted by duration and then pin to dashboard, but it is showing me a single value and i cannot configure it in Data Explorer.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Aug 2026 08:19:12 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303389#M4849</guid>
      <dc:creator>Khejazi</dc:creator>
      <dc:date>2026-08-18T08:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Problem duration metric sorted by longest duration</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303420#M4850</link>
      <description>&lt;P&gt;If you are using the Gen1/2 Problem page and you save the tile, it will only save filter constructs and time frames, not sorting preferences on the table view. Additionally the tile will only show you a problem count. If you want a table version say a top 10 list, you will need to do this in the Gen3 UI with the new problems page:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChadTurner_0-1787058514572.png"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/34025i5AC8D0CE2AF33B19/image-size/large?v=v2&amp;amp;px=999" alt="ChadTurner_0-1787058514572.png" title="ChadTurner_0-1787058514572.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Granted this is in a Scatter plot but you can put it into a table format, or even a record format.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Aug 2026 13:11:00 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303420#M4850</guid>
      <dc:creator>ChadTurner</dc:creator>
      <dc:date>2026-08-18T13:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problem duration metric sorted by longest duration</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303587#M4851</link>
      <description>&lt;P&gt;Unfortunately, i am using Dynatrace managed where I cannot write DQL , so I was playing with the metrics but could not reach to a solution&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2026 05:59:40 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303587#M4851</guid>
      <dc:creator>Khejazi</dc:creator>
      <dc:date>2026-08-20T05:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Problem duration metric sorted by longest duration</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303589#M4852</link>
      <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/100771"&gt;@Khejazi&lt;/a&gt;&amp;nbsp;Managed does not have any &lt;A href="https://docs.dynatrace.com/managed/shortlink/built-in-metrics" target="_blank"&gt;built-in metrics&lt;/A&gt;&amp;nbsp;related to problems. You cannot create metric on problem data directly in Managed. You can only do that externally by fetching the data using Problem V2 API and sending a metric data. For example, by an ActiveGate extension.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2026 06:27:38 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303589#M4852</guid>
      <dc:creator>Julius_Loman</dc:creator>
      <dc:date>2026-08-20T06:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Problem duration metric sorted by longest duration</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303590#M4853</link>
      <description>&lt;P&gt;Well,&lt;/P&gt;&lt;P&gt;Can you guide me how to do that if you please&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2026 06:51:38 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303590#M4853</guid>
      <dc:creator>Khejazi</dc:creator>
      <dc:date>2026-08-20T06:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: Problem duration metric sorted by longest duration</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303711#M4854</link>
      <description>&lt;P&gt;Still looking for a solution here please&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2026 10:59:35 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303711#M4854</guid>
      <dc:creator>Khejazi</dc:creator>
      <dc:date>2026-08-24T10:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Problem duration metric sorted by longest duration</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303749#M4855</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/100771"&gt;@Khejazi&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;Quick and dirty approach (Sorry, vibecoded due to time pressure), you need to install the python modules&amp;nbsp;&lt;SPAN&gt;requests and&amp;nbsp;dynatrace-metric-utils.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#!/usr/bin/env python3
"""Fetch open problems from Dynatrace Problems v2 API, print them, and push duration as metric.ingest."""

import os
import sys
from datetime import datetime, timezone

import requests
from dynatrace.metric.utils import DynatraceMetricsFactory, DynatraceMetricsSerializer, MetricError

DT_ENVIRONMENT = os.environ.get("DT_ENVIRONMENT")  # e.g. https://abc12345.live.dynatrace.com
DT_APITOKEN = os.environ.get("DT_APITOKEN")

METRIC_KEY = "problems.active"

factory = DynatraceMetricsFactory()
serializer = DynatraceMetricsSerializer()


def duration_seconds(start_ms, end_ms):
    end_ms = end_ms if end_ms and end_ms &amp;gt; 0 else int(datetime.now(timezone.utc).timestamp() * 1000)
    return (end_ms - start_ms) // 1000


def format_duration(seconds):
    hours, remainder = divmod(seconds, 3600)
    minutes, seconds = divmod(remainder, 60)
    return f"{hours}h {minutes}m"


def get_open_problems():
    if not DT_ENVIRONMENT or not DT_APITOKEN:
        sys.exit("Set DT_ENVIRONMENT and DT_APITOKEN environment variables.")

    url = f"{DT_ENVIRONMENT.rstrip('/')}/api/v2/problems"
    headers = {"Authorization": f"Api-Token {DT_APITOKEN}"}
    params = {
        "problemSelector": 'status("open")',
        "fields": "impactLevel,severityLevel",
    }

    problems = []
    while True:
        resp = requests.get(url, headers=headers, params=params, timeout=30)
        resp.raise_for_status()
        data = resp.json()
        problems.extend(data.get("problems", []))

        next_page_key = data.get("nextPageKey")
        if not next_page_key:
            break
        params = {"nextPageKey": next_page_key}

    return problems


def build_metric_line(problem, seconds):
    dimensions = {
        "problemId": problem["problemId"],
        "displayId": problem.get("displayId", "N/A"),
        "title": problem.get("title", "N/A"),
    }
    metric = factory.create_int_gauge(METRIC_KEY, seconds, dimensions)
    return serializer.serialize(metric)


def ingest_metrics(lines):
    url = f"{DT_ENVIRONMENT.rstrip('/')}/api/v2/metrics/ingest"
    headers = {
        "Authorization": f"Api-Token {DT_APITOKEN}",
        "Content-Type": "text/plain; charset=utf-8",
    }
    resp = requests.post(url, headers=headers, data="\n".join(lines), timeout=30)
    resp.raise_for_status()
    return resp.json()


def main():
    problems = get_open_problems()

    if not problems:
        print("No open problems.")
        return

    lines = []
    for p in problems:
        seconds = duration_seconds(p["startTime"], p.get("endTime", -1))
        print(
            f"{p['problemId']}\t"
            f"{p.get('severityLevel', 'N/A')}\t"
            f"{p.get('impactLevel', 'N/A')}\t"
            f"{p.get('title', 'N/A')}\t"
            f"{format_duration(seconds)}"
        )
        try:
            lines.append(build_metric_line(p, seconds))
        except MetricError as e:
            print(f"  skipped metric for {p['problemId']}: {e}")

    result = ingest_metrics(lines)
    print(f"Ingested: {result.get('linesOk', 0)} ok, {result.get('linesInvalid', 0)} invalid")

if __name__ == "__main__":
    main()&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Julius_Loman_0-1787641928935.png"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/34122iAF339EB5F35722C1/image-size/medium?v=v2&amp;amp;px=400" alt="Julius_Loman_0-1787641928935.png" title="Julius_Loman_0-1787641928935.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2026 07:14:00 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303749#M4855</guid>
      <dc:creator>Julius_Loman</dc:creator>
      <dc:date>2026-08-25T07:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problem duration metric sorted by longest duration</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303750#M4856</link>
      <description>&lt;P&gt;This would indeed be the only way -- to ingest the problems as a metric, as there isn’t currently a metric for this in Managed.&lt;/P&gt;&lt;P&gt;You could use the &lt;STRONG&gt;Problem ID&lt;/STRONG&gt; and optionally the &lt;STRONG&gt;title&lt;/STRONG&gt; as dimensions and then build your dashboard tile based on that.&lt;/P&gt;&lt;P&gt;Just keep in mind that this will come with a certain &lt;STRONG&gt;DDU cost&lt;/STRONG&gt;, as each problem will generate a data points that consumes some of your DDU's.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2026 08:48:39 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303750#M4856</guid>
      <dc:creator>dylan_taelemans</dc:creator>
      <dc:date>2026-08-25T08:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: Problem duration metric sorted by longest duration</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303751#M4857</link>
      <description>&lt;P&gt;Well,&lt;/P&gt;&lt;P&gt;I think then it would not be the best way to implement it as it will consume the DDU in some time as&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for both of you&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/3364"&gt;@Julius_Loman&lt;/a&gt;&amp;nbsp; &amp;amp;&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/19639"&gt;@dylan_taelemans&lt;/a&gt;&amp;nbsp;for your contribution&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2026 09:04:03 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303751#M4857</guid>
      <dc:creator>Khejazi</dc:creator>
      <dc:date>2026-08-25T09:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Problem duration metric sorted by longest duration</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303754#M4858</link>
      <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/100771"&gt;@Khejazi&lt;/a&gt;&amp;nbsp;there is no other way of doing that in Managed when you need the data to be displayed on a Dynatrace dashboard.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2026 10:49:40 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303754#M4858</guid>
      <dc:creator>Julius_Loman</dc:creator>
      <dc:date>2026-08-25T10:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Problem duration metric sorted by longest duration</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303756#M4859</link>
      <description>&lt;P&gt;Thanks for the support&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2026 11:20:14 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-Managed-Q-A/Problem-duration-metric-sorted-by-longest-duration/m-p/303756#M4859</guid>
      <dc:creator>Khejazi</dc:creator>
      <dc:date>2026-08-25T11:20:14Z</dc:date>
    </item>
  </channel>
</rss>

