Dynatrace tips
Tips and workarounds from Dynatrace users for Dynatrace users.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PRO TIP - Build dashboards with Dashboard snippets with Monaco Configuration as code

Julius_Loman
DynaMight Legend
DynaMight Legend

Building reusable dashboards is not easy. Sometimes you need to include the same set of widgets across your dashboards and make changes in a single place in your config as code.

Dynatrace Monaco has supported the file parameters already for a while, which allows you to include data from a file as a parameter. So we want to define our snippets and use them in our dashboards. 

In my example for Dashboards Classic, I have two snippets:

  • JVM - tiles with JVM metrics
  • Service Metrics - tiles with service metrics

We need to specify the boundaries (basically top left position of the snippet) and path to the include file. The escape: false parameters ensures the file won't be escaped and will be processed correctly. We also need to reference the parameters being used in the snippet. 

Of course, both of the snippet references need to be included in the main dashboard.json.

configs:
- id: dashboard-snippet1
  config:
    name: "Dashboard with Snippets1"
    parameters:
      # General parameters
      serviceTag: "service1"
      processTag: "process1"

      # Snippet for JVM Metrics
      snippet_JVM_left: 0  # left snippet boundary
      snippet_JVM_top: 0   # top snippet boundary
      snippet_JVM:
        type: file
        path: snippets/JVM.json
        escape: false
        references:
          - snippet_JVM_left
          - snippet_JVM_top
          - processTag

      # Snippet for Service Metrics
      snippet_ServiceMetrics_left: 0  # left snippet boundary
      snippet_ServiceMetrics_top: 304 # top snippet boundary - this has to be a constant we can't do relative calculation
      snippet_ServiceMetrics:
        type: file
        path: snippets/ServiceMetrics.json
        escape: false
        references:
          - snippet_ServiceMetrics_left
          - snippet_ServiceMetrics_top
          - serviceTag

    template: dashboard.json
    skip: false
  type:
    api: dashboard


Snippets themselves have to lay out it's tiles based on parameters. This allows having relative positions of the tiles on a classic dashboard. 

A complete sample is available in my GitHub repository https://github.com/juliusloman/dynatrace-configuration-as-code-advanced-samples 

Dynatrace Ambassador | Alanata a.s., Slovakia, Dynatrace Master Partner
0 REPLIES 0

Featured Posts