我正在为我的应用程序见解添加指标,但是我不知道如何可视化我跟踪的值。我不知道我做的是否正确。
我的代码如下:
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
也许我的代码有错误?有人帮忙吗?