Search code examples
azureazure-application-insightsmetrics

different between counterBuilder and histogramBuilder when you create graphe on monitor azur metric?


hi i have question about custom metric . i use this method

GlobalOpenTelemetry.getMeter("toto").counterBuilder("count").setUnit("milliseconds").build().add(Long.valueOf(2L);
GlobalOpenTelemetry.getMeter("toto").histogramBuilder("histo").setUnit("milliseconds").build().record(2.0);

when i click on azur monitor ->supervision -> metric i select the metric name and i can see my graph . count metric and "histo" metric are no different ?

other example i use this tutorial


  Meter meter = GlobalOpenTelemetry.getMeter("OTEL.AzureMonitor.Demo");

        LongCounter myFruitCounter = meter
                .counterBuilder("MyFruitCounter")
                .build();

        myFruitCounter.add(1, Attributes.of(AttributeKey.stringKey("name"), "apple", AttributeKey.stringKey("color"), "red"));
        myFruitCounter.add(2, Attributes.of(AttributeKey.stringKey("name"), "lemon", AttributeKey.stringKey("color"), "yellow"));
        myFruitCounter.add(1, Attributes.of(AttributeKey.stringKey("name"), "lemon", AttributeKey.stringKey("color"), "yellow"));
        myFruitCounter.add(2, Attributes.of(AttributeKey.stringKey("name"), "apple", AttributeKey.stringKey("color"), "green"));
        myFruitCounter.add(5, Attributes.of(AttributeKey.stringKey("name"), "apple", AttributeKey.stringKey("color"), "red"));
        myFruitCounter.add(4, Attributes.of(AttributeKey.stringKey("name"), "lemon", AttributeKey.stringKey("color"), "yellow"));
    }

i try to create my graphe in azur monitor >supervision>metric i can select my metric . but when i create the graph i cannot see the label apple and lemon . maybe metric on azur its not to create graph for metric :/. how i can create this specfic graph i dont want to use grafana :)

i try the solution and use microsoft azure website but the tutorial is not good :/


Solution

  • Counter and histogram metrics serve different purposes. To see meaningful distinctions in the metrics in Azure Monitor, Adjusting the data collected and the visualization settings should help you see the differences more clearly. collecting and visualizing the data in a way that highlights their specific characteristics and purposes.

    • Azure Monitor's native metric charts might not always show labels for individual data points when you have multiple dimensions or attributes attached to your metrics.

    By using Azure Monitor Workbooks, we can visualize the "apple" and "lemon" labels alongside the metric values.

    Created Custom metrics:

    enter image description here

    • After sending your metrics data with values to Azure Monitor, you can query these metrics in Azure Monitor Metrics Explorer or Logs.

    Use Metrics Explorer:

    • Select the metric ("MyFruitCounter") and use the "Group by" feature to group the data by the "name" and "color" dimensions. it creates separate lines or bars for each combination of "name" and "color,"

    Create a log query:

    enter image description here

    • Write a custom query to group and aggregate data by values.
    MyFruitCounter
    | summarize SumValue = sum(CounterValue) by name, color
    

    Use the grouping and aggregation capabilities in Metrics Explorer or Logs to visualize your data by these values.