如何可视化指标应用程序见解?

时间:2019-03-21 14:15:22

标签: c# azure azure-application-insights

我正在为我的应用程序见解添加指标,但是我不知道如何可视化我跟踪的值。我不知道我做的是否正确。

我的代码如下:

    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;
            .........

我将方法称为:

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);
        }

    }

我不知道我是否正确理解了轨道,因为我在Azure Application Insights上看不到任何东西。

Azure Portal Application Insights

也许我的代码有错误?有人帮忙吗?

1 个答案:

答案 0 :(得分:0)

找到了解决方案。您必须单击“指标”,然后查找您已制定的指标。

enter image description here

然后您可以通过选择图形来获取图形。

enter image description here

您还可以通过在Analysis上查询来检查它们。