首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Azure中收集多个资源的日志记录(VM、SQL数据库、自定义日志记录)-最佳方法?

问如何在Azure中收集多个资源的日志记录(VM、SQL数据库、自定义日志记录)-最佳方法?
EN

Stack Overflow用户
提问于 2019-07-19 22:47:46
回答 2查看 631关注 0票数 0

我在Azure云上启动并运行了多个虚拟机(Citrix工作进程、文件服务器、数据库服务器、数据中心等)在这些citrix工作线程上,我运行了一些应用程序。到目前为止一切顺利,现在我想收集日志记录信息:服务器健康(内存使用、CPU等)、应用程序健康(内存使用应用程序、启动应用程序等)和db监控。我希望将包含历史数据(过去2年,聚合)的PowerBI输出可视化为实时数据(Server1:运行,80%内存使用等)

我正在查看以下设置: Event hubs - Stream Analytics - SQL server - PowerBI。首先,为了服务器的健康,我找到了一个网页,它描述了如何为虚拟机设置诊断设置,但只能通过visual studio,这是不是不可能通过门户(我正在做POC)来完成?其次,我有一个收集应用程序信息的powershell脚本,但是现在,它被写到csv文件中,有谁有使用PowerShell中的core.net对象将指标直接发送到event hub的经验吗?第三个也是最后一个问题,这是可行的方法吗?或者是否有更好的设置来收集这种日志/指标,例如Log Analytics或VM insights (预览) ...

谢谢!

EN

回答 2

Stack Overflow用户

发布于 2019-07-23 19:33:03

欢迎来到Stackoverflow!

Azure Stream Analytics不是从多个Azure资源收集日志的正确选择。

原因:

是一个实时分析和复杂的事件处理引擎,旨在同时分析和处理来自多个源的大量快速流数据。可以在从许多输入源提取的信息中识别模式和关系,这些输入源包括设备、传感器、点击流、社交媒体馈送和应用程序。这些模式可用于触发操作和启动工作流,如创建警报、向报告工具提供信息或存储转换后的数据以供以后使用。此外,流分析在Azure IoT边缘运行时上可用,并支持与云完全相同的语言或语法。

下图显示了如何将数据发送到Stream Analytics,进行分析,并发送用于存储或呈现等其他操作:

​

​

以下场景是可以使用Azure流分析的示例:

  • 分析来自IoT设备的实时遥测数据流
  • 网络日志/点击流vehicles
  • Remote分析用于车队管理,无人驾驶assets
  • Real-time监控和预测性维护针对销售点数据的高价值分析,用于库存控制和异常检测

通过提供全面的解决方案,从您的云和本地环境收集、分析和处理遥测数据,从而最大限度地提高应用程序的可用性和性能。

Azure提供了大量可配置的安全审计和日志记录选项,以帮助您识别安全策略和机制中的漏洞。此article讨论从托管在Azure上的服务生成、收集和分析安全日志。

希望这能有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2019-07-28 21:25:40

即使我同意Pradeep的回答,Azure Stream Analytics也太昂贵了。除非你真的想做一些实时分析。我不建议使用Azure Stream Analytics。

Azure Log Analytics可以很好地满足您的需求,以收集事件日志、性能日志、IIS日志等...我已经看到,你几乎可以在10秒的延迟内收集实时almos。

1)在你所有的虚拟机上(在prems/Azure上无关紧要)安装日志分析MMA代理(https://docs.microsoft.com/en-us/azure/azure-monitor/platform/agent窗口)。

2)配置您要收集的数据(甚至日志、自定义日志、性能计数器、IIS日志等)。

3)数据将立即开始流向您的日志分析实例(20分钟)。

4)您还可以创建告警和监控。

@Jente :通过创建示例表,找到插入数据到日志分析的示例代码。

代码语言:javascript
复制
    # This is the sample code for inserting the data to Log Analytics Table
    # https://docs.microsoft.com/en-us/azure/azure-monitor/platform/data-collector-api reference 

    #Get the maintainence windows and regions

    $CloudName = Read-Host -Prompt 'Insert the cloud Name for Maintainence'
    $starttime = Read-Host -Prompt 'Enter the start time of the maintainence(UTC)'
    $endtime   = Read-Host -Prompt 'Enter the end time of the maintainence(UTC)'


    # Replace with your Workspace ID
    $CustomerId = "XXXXXXXXXXXXXXXX"  

    # Replace with your Primary Key
    $SharedKey = "XXXXXXXXXXXXXXXX"

    # Specify the name of the record type that you'll be creating. You will be seeing the table with the below name
    $LogType = "AZStack_Maintainence_Window"

    # You can use an optional field to specify the timestamp from the data. If the time field is not specified, Azure Monitor assumes the time is the message ingestion time
    $TimeStampField = ""


    $json = @{CloudName=$cloudname;StartTime=$starttime;EndTime=$endtime}
    $json = ConvertTo-Json $json



    # Create two records with the same set of properties to create
    #$json = @
    #[{  "CloudName": $CloudName ,
    #    "Maintainence Start Time": $starttime,
    #    "Maintainence End Time": $endtime    
    #}
    #]
    #"@

    # Create the function to create the authorization signature
    Function Build-Signature ($customerId, $sharedKey, $date, $contentLength, $method, $contentType, $resource)
    {
        $xHeaders = "x-ms-date:" + $date
        $stringToHash = $method + "`n" + $contentLength + "`n" + $contentType + "`n" + $xHeaders + "`n" + $resource

        $bytesToHash = [Text.Encoding]::UTF8.GetBytes($stringToHash)
        $keyBytes = [Convert]::FromBase64String($sharedKey)

        $sha256 = New-Object System.Security.Cryptography.HMACSHA256
        $sha256.Key = $keyBytes
        $calculatedHash = $sha256.ComputeHash($bytesToHash)
        $encodedHash = [Convert]::ToBase64String($calculatedHash)
        $authorization = 'SharedKey {0}:{1}' -f $customerId,$encodedHash
        return $authorization
    }


    # Create the function to create and post the request
    Function Post-LogAnalyticsData($customerId, $sharedKey, $body, $logType)
    {
        $method = "POST"
        $contentType = "application/json"
        $resource = "/api/logs"
        $rfc1123date = [DateTime]::UtcNow.ToString("r")
        $contentLength = $body.Length
        $signature = Build-Signature `
            -customerId $customerId `
            -sharedKey $sharedKey `
            -date $rfc1123date `
            -contentLength $contentLength `
            -method $method `
            -contentType $contentType `
            -resource $resource
        $uri = "https://" + $customerId + ".ods.opinsights.azure.com" + $resource + "?api-version=2016-04-01"

        $headers = @{
            "Authorization" = $signature;
            "Log-Type" = $logType;
            "x-ms-date" = $rfc1123date;
            "time-generated-field" = $TimeStampField;
        }

        $response = Invoke-WebRequest -Uri $uri -Method $method -ContentType $contentType -Headers $headers -Body $body -UseBasicParsing
        return $response.StatusCode

    }


    # Submit the data to the API endpoint
    Post-LogAnalyticsData -customerId $customerId -sharedKey $sharedKey -body ([System.Text.Encoding]::UTF8.GetBytes($json)) -logType $logType

还可以找到将日志分析数据插入到SQL Server数据库的示例代码。同样类型的示例也应该适用于Azure SQL数据库。

代码语言:javascript
复制
# Sample script to insert data to SQL from Log analytics
# it is just sample not for ready use for prod..

function QueryLogAnalytics()
{
write-Host "fetching the data from LA"
$query = "Perf | summarize by ObjectName, CounterName"
$queryResults = Invoke-AzOperationalInsightsQuery -WorkspaceId XXXXXXX  -Query $query
return $queryResults
}

function Login() 
{
$Subscription = 'XXXXXX'
try
{
    Write-Host "Logging into Azure and selecting subscription..."
    if ([string]::IsNullOrEmpty($(Get-AzContext).Account))
    {
        Connect-AzAccount
    }
    else
    {
        Write-Host "Existing Az session detected. Skipping login prompt."
    }

    Select-AzSubscription -Subscription $Subscription -ErrorAction Stop | Out-Null
}
catch
{
    Write-Error "Failed to login to Azure subscription with error $($_.Exception.Message)"
    Exit 1
}

}

#Main .. 

Login
$Results = QueryLogAnalytics | ConvertTo-Json #Converting to Json 
foreach($Result in $Results) 
{ 
Write-Host "Insert Results as Json"

$insertquery= "INSERT INTO [dbo].[Res] VALUES ('$Result')" 

Invoke-SQLcmd -ServerInstance 'ARUNKRALAP' -query $insertquery -Database Results 

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57114876

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档