- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用 Azure Functions:我主要尝试将现有的 Web 作业迁移到 Azure Functions,现在是时候将 Application Insights 集成到我的一个函数中了。
所以基本上我只需要一个 TelemetryClient
实例,但这假设我能够在应用程序停止时刷新内存缓冲区。
我使用了 TimerTrigger,但它只是用于测试目的。
我引用了 Microsoft.ApplicationInsights nuget 包 ( from this SO post) 和我的 run.csx
文件如下所示:
using System;
using Microsoft.ApplicationInsights;
using Microsoft.Azure.WebJobs;
public static void Run(TimerInfo myTimer, TraceWriter log)
{
MyTimerJob.TelemetryClient.TrackEvent("AzureFunctionTriggered");
log.Verbose($"C# Timer trigger function executed at: {DateTime.Now}");
}
public static class MyTimerJob
{
public static readonly TelemetryClient TelemetryClient;
static MyTimerJob(){
TelemetryClient = new TelemetryClient()
{ InstrumentationKey = "MyInstrumentationKey" };
// When it shutdowns, we flush the telemty client.
new WebJobsShutdownWatcher().Token.Register(() =>
{
TelemetryClient.TrackEvent("TelemetryClientFlush");
TelemetryClient.Flush();
});
}
}
这个实现有点棘手...
TelemetryClient
来确保我将重用同一个实例。WebJobsShutdownWatcher
来检测主机何时停止,以便我可以刷新 TelemetryClient。为了模拟应用程序关闭,我在底层 Web 应用程序中创建了一个 “test”
应用程序设置,并在我希望主机重新启动时修改它:
不幸的是,这不起作用...我没有在应用洞察仪表板中看到任何名为 "TelemetryClientFlush"
的事件:
所以我现在想知道是否有任何方法可以在 azure 函数主机停止时进行拦截?
最佳答案
除了 Mathew 描述的内容之外,您可能还想尝试一下我们会根据要求传递的取消 token 。
如果您将 CancellationToken
类型的参数添加到您的函数,我们将传递一个 token ,当主机在正常情况下关闭时,该 token 将发出信号。使用它可以让您接近您需要的东西:
using System;
using System.Threading;
using Microsoft.ApplicationInsights;
public static readonly TelemetryClient TelemetryClient = new TelemetryClient(){ InstrumentationKey = "MyInstrumentationKey" };
public static bool first = true;
public static void Run(TimerInfo myTimer, TraceWriter log, CancellationToken token)
{
if(first){
token.Register(() =>
{
TelemetryClient.TrackEvent("TelemetryClientFlush");
TelemetryClient.Flush();
});
first = false;
}
TelemetryClient.TrackEvent("AzureFunctionTriggered");
log.Verbose($"C# Timer trigger function executed at: {DateTime.Now}");
}
关于c# - 拦截 Azure 函数主机关闭 : Flush Application Insights TelemetryClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36760241/
在MySQL中,执行FLUSH TABLES, PRIVILEGES;和执行FLUSH TABLES;再执行FLUSH PRIVILEGES;效果一样吗?此外,这是否适用于任何刷新选项(FLUSH L
在spring security生成类UserRole或 SecUserSecRole (你可以随便叫它)有一个命令可以创建 new UserRole()并用 .save(flush:flush, i
我正在使用 Hibernate 3.2.6。我正面临异常(exception)情况 save the transient instance before flushing 在我的代码中,有时我们在一个
我有一个 StreamWriter,它的底层流是一个 FileStream。以下代码是否保证 FileStream 也将其缓冲区刷新到文件系统上的实际文件中,还是我需要在 上显式调用 Flush()文
我在 ASP.NET Web API 中使用 PushStreamContent 将事件从服务器推送到客户端(使用服务器发送事件)。每次发送事件后,我都会在 Stream 上调用 Flush 以将缓冲
MSDN说FileStream.Flush(True) “还清除所有中间文件缓冲区。”。 “所有中间文件缓冲区”到底是什么意思? 最佳答案 它会将缓冲在文件系统缓存中的文件数据写入磁盘。该数据通常是根
在我的项目中,我有很多嵌套的对象,几天后服务器在每次查询执行时都变得非常缓慢。 我从object.save(flush:true)中删除了flush:true,这应该避免对象立即被数据库持久化,因为我
假设您需要将二进制数据写入标准输出: sys.stdout.buffer.write(data) 然后要刷新它,您可以使用以下两种方法之一: sys.stdout.flush() sys.stdout
我已经覆盖了 std::ostream::flush() 函数。下面我从示例中删除了所有其他代码: #include #include class CMyStream : public std::
我在我的服务中实现了取消 http 请求,我想测试它: angular.module('EmsWeb.Services').factory('DalService', ['$q', '$http',
有这个 Angular 组件: import { Component, OnDestroy, OnInit } from '@angular/core'; import { asyncSchedule
magento的缓存管理中“Flush Magento Cache”和“Flush Cache Storage”有什么区别? 最佳答案 有时,缓存位置(如 /tmp/)或服务(如 Memcache)会
我有一个实现 postFlush() 的 Hibernate 拦截器.据我了解,刷新后是数据已保存到数据库中,但在调用提交之前可能会回滚。如果我有一个看起来像这样的 hibernate 配置: tru
这是我第一次接触 Clojure,所以我尝试编写一个简单的脚本,它提供基于维基百科的翻译(欢迎任何批评/评论) 问题是:当我从翻译中删除(刷新)时,脚本输出 nil 而不是翻译后的单词。这是为什么?我
我正在开发 iPhone 应用程序并希望使用: CFStreamCreatePairWithSocketToHost(NULL, url, port, &serverReadStream, &serv
我有一个相机将图片发送到回调函数,我想使用 FFmpeg 用这些图片制作一部电影。我遵循了 decoding_encoding 示例 here但我不确定如何使用 got_output 刷新编码器并获取
is_master_def: volatile bool is_master_; is_master_ 值被另一个线程设置为 true,但似乎 is_master_ 值 dosnt 刷新(它没有计算出
什么意思 “我会在您将所有内容发送给客户端并刷新后执行此操作。” 谢谢你 最佳答案 刷新是对数据流进行缓冲时涉及的操作。 让我们假设一个普通的stdout 流。每个字节一到达就打印出来效率很低,这就是
我们正在开发 iMX6Sx Freescale 开发板,使用 Yocto 构建 Linux 内核发行版。我想知道是否有办法检查是否有可能检查文件系统操作(特别是写入)是否真的终止,避免在操作仍在进行时
我已经实现了一个 Java 程序,它通过 ServerSocket 从 GPS 设备读取数据。 ServerSocket serverSocket = new ServerSocket(13811);
我是一名优秀的程序员,十分优秀!