Search code examples
javametricsdatadog

How to display correct monetary value in Datadog Dashboard Widget


I've created a custom Datadog metric in a Springboot Java App, and turned on the management end-points.

I am incrementing a MeterRegistry Counter with a double value (relating to the monetary value of an order) When I use the /management/metrics end-point, I can see the correct value being stored.

However, when I create a widget in my Datadog dashboard, it is only displaying the pre-decimal point value of the data. e.g the order value is 61.67 and in Datadog it is displaying 61, so it's not even doing any rounding !

Is there any way to display the raw value of the counter in a Datadog Dashboard widget?

Thanks in advance


Solution

    1. First, I would check what metrics are being stored in Datadog with the API
    2. Second, I would check the type of metric you are sending https://app.datadoghq.com/metric/summary?metric=<my-metric> Not sure if a counter type can have decimal values, maybe a gauge would be more appropriate.
    3. Finally, to display a value you can use a query value widget such as the one in the snippet below. Make sure to:
      • Take the last value (here aggregator: last)
      • Select the number of decimals of interest (here precision: 3)
      • Select the right space aggregation if you receive this metric from multiple places (i.e. multiple tags) (here avg:my_metric{*})
    {
      "viz": "query_value",
      "requests": [
        {
          "q": "avg:nginx.logs.request.count{*}.as_count()",
          "type": null,
          "style": {
            "palette": "dog_classic",
            "type": "solid",
            "width": "normal"
          },
          "aggregator": "last",
          "conditional_formats": [
            {
              "comparator": ">",
              "palette": "white_on_red",
              "value": null
            },
            {
              "comparator": ">=",
              "palette": "white_on_yellow",
              "value": null
            },
            {
              "comparator": "<",
              "palette": "white_on_green",
              "value": null
            }
          ]
        }
      ],
      "autoscale": true,
      "precision": "3"
    }
    

    Side note: I also use this for Kafka (just as a reference) but it should not be required in your case:

    ENTRYPOINT ["java","-javaagent:dd-java-agent.jar","-Ddd.agent.host=localhost","-Ddd.jmxfetch.statsd.host=localhost","-Ddd.trace.global.tags=env:kafka","-Ddd.agent.port=8126","-Ddd.service.name=KafkaProducer","-Ddd.logs.injection=true","-Ddd.trace.analytics.enabled=true","-Ddd.kafka.analytics.enabled=true","-Ddd.servlet.analytics.enabled=true","-Ddd.spring-web.analytics.enabled=true","-jar","target/KafkaConsumer-0.0.1-SNAPSHOT.jar"]