Azure日志分析.NET SDK中的跨工作区查询 [英] Cross-workspace queries in azure log analytics .NET SDK

查看:55
本文介绍了Azure日志分析.NET SDK中的跨工作区查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用azure日志分析.NET SDK执行一些日志分析查询.

我为此SDK使用的块包是

任何帮助将不胜感激.

解决方案

使用Microsoft.Azure.OperationalInsights.

This allows me to issue some simple queries like in the following code sample :

Authentication & Simple query :

partial class QueryProvider
{

    private OperationalInsightsDataClient _operationalInsightsDataClient;


    private async void Authenticate()
    {

        // Retrieving the credentials and settings data from the app settings .
        var domain = SettingsHelpers.PullSettingsByKey("domain");
        var clientId = SettingsHelpers.PullSettingsByKey("clientId");
        var workspaceId = SettingsHelpers.PullSettingsByKey("workspaceId");

        var authEndpoint = SettingsHelpers.PullSettingsByKey("authEndpoint");
        var clientSecret = SettingsHelpers.PullSettingsByKey("clientSecret");
        var tokenAudience = SettingsHelpers.PullSettingsByKey("tokenAudience");


        // Authenticating to the azure log analytics service .
        var azureActiveDirectorySettings = new ActiveDirectoryServiceSettings
        {
            AuthenticationEndpoint = new Uri(authEndpoint),
            TokenAudience = new Uri(tokenAudience),
            ValidateAuthority = true
        };


        var credentials = await ApplicationTokenProvider.LoginSilentAsync
        (
              domain
            , clientId
            , clientSecret
            , azureActiveDirectorySettings
        );


        _operationalInsightsDataClient = new OperationalInsightsDataClient(credentials);
        _operationalInsightsDataClient.WorkspaceId = workspaceId;

    }


    public async Task<string> LogAnalyticsSamleQuery()
    {

        var query = @"Usage 
                    | where TimeGenerated > ago(3h)
                    | where DataType == 'Perf' 
                    | where QuantityUnit == 'MBytes'
                    | summarize avg(Quantity) by Computer
                    | sort by avg_Quantity desc nulls last";


       var jsonResult = await _operationalInsightsDataClient.QueryAsync(query);

        return JsonConvert.SerializeObject(jsonResult.Results);

    } 
}

Now I want to write a method that runs a cross-workspace query , I get the workspaces Ids dynamically and I want to build o query that references all those workspaces .

I did not find any sample in the doc to build such queries .

I found an attribute of OperationalInsightDataClient class called AdditionalWorkspaces but it's unclear how to use it to achieve the goal .

Any help would be very appreciated .

解决方案

Use the ListWorkspaces method, store workspace Id , CustomerIdor Name in List.

var ws = new List<string>();
foreach (var w in workspaces)
{
     ws.Add(w.Id);
}

AdditionalWorkspaces is used to store workspaces you want to query, but has no influence on the query result.

_operationalInsightsDataClient.AdditionalWorkspaces = ws;

To cross-workspace query, add the list of workspace-Id in the query method.

var jsonResult = await _operationalInsightsDataClient.QueryAsync(query,null, _operationalInsightsDataClient.AdditionalWorkspaces);

这篇关于Azure日志分析.NET SDK中的跨工作区查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆