Swiftorial Logo
Home
Swift Lessons
Tutorials
Learn More
Career
Resources

Custom Metrics Tutorial - Dynatrace

Introduction to Custom Metrics

Custom metrics are user-defined metrics that allow you to monitor specific performance indicators that are not covered by the default metrics provided by Dynatrace. These metrics can help you gain insights into your applications and infrastructure by tracking their unique performance characteristics.

In this tutorial, we will explore how to create and use custom metrics in Dynatrace, along with practical examples to illustrate the process.

Why Use Custom Metrics?

Default metrics are excellent for general performance monitoring, but they may not capture all the specific metrics pertinent to your applications. Custom metrics enable you to:

  • Track application-specific performance indicators.
  • Measure business KPIs (Key Performance Indicators).
  • Enhance observability by monitoring unique events or states.

How to Create Custom Metrics

Creating custom metrics in Dynatrace involves a few essential steps. Here’s how you can do it:

  1. Define the Metric: Identify what you want to measure. For example, if you want to track the number of user logins in your application, you would define a metric called user.logins.
  2. Implement Metric Tracking: Use the Dynatrace API or SDK to send data for your custom metric. For example, if you're using a Java application, you could use the Dynatrace SDK for Java to send your custom metric data.
  3. Visualize the Metric: After sending the data, you can visualize it in the Dynatrace dashboard by creating custom charts and dashboards.

Example: Tracking User Logins

Let's say you want to track the number of user logins to your application. Here’s how you can implement this custom metric:

Step 1: Define Metric
user.logins
Step 2: Implement Metric Tracking

Using the Dynatrace SDK for Java, you could implement the following code:

// Import the Dynatrace SDK import com.dynatrace.sdk.*; // Assuming you have a method that gets called on user login public void onUserLogin() { // Send custom metric to Dynatrace CustomMetrics.send("user.logins", 1); }
Step 3: Visualize the Metric

After implementing the above code, go to the Dynatrace dashboard, and create a chart to visualize the user.logins metric. You can filter by application and time to gain insights into user behavior.

Conclusion

Custom metrics are a powerful way to extend the capabilities of Dynatrace and monitor application performance tailored to your specific needs. By following the steps outlined in this tutorial, you can effectively create, implement, and visualize custom metrics in your own environment.