gpt4 book ai didi

azure - 有没有办法指定目标日志文件供微软监控代理监听并从代码中获取日志?

转载 作者:行者123 更新时间:2023-12-03 05:41:30 35 4
gpt4 key购买 nike

我正在考虑使用 Microsoft 监控代理从系统上的日志文件中收集一些日志记录并将其发送到日志分析工作区。有没有一种方法可以指定代理将监听的目标文件(自定义日志文件)并将日志直接流式传输到 azure 工作区。我知道可以通过 azure 门户通过在工作区中添加额外的数据源(如此链接 https://learn.microsoft.com/en-us/azure/azure-monitor/platform/data-sources-custom-logs 指定)来完成。我正在寻找一种从 C# 代码/powershell 脚本配置这些数据源的方法。(可能是我不知道的 api 或 sdk)。

最佳答案

添加自定义日志使用 New-AzOperationalInsightsCustomLogDataSource。

这里是其他 powershell commandlet,可以方便地查询和创建 LogAnalytics 数据源。

get-azoperationalinsightsdatasource
New-AzOperationalInsightsApplicationInsightsDataSource
New-AzOperationalInsightsAzureActivityLogDataSource
New-AzOperationalInsightsComputerGroup
New-AzOperationalInsightsCustomLogDataSource
New-AzOperationalInsightsLinuxPerformanceObjectDataSource
New-AzOperationalInsightsLinuxSyslogDataSource
New-AzOperationalInsightsSavedSearch
New-AzOperationalInsightsStorageInsight
New-AzOperationalInsightsWindowsEventDataSource
New-AzOperationalInsightsWindowsPerformanceCounterDataSource

https://learn.microsoft.com/en-us/powershell/module/az.operationalinsights/get-azoperationalinsightsdatasource?view=azps-2.7.0

还可以找到日志分析 Rest API 的链接,该 API 可以轻松地与 C# 代码一起使用。

https://learn.microsoft.com/en-us/rest/api/loganalytics/ https://learn.microsoft.com/en-us/rest/api/loganalytics/datasources/createorupdate

Powershell

要收集的自定义日志

链接:https://learn.microsoft.com/en-us/azure/azure-monitor/platform/powershell-workspace-configuration

$CustomLog = @"
{
"customLogName": "sampleCustomLog1",
"description": "Example custom log datasource",
"inputs": [
{
"location": {
"fileSystemLocations": {
"windowsFileTypeLogPaths": [ "e:\\iis5\\*.log" ],
"linuxFileTypeLogPaths": [ "/var/logs" ]
}
},
"recordDelimiter": {
"regexDelimiter": {
"pattern": "\\n",
"matchIndex": 0,
"matchIndexSpecified": true,
"numberedGroup": null
}
}
}
],
"extractions": [
{
"extractionName": "TimeGenerated",
"extractionType": "DateTime",
"extractionProperties": {
"dateTimeExtraction": {
"regex": null,
"joinStringRegex": null
}
}
}
]
}
"@




# Custom Logs

New-AzOperationalInsightsCustomLogDataSource -ResourceGroupName $ResourceGroup -WorkspaceName $WorkspaceName -CustomLogRawJson "$CustomLog" -Name "Example Custom Log Collection"
  • ARM 模板

对于 Arm 模板,自定义日志的格式如下。详细链接见https://learn.microsoft.com/en-us/azure/azure-monitor/platform/template-workspace-configuration


{
"apiVersion": "2015-11-01-preview",
"type": "dataSources",
"name": "[concat(parameters('workspaceName'), parameters('customlogName'))]",
"dependsOn": [
"[concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]"
],
"kind": "CustomLog",
"properties": {
"customLogName": "[parameters('customlogName')]",
"description": "this is a description",
"extractions": [
{
"extractionName": "TimeGenerated",
"extractionProperties": {
"dateTimeExtraction": {
"regex": [
{
"matchIndex": 0,
"numberdGroup": null,
"pattern": "((\\d{2})|(\\d{4}))-([0-1]\\d)-(([0-3]\\d)|(\\d))\\s((\\d)|([0-1]\\d)|(2[0-4])):[0-5][0-9]:[0-5][0-9]"
}
]
}
},
"extractionType": "DateTime"
}
],
"inputs": [
{
"location": {
"fileSystemLocations": {
"linuxFileTypeLogPaths": null,
"windowsFileTypeLogPaths": [
"[concat('c:\\Windows\\Logs\\',parameters('customlogName'))]"
]
}
},
"recordDelimiter": {
"regexDelimiter": {
"matchIndex": 0,
"numberdGroup": null,
"pattern": "(^.*((\\d{2})|(\\d{4}))-([0-1]\\d)-(([0-3]\\d)|(\\d))\\s((\\d)|([0-1]\\d)|(2[0-4])):[0-5][0-9]:[0-5][0-9].*$)"
}
}
}
]
}
}

关于azure - 有没有办法指定目标日志文件供微软监控代理监听并从代码中获取日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58338588/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com