Application Insights Alert not firing for custom Metric

核能气质少年 提交于 2019-12-24 21:57:06

问题


I have set up ApplicationInsights in my js code and whenever I send data to it, it is tracked correctly and I can see it in the portal. I want now to set up an email notification when errors or some custom metric that I define occur. As you can see from the image below, I have set up 3 alerts. The first 2 (ServerErrors and BrowserErrors) work fine and I get email notifications. I have then set up the 3rd so that when I send a metric using this code

var properties = {
        Date: new Date(),
        Text: 'some text',
        Email: 'someemail@email.com'
    };
appInsights.trackMetric('UserFeedback', 1, null, null, null, properties);

I should get an email notification, but I don't. From the Metrics Explorer I see the metric but I can't investigate into the metric details because the detail tab is "Under construction" in the portal. I don't know what (and if) I am doing something wrong.

Furthermore, sometimes a yellow triangle (like the one at the left of my UserFeedback alert) appears on the left side of any of the alerts (looks quite random to me). Has anyone got an idea what they are and how to fix them?


回答1:


the yellow triangle means "this event is active", and is true until the event's criteria are no longer true.

you might want to re-write this as a custom event, and submit the metric value in a call there, so you can see/search the custom event's details? metrics are not a searchable, so it would be hard to ever see the properties that way.

var properties = {
    Text: 'some text',
    Email: 'someemail@email.com'
};
var metrics = {
    UserFeedback: 1,
};
appInsights.trackEvent('User sent feedback', properties, metrics );

or something like that? (you don't need the date field, it is part of default telemetry for custom events)

As for why the alert is firing, i can never remember if the metric value is an average over the time period, or if that's a sum or something so that every time you submit 1 feedback, UserFeedback is constantly growing, so the alert value will never be back to 0?

The documentation for alerts is here: https://azure.microsoft.com/en-us/documentation/articles/app-insights-alerts/

and says:

•The period that you choose specifies the interval over which metrics are aggregated. It doesn't affect how often the alert is evaluated: that depends on the frequency of arrival of metrics.

• If no data arrives for a particular metric for some time, the gap has different effects on alert evaluation and on the charts in metric explorer. In metric explorer, if no data is seen for longer than the chart's sampling interval, the chart will show a value of 0. But an alert based on the same metric will not be re-evaluated, and the alert's state will remain unchanged.

• When data eventually arrives, the chart will jump back to a non-zero value. The alert will evaluate based on the data available for the period you specified. If the new data point is the only one available in the period, the aggregate will be based just on that.

i believe it is that second and third bullets there are getting you. you've set the value to 1, because you sent the metric. but if nobody ever sends a 0 value for that metric, the alert rules never see the value change again. you might have to do a second trackMetric("UserFeedback", 0, ... ) after your initial call so that the alert goes away? (and then set your threshold to like .5 instead of 1?)

But i'd still send any details with a custom event so you can actually see them.



来源:https://stackoverflow.com/questions/33232054/application-insights-alert-not-firing-for-custom-metric

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!