azure - 是否可以在不接触机器的情况下将 Azure VM 指标流式传输到 eventhub?
问题描述
我目前正在尝试将 Azure Windows VM(如 cpu 等)的指标流式传输到 eventthub。
我在https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-streaming-azure-diags-data下找到了一个教程,但是在本教程中,有必要更改每个的配置系统。由于我们有很多系统,这将意味着很大的不便。我们目前需要的唯一指标是单击 Azure 中的 VM 时显示的指标(CPU 百分比、网络输入/输出、磁盘读取/写入字节、磁盘读取操作)。我们已经设法通过逻辑应用根据这些指标发送警报。
解决方案
是否可以在不接触机器的情况下将 Azure VM 指标流式传输到 eventhub?
是的,我们可以使用Microsoft.Azure.Management.Monitor.Fluent 库t 获取指标。您可以参考这个SO 线程来获取演示代码。我们还可以从Supported metrics with Azure Monitor中获得更多其他受支持的指标名称。
var azureTenantId = "tenant id";
var azureSecretKey = "secret key";
var azureAppId = "client id";
var subscriptionId = "subscription id";
var resourceGroup = "resource group";
var machineName = "machine name";
var serviceCreds = ApplicationTokenProvider.LoginSilentAsync(azureTenantId, azureAppId, azureSecretKey).Result;
MonitorClient monitorClient = new MonitorClient(serviceCreds) { SubscriptionId = subscriptionId };
var resourceUrl = $"subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{machineName}";
var metricNames = "(name.value eq 'Disk Write Operations/Sec' or name.value eq 'Percentage CPU' or name.value eq 'Network In' or name.value eq 'Network Out' or name.value eq 'Disk Read Operations/Sec' or name.value eq 'Disk Read Bytes' or name.value eq 'Disk Write Bytes')";
string timeGrain = " and timeGrain eq duration'PT5M'";
string startDate = " and startTime eq 2017-10-26T05:28:34.919Z";
string endDate = " and endTime eq 2017-10-26T05:33:34.919Z";
var odataFilterMetrics = new ODataQuery<MetricInner>(
$"{metricNames}{timeGrain}{startDate}{endDate}");
var metrics = monitorClient.Metrics.ListWithHttpMessagesAsync(resourceUrl, odataFilterMetrics).Result;
以及如何将消息发送到事件中心,请参阅本教程。
推荐阅读
- javascript - Angular:是否可以使 Angular 指令(例如 NgIf 和 NgFor)仅在我想要的时候检查它们绑定的变量?
- mysql - 错误:在 openstack pike devstack 上创建 VM 实例时未建立 sql_connection 参数
- python - Pyaudio - 我不能录制超过 10 秒。可能是什么问题?
- javascript - IFrame 中的滚动和焦点属性
- javascript - 将 'fs' 设置为空或 false 不会帮助 browserify 中的 browser-pack 在 web 上运行
- tsql - TSQL除法时的小数精度问题
- python - find_peaks 未识别数组开头的峰值
- json - 如何使用 RobotFrameWork 在 json 文件中添加新对象
- javascript - 使用“file-in”和“xml”节点时如何检测文件结尾?
- .net-core - 无法在 EF 核心 3.1 查询中使用 .AddDays