我使用Microsoft.Azure.Management.Fluent
SDK包来访问Azure Monitor指标,如下所示:
var credentials = SdkContext.AzureCredentialsFactory
.FromServicePrincipal("some-client-id", "some-client-secret", "some-tenant-id", AzureEnvironment.AzureGlobalCloud);
var azure = Microsoft.Azure.Management.Fluent.Azure
.Configure()
.Authenticate(credentials)
.WithSubscription("my-subscription");
foreach (var metricDefinition in azure.MetricDefinitions.ListByResource("my-resource-uri"))
{
...
}
它对于常见指标(Application Insights标准指标)工作正常。但是,如何使用此SDK获取自定义事件,以将其呈现在自定义应用仪表板中?我在Application Insights仪表板的“基于日志的指标”下看到了记录的事件,但ListByResource方法未返回它们。
我怀疑这可能是错误。
ListByResource
方法有2个参数,第二个是metricnamespace
。
默认情况下,metricnamespace
是microsoft.insights/components
,用于Application Insights standard metrics
。
对于Log-based metrics
,metricnamespace
应该为microsoft.insights/components/kusto
(要检查该值,可以使用Fiddler
或developer tool of any browser
之类的工具)。根据我的测试,当使用ListByResource("resourceId","microsoft.insights/components/kusto")
时,它将引发“错误请求”错误。因此,我提出了an issue以对此进行跟踪。