# Convert Log query to log metric event for alerting

**URL:** <https://community.dynatrace.com/t/convert-log-query-to-log-metric-event-for-alerting/49665>\
**Category:** Alerting\
**Tags:** problem-detection, problem-notification, anomaly-detection\
**Created:** [January 10, 2025, 10:14pm UTC](https://community.dynatrace.com/t/convert-log-query-to-log-metric-event-for-alerting/49665 "2025-01-10T22:14:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpeng](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@rpeng](https://community.dynatrace.com/u/rpeng)\
**Post date:** [January 10, 2025, 10:14pm UTC](https://community.dynatrace.com/t/convert-log-query-to-log-metric-event-for-alerting/49665/1 "2025-01-10T22:14:18Z")

</div>

Hello,

We need to create a log metric to track the number of errors per minute, and then we can create a metric event that triggers if the number of errors is \> some value for more than X minutes in the last X minutes.&nbsp; This should then create a problem card if there are errors and then we can create alerts off of that problem card.

Query:

fetch logs //, scanLimitGBytes: 500, samplingRatio: 1000  
| filter matchesValue(dt.kubernetes.cluster.name, “dynakube-prd-centralus-plum-app-k8s”) or matchesValue(dt.kubernetes.cluster.name, “dynakube-prd-eastus2-plum-app-k8s”)  
| filter matchesValue(k8s.deployment.name, “claims-ai-svc-claims-ai-helm-\*”)  
| filter k8s.container.name == “claims-ai-helm”&nbsp;  
| sort timestamp desc  
| parse content, “JSON:json”  
| filter json[level] == “error”  
| fields&nbsp; timestamp ,json[level],json[data][msg],json[context], json[aiClaimId],content,json[hostname]

I am creating the new log processing rule but I am unable to set the correct processor definition in addition to the Matcher as my query above has several filters. Can someone assist me with corrections? Following documentation here:

[Create anomaly detection metric — Dynatrace Docs](https://docs.dynatrace.com/docs/analyze-explore-automate/logs/lma-use-cases/lma-e2e-create-anomaly-detection-metric)

Currently i’m using the last matchesValue:

matchesValue(k8s.deployment.name, “claims-ai-svc-claims-ai-helm-\*”)

 ![json-content.jpg](https://global.discourse-cdn.com/dynatrace/original/3X/b/4/b422197fc1e1e9552eaabb390db313850adfc7c1.jpeg)  
 ![ai-claims-parse.jpg](https://global.discourse-cdn.com/dynatrace/original/3X/a/e/aed59ecc521aaa1055c73a88c50fc78a34e06c84.jpeg)

---

<div class="post-metadata">

**Author:** ![RohitBisht](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/rohitbisht/32/38577_2.png) [@RohitBisht](https://community.dynatrace.com/u/RohitBisht)\
**Post date:** [January 11, 2025, 1:09am UTC](https://community.dynatrace.com/t/convert-log-query-to-log-metric-event-for-alerting/49665/2 "2025-01-11T01:09:20Z")

</div>

Hi&nbsp;[@rpeng](https://community.dynatrace.com/user/59572)&nbsp;,  
As far as I understood your query, you should use summarize to get the count of errors and then split using dimensions.  
Below is a sample:

fetch logs  
| filter loglevel == “ERROR”  
| summarize count(), by: {dt.entity.host,log.source}

Later, while setting the alert definition you can set the 1 minute interval to check the count of errors.

> **[Set up custom alerts based on metrics extracted from logs](https://docs.dynatrace.com/docs/analyze-explore-automate/logs/lma-use-cases/lma-alert-log-based-metrics)**
>
> How to create and configure Davis problems and custom alerts with metrics based on logs.
