0
votes

I am adding metrics to my application insights, but I don't know how to visualize values I track. I don't know if I'm doing it correctly.

My code looks like:

    public void AddCustomMetric(String metricName,double Amount,  List<Property> additionalProperties)
    {
        CreateMetric(metricName, Amount, additionalProperties);
    }

    private void CreateMetric(String metricName, double amount, List<Property> additionalProperties)
    {
        List<String> metrycsNameList = new List<String>();
        List<String> metrycsValueList = new List<String>();
        try
        {
           additionalProperties.ForEach(property => metrycsValueList.Add(property.Value));
           additionalProperties.ForEach(property => metrycsNameList.Add(property.Name));
           Metric metric = _client.GetMetric(new MetricIdentifier("MetricNamespace", metricName, metrycsNameList));
            //metrycsValueList.ForEach(metricValue => metric.TrackValue(Amount, metricValue, "hola", "adios"));
            AddMetricValues(metric, amount, metrycsValueList);
        }
        catch (Exception ex)
        {
            throw new CustomMetricException("CustomMetricException", "Error adding a Custom Metric", ex.StackTrace);
        }

    }

    private void AddMetricValues(Metric metric, double amount, List<String> metrycsValueList)
    {
        int numberOfElements = metrycsValueList.Count;

        switch (numberOfElements)
        {
            case 1:
                metric.TrackValue(amount, metrycsValueList[0]);
                break;
            case 2:
                metric.TrackValue(amount, metrycsValueList[0], metrycsValueList[1]);
                break;
            case 3:
                metric.TrackValue(amount, metrycsValueList[0], metrycsValueList[1], metrycsValueList[2]); 
                break;
            .........

I call the method like:

public void AddCustomMetricTestTupla()
    {
        List<Property> propertiesList = new List<Property>();
        propertiesList.Add(new Property("propertyExample", "value"));
        propertiesList.Add(new Property("propertyExample1", "value2"));
        propertiesList.Add(new Property("propertyExample2", "value3"));

        //Tests method AddCustomMetric giving a tuple as a param.
        using (AzureInsightsClient azureInsightsClient = new AzureInsightsClient(myClientKey))
        {
            azureInsightsClient.FlushMetrics();
            azureInsightsClient.AddCustomMetric("Example", 2, propertiesList);
        }

    }

I don't know if I'm getting the track correctly or not, because I can't see anything on Azure Application Insights.

Azure Portal Application Insights

Maybe I have an error on my code? Anyone help?

1
What is AzureInsightsClient? (And what does the Dispose inside of it do?) and what does FlushMetrics do?Peter Bons

1 Answers

0
votes

Found the solution. You have to click on Metrics and look for your metric you have made.

enter image description here

And you can get the graphs by selecting it.

enter image description here

You can also check them by query at Analysis.