Create 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:
- Go to Logs or Logs & Events (latest Dynatrace).
- On the Logs and events page, turn on Advanced mode.
- Select copy for the code sample below.
fetch logs| filter matchesPhrase(content, "Connection refused")| 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 filters the log data containing the phrasematchesPhrase(content, "Connection refused")Connection refused
. - For the Metric measurement option, select Occurrence of log records.
The metric represents the count of occurrences of log records that contain theConnection refused
phrase. - Select Save changes to create the log metric.
View metric
To view the result in Data Explorer
- Go to Data Explorer.
- Select the
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. 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
- Go to Logs or Logs & Events (latest Dynatrace).
- On the Logs and events page, turn on Advanced mode.
- Select Copy for the code sample below.
fetch logs| filter matchesValue(dt.entity.kubernetes_cluster, "KUBERNETES_CLUSTER-92233333")| 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 containing theKUBERNETES_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):matchesValue(dt.entity.kubernetes_cluster, "KUBERNETES_CLUSTER-92233333") - For the Metric measurement option, select Occurrence of log records.
The metric represents the count of occurrences of log records that contain the phraseKUBERNETES_CLUSTER-92233333
. - Add a dimension
status
. - Select Save changes to create the log metric.
View metric
To view the result in Data Explorer
- Go to Data Explorer.
- Select the
log.K8-92233333
log key and, in the Split by, addstatus
. - Select Run query.