Creating log metric
Dynatrace Log Management and Analytics gives you the ability not only to view and analyze logs but also to create metrics based on log data and use them throughout Dynatrace like any other metric. You can add them to your dashboard, include them in an analysis, and even create custom alerts.
Create connections refused metric
You need to count how many refused connections are recorded in your log data. For that, filter the correct logs and turn the number of occurrences into a log metric. By tracking the metric, you can track possible firewall, network connectivity or server configuration issues.
Build DQL query
To build and run your query:
- In the Dynatrace menu, go to Logs.
- On the Logs and events page, turn on Advanced mode.
- Select
copy for the code sample below.
1fetch logs2| filter matchesPhrase(content, "Connection refused")3| sort timestamp desc - Paste the query into the query edit box and select Run query.
This query performs the following actions:
- Retrieves logs with the
Connection refused
phrase found in the log content. Sorts the result in descending order according to the timestamp.
Create metric
- Go to Settings > Log Monitoring > Metrics extraction and select Add log metric.
- In Key, append the metric name to the
log.
metric key:log.conn_refused_count
- Add Matcher.
Use the DQL function for matching phrases, which is part of the Dynatrace Query Language (DQL):This will filter the log data containing the phrase1matchesPhrase(content, "Connection refused")Connection refused
. - For the Metrc measurement option, select Occurrence of log records.
The metric will represent the count of occurrences of log records that containConnection refused
phrase. - Select Save changes to create the log metric.
View metric
View the result in data explorer:
- In the Dynatrace menu, go to Data explorer.
- Select
log.conn_refused_count
log key. - Select Run query.
Create log attribute metric
You need to monitor an attribute of your logs, and you need to keep an eye on the error levels reported in your logs from your K8s cluster. Find the correct logs from Grail, and use the filters to create a new metric for these. Turn your attention to add log status (error/warning/info) to your metric, which makes it easy to track these with metrics.
Build DQL query
To build and run your query:
- In the Dynatrace menu, go to Logs.
- On the Logs and events page, turn on Advanced mode.
- Select
copy for the code sample below.
1fetch logs2| filter matchesValue(dt.entity.kubernetes_cluster, "KUBERNETES_CLUSTER-92233333")3| summarize count(), by:status - Paste the query into the query edit box and select Run query.
This query performs the following actions:
- Retrieves log records with the
dt.entity.kubernetes_cluster
attribute containingKUBERNETES_CLUSTER-92233333
phrase in the log content. Counts the number of such log records and orders them by their status attribute.
Create metric
- Go to Settings > Log Monitoring > Metrics extraction and select Add log metric.
- In Key, append the metric name to the
log.
metric key:K8-92233333
- Add Matcher.
Use the DQL function for matching phrases, which is part of the Dynatrace Query Language (DQL):1matchesValue(dt.entity.kubernetes_cluster, "KUBERNETES_CLUSTER-92233333") - For the Metrc measurement option, select Occurrence of log records.
The metric will represent the count of occurrences of log records that containKUBERNETES_CLUSTER-92233333
phrase. - Add a dimension
status
. - Select Save changes to create the log metric.
View metric
View the result in data explorer:
- In the Dynatrace menu, go to Data explorer.
- Select
log.K8-92233333
log key and in the Split by addstatus
. - Select Run query.