桌面计算机性能监控系统,监视 Windows 桌面应用的使用情况和性能 - Azure Monitor | Microsoft Docs...

您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

监视经典 Windows 桌面应用中的使用情况和性能

06/11/2020

本文内容

在 Azure 和其他云中本地托管的应用程序都可以利用 Application Insights。 唯一限制是需要允许与 Application Insights 服务通信。 若要监视通用 Windows 平台 (UWP) 应用程序,我们建议使用 Visual Studio App Center。

将遥测从经典 Windows 应用程序发送到 Application Insights

获取检测密钥的副本。

在 Visual Studio 中,编辑应用项目的 NuGet 包,并添加 Microsoft.ApplicationInsights.WindowsServer。 (或者,如果只需要基本 API,而无需标准遥测收集模块,则选择 Microsoft.ApplicationInsights。)

在代码中设置检测密钥:

TelemetryConfiguration.Active.InstrumentationKey = "你的密钥";

或在 ApplicationInsights.config 中设置检测密钥(如果已安装标准遥测包之一):

你的密钥

如果使用 ApplicationInsights.config,请确保它在解决方案资源管理器中的属性设置为“生成操作”=“内容”、“复制到输出目录”=“复制”。

运行应用,并在 Azure 门户中创建的资源中查看遥测。

示例代码

using Microsoft.ApplicationInsights;

public partial class Form1 : Form

{

private TelemetryClient tc = new TelemetryClient();

...

private void Form1_Load(object sender, EventArgs e)

{

// Alternative to setting ikey in config file:

tc.InstrumentationKey = "key copied from portal";

// Set session data:

tc.Context.Session.Id = Guid.NewGuid().ToString();

tc.Context.Device.OperatingSystem = Environment.OSVersion.ToString();

// Log a page view:

tc.TrackPageView("Form1");

...

}

protected override void OnFormClosing(System.Windows.Forms.FormClosingEventArgs e)

{

if (tc != null)

{

tc.Flush(); // only for desktop apps

// Allow time for flushing:

System.Threading.Thread.Sleep(1000);

}

base.OnFormClosing(e);

}

...

替代计算机名称的存储

默认情况下,此 SDK 将收集并存储发出遥测的系统的计算机名称。

计算机名由 Application Insights 旧的企业(按节点)定价层用于内部计费。 默认情况下,如果使用遥测初始值设定项替代 telemetry.Context.Cloud.RoleInstance,则将发送一个单独的属性 ai.internal.nodeName,该属性仍将包含计算机名值。 此值不会与 Application Insights 遥测数据一起存储,而是在内部引入时使用,以允许向后兼容基于旧节点的计费模型。

如果你使用的是旧的企业(按节点)定价层,并且只需要替代计算机名的存储,请使用遥测初始值设定项:

按如下所示编写自定义 TelemetryInitializer。

using Microsoft.ApplicationInsights.Channel;

using Microsoft.ApplicationInsights.Extensibility;

namespace CustomInitializer.Telemetry

{

public class MyTelemetryInitializer : ITelemetryInitializer

{

public void Initialize(ITelemetry telemetry)

{

if (string.IsNullOrEmpty(telemetry.Context.Cloud.RoleInstance))

{

// Set custom role name here. Providing an empty string will result

// in the computer name still be sent via this property.

telemetry.Context.Cloud.RoleInstance = "Custom RoleInstance";

}

}

}

}

在以下设置检测密钥的 Program.cs Main() 方法中实例化初始化程序:

using Microsoft.ApplicationInsights.Extensibility;

using CustomInitializer.Telemetry;

static void Main()

{

TelemetryConfiguration.Active.InstrumentationKey = "{Instrumentation-key-here}";

TelemetryConfiguration.Active.TelemetryInitializers.Add(new MyTelemetryInitializer());

//...

}

替代计算机名的传输

如果你使用的不是旧的企业(按节点)定价层,并且想要完全阻止发送包含计算机名的任何遥测,则需要使用遥测处理器。

遥测处理器

using Microsoft.ApplicationInsights.Channel;

using Microsoft.ApplicationInsights.Extensibility;

namespace WindowsFormsApp2

{

public class CustomTelemetryProcessor : ITelemetryProcessor

{

private readonly ITelemetryProcessor _next;

public CustomTelemetryProcessor(ITelemetryProcessor next)

{

_next = next;

}

public void Process(ITelemetry item)

{

if (item != null)

{

item.Context.Cloud.RoleInstance = string.Empty;

}

_next.Process(item);

}

}

}

在以下设置检测密钥的 Program.cs Main() 方法中实例化遥测处理器:

using Microsoft.ApplicationInsights.Extensibility;

namespace WindowsFormsApp2

{

static class Program

{

static void Main()

{

TelemetryConfiguration.Active.InstrumentationKey = "{Instrumentation-key-here}";

var builder = TelemetryConfiguration.Active.DefaultTelemetrySink.TelemetryProcessorChainBuilder;

builder.Use((next) => new CustomTelemetryProcessor(next));

builder.Build();

//...

}

}

}

备注

尽管技术上你可以使用如上所述的遥测处理器(即使你使用的是旧的企业(按节点)定价层),但这将由于无法针对每个节点定价区分节点而导致超额计费。

后续步骤

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
电子邮件是整个互联网行业重要的组成部分。据统计,四分之三以上的用户上网的主要目的是收发邮件,每天有十数亿封电子邮件在全球传递。电子邮件已成为用户不可或缺的需要。用户对电子邮件安全性、可靠性以及功能上的要求也在不断提高。因此,服务供应商必须提供更安全、更可靠、功能更丰富的服务,才能发展业务、吸引用户,从众多竞争者中脱颖而出。 为了使邮件服务器架构者能够在服务器投入使用前对服务器性能进行必要的测试,确保系统的性能和可靠性能够满足现有状况和预期情况下的使用,以及服务器运行过程中可以随时了解服务器运行的信息。我们构建本系统来针对邮件服务器性能进行监视,本系统提供了以下几种功能:  CPU监视  Memory监视  Disk监视  Network监视  Process监视 此外,本系统预留了很好的可扩展性,为以后监视对象的增加提供了更大的便利。 系统由用户输入start命令来启动,stop命令来停止系统的运行,为此stop进程必须了解start进程中的一些信息,系统中通过使用共享内存来完成这两个进程间的通信,确保程序的正常退出。为与Linux其他服务相统一,系统中还提供了restart(重新启动监视器)命令。系统要求对五个监视对象进行并发监视,多进程概念的引入恰好完成了该功能。另外当系统运行后,为了不挂起终端,我们必须将程序放在后台执行,系统中通过使用守护进程来完成该任务。 下面是本文各章节的一些简要概括:  第一章讲述了本系统的研发背景以及用到的一些技术。  第二章对系统做了一些必要的分析,同时给出系统的用况图和类图。  第三章对本系统的的主体部分进行了详细设计,并针对难点进行了详细的讲解。  第四章分别对以上五种对象的信息收集,包括使用Shell取得相关对象信息、采集我们需要的数据(由第五章描述)以及信息的存储进行了详细设计,并给出了相应的顺序图。  第五章分别对五种对象的信息采集(为信息收集的一部分)进行了详细设计,同时给出各自的顺序图。  第六章讲述了本系统中Makefile文件的编写方法,同时对系统进行了一些必要的测试,并进行了总结。 关键词:邮件服务器性能监视,多进程,守护进程,共享内存,信号量,PRO*C
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值