Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在使用Azure Application Insights调用第三方API时创建警报_Azure_Alert_Monitoring_Azure Application Insights - Fatal编程技术网

在使用Azure Application Insights调用第三方API时创建警报

在使用Azure Application Insights调用第三方API时创建警报,azure,alert,monitoring,azure-application-insights,Azure,Alert,Monitoring,Azure Application Insights,我已经在我创建的Azure WebApp上启用了应用程序洞察。我的WebApp正在调用一个按配额运行的第三方API。我每月只允许打10万个电话 我需要跟踪这些API调用,以便在调用数达到50%时创建一个警报,然后再创建一个75%的警报 每次调用时,我都会使用TrackEvent,AppInsights仪表板中的事件不会增加。但我似乎无法在拨打一定数量的电话时创建警报。我无法从“事件”下拉列表中看到它 此外,我需要的另一个要求是,当呼叫的次数超过每分钟10次时,创建警报 TrackEvent是满足

我已经在我创建的Azure WebApp上启用了应用程序洞察。我的WebApp正在调用一个按配额运行的第三方API。我每月只允许打10万个电话

我需要跟踪这些API调用,以便在调用数达到50%时创建一个警报,然后再创建一个75%的警报

每次调用时,我都会使用TrackEvent,AppInsights仪表板中的事件不会增加。但我似乎无法在拨打一定数量的电话时创建警报。我无法从“事件”下拉列表中看到它

此外,我需要的另一个要求是,当呼叫的次数超过每分钟10次时,创建警报

TrackEvent是满足这些要求的正确方法吗

我做了这样的事

var telemetryEventClient = new Microsoft.ApplicationInsights.TelemetryClient(new Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration() { InstrumentationKey = "Instrumentation Key" });
telemetryEventClient.Context.Operation.Name = "MyAPIProvider";

var properties = new Dictionary<string, string>
{
    { "Source", "WebAppToAPI" }
};

var metrics = new Dictionary<string, double>
{
    { "CallingAPIMetric", 1 }
};

telemetryEventClient.TrackEvent("CallingAPI", properties, metrics);
var telemetryEventClient=新的Microsoft.ApplicationInsights.TelemetryClient(新的Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration(){InstrumentationKey=“Instrumentation Key”});
telemetryEventClient.Context.Operation.Name=“MyAPIProvider”;
var属性=新字典
{
{“源”,“WebAppToAPI”}
};
var度量=新字典
{
{“CallingAPIMetric”,1}
};
telemetryEventClient.TrackEvent(“CallingAPI”、属性、度量);

但是,当我考虑设置警报并将阈值设置为50000(对于测试,我只设置了5)时,我从未达到该阈值,因为事件计数始终为1。我这样做对吗?

您试图定义的警报总是关注您在自定义事件中提供的值,而不是您触发的事件量。
您可以创建一个自动流来查询事件,并在查询结果超过某个阈值时向您发送电子邮件。 适用于Flow和Microsoft Logic应用程序的Application Insights Connector就是为此而创建的,它可以在任何文档类型(事件、度量甚至跟踪)的任何查询结果上定义。 关于如何创建自己的流的分步文档如下所示

至于您的查询-您需要一个简单的分析查询,如下所示:

customEvents
| where timestamp > ago(1h) // or any time range you need
| where name == "CallingAPI"
| count

关于如何使用流/逻辑应用程序,这真的很有趣。我以后肯定会在另一个项目中使用它。但是与公司安全人员聊天,他说任何使用API密钥和/或链接其他应用程序的行为都不会被接受。还有其他选择吗?我们试图解决“资源枯竭”的问题,这就是为什么我想计算一小时内发生了多少次“CallingAPI”。如果阈值设置为50,并且一小时内有51个呼叫,则会发送电子邮件警报。如何执行自定义事件以获取事件量而不是传递的值?