尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

【计算机工具类-监控和日志Skills】azure-mgmt-applicationinsights-dotnet 技能

【计算机工具类-监控和日志Skills】azure-mgmt-applicationinsights-dotnet 技能 Azure Application Insights SDK for .NET. Application performance monitoring and observability resource management.技能概述azure-mgmt-applicationinsights-dotnet 技能用于管理Application Insights资源用于应用程序性能监控。此SDK提供完整的Application Insights资源管理功能包括创建、更新、删除和监控应用程序性能。下载地址agentic-awesome-skills/skills/azure-mgmt-applicationinsights-dotnet at main · sickn33/agentic-awesome-skills · GitHub安装dotnet add package Azure.ResourceManager.ApplicationInsights dotnet add package Azure.Identity当前版本v1.0.0 (GA)API版本2022-06-15环境变量AZURE_SUBSCRIPTION_IDyour-subscription-idAZURE_RESOURCE_GROUPyour-resource-groupAZURE_APPINSIGHTS_NAMEyour-appinsights-component身份验证using Azure.Identity;using Azure.ResourceManager;using Azure.ResourceManager.ApplicationInsights;ArmClient client new ArmClient(new DefaultAzureCredential());资源层次结构Subscription└── ResourceGroup└── ApplicationInsightsComponent # App Insights resource├── ApplicationInsightsComponentApiKey # API keys for programmatic access├── ComponentLinkedStorageAccount # Linked storage for data export└── (via component ID)├── WebTest # Availability tests├── Workbook # Workbooks for analysis├── WorkbookTemplate # Workbook templates└── MyWorkbook # Private workbooks核心工作流1. 创建Application Insights组件基于工作区using Azure.ResourceManager.ApplicationInsights;using Azure.ResourceManager.ApplicationInsights.Models;ResourceGroupResource resourceGroup await client.GetDefaultSubscriptionAsync().Result.GetResourceGroupAsync(my-resource-group);ApplicationInsightsComponentCollection components resourceGroup.GetApplicationInsightsComponents();// Workspace-based Application Insights (recommended)ApplicationInsightsComponentData data new ApplicationInsightsComponentData(AzureLocation.EastUS,ApplicationInsightsApplicationType.Web){Kind web,WorkspaceResourceId new ResourceIdentifier(/subscriptions/sub-id/resourceGroups/rg/providers/Microsoft.OperationalInsights/workspaces/workspace-name),IngestionMode IngestionMode.LogAnalytics,PublicNetworkAccessForIngestion PublicNetworkAccessType.Enabled,PublicNetworkAccessForQuery PublicNetworkAccessType.Enabled,RetentionInDays 90,SamplingPercentage 100,DisableIPMasking false,ImmediatePurgeDataOn30Days false,Tags {{ environment, production },{ application, mywebapp }}};ArmOperationApplicationInsightsComponentResource operation await components.CreateOrUpdateAsync(WaitUntil.Completed, my-appinsights, data);ApplicationInsightsComponentResource component operation.Value;Console.WriteLine($Component created: {component.Data.Name});Console.WriteLine($Instrumentation Key: {component.Data.InstrumentationKey});Console.WriteLine($Connection String: {component.Data.ConnectionString});2. 获取连接字符串和密钥ApplicationInsightsComponentResource component await resourceGroup.GetApplicationInsightsComponentAsync(my-appinsights);// Get connection string for SDK configurationstring connectionString component.Data.ConnectionString;string instrumentationKey component.Data.InstrumentationKey;string appId component.Data.AppId;Console.WriteLine($Connection String: {connectionString});Console.WriteLine($Instrumentation Key: {instrumentationKey});Console.WriteLine($App ID: {appId});3. 创建API密钥ApplicationInsightsComponentResource component await resourceGroup.GetApplicationInsightsComponentAsync(my-appinsights);ApplicationInsightsComponentApiKeyCollection apiKeys component.GetApplicationInsightsComponentApiKeys();// API key for reading telemetryApplicationInsightsApiKeyContent keyContent new ApplicationInsightsApiKeyContent{Name ReadTelemetryKey,LinkedReadProperties {$/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{component.Data.Name}/api,$/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{component.Data.Name}/agentconfig}};ApplicationInsightsComponentApiKeyResource apiKey await apiKeys.CreateOrUpdateAsync(WaitUntil.Completed, keyContent);Console.WriteLine($API Key Name: {apiKey.Data.Name});Console.WriteLine($API Key: {apiKey.Data.ApiKey}); // Only shown once!// 4. 创建Web测试可用性测试WebTestCollection webTests resourceGroup.GetWebTests();// URL Ping TestWebTestData urlPingTest new WebTestData(AzureLocation.EastUS){Kind WebTestKind.Ping,SyntheticMonitorId webtest-ping-myapp,WebTestName Homepage Availability,Description Checks if homepage is available,IsEnabled true,Frequency 300, // 5 minutesTimeout 120, // 2 minutesWebTestKind WebTestKind.Ping,IsRetryEnabled true,Locations {new WebTestGeolocation { WebTestLocationId us-ca-sjc-azr }, // West USnew WebTestGeolocation { WebTestLocationId us-tx-sn1-azr }, // South Central USnew WebTestGeolocation { WebTestLocationId us-il-ch1-azr }, // North Central USnew WebTestGeolocation { WebTestLocationId emea-gb-db3-azr }, // UK Southnew WebTestGeolocation { WebTestLocationId apac-sg-sin-azr } // Southeast Asia},Configuration new WebTestConfiguration{WebTest WebTest NameHomepage EnabledTrue Timeout120 xmlnshttp://microsoft.com/schemas/VisualStudio/TeamTest/2010ItemsRequest MethodGET Version1.1 Urlhttps://myapp.example.com ThinkTime0 Timeout120 ParseDependentRequestsFalse FollowRedirectsTrue RecordResultTrue CacheFalse ResponseTimeGoal0 Encodingutf-8 ExpectedHttpStatusCode200 //Items/WebTest},Tags {{ $hidden-link:/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/my-appinsights, Resource }}};ArmOperationWebTestResource operation await webTests.CreateOrUpdateAsync(WaitUntil.Completed, webtest-homepage, urlPingTest);WebTestResource webTest operation.Value;Console.WriteLine($Web test created: {webTest.Data.Name});核心功能功能描述Application Insights组件管理创建、更新、删除和监控Application Insights资源API密钥管理创建和管理用于编程访问的API密钥Web测试创建可用性测试以监控应用程序可用性工作簿创建和管理用于分析的工作簿链接存储配置数据导出的链接存储账户连接字符串管理获取连接字符串和检测密钥最佳实践使用基于工作区的Application Insights- 推荐用于新的部署安全存储API密钥- API密钥只显示一次配置适当的保留期- 根据需求设置数据保留使用标签组织资源- 为资源添加环境、应用程序等标签配置采样百分比- 根据流量设置适当的采样率启用公共网络访问控制- 根据安全需求配置网络访问定期监控Web测试- 检查可用性测试结果使用DefaultAzureCredential- 用于安全的身份验证配置多个测试位置- 从多个地理位置测试可用性文档化资源- 记录Application Insights配置和用途常见使用场景应用程序性能监控- 监控应用程序性能和可用性故障诊断- 识别和诊断应用程序问题用户行为分析- 分析用户行为和使用模式可用性监控- 通过Web测试监控应用程序可用性自定义指标- 跟踪自定义业务指标依赖跟踪- 监控外部依赖项的性能日志分析- 使用Kusto查询分析日志警报配置- 设置性能和可用性警报
返回列表