【问题标题】:display only specific resources by type with kusto in Resource Graph Explorer在资源图资源管理器中使用 kusto 仅按类型显示特定资源
【发布时间】:2021-03-06 05:34:48
【问题描述】:

我在使用 azure kusto 查询显示特定资源时遇到问题。

我想要的是编写一个 kusto 查询,只显示 azure 中的数据库资源和服务器资源。

我写了以下关于数据库的查询:

resources
| where type in ("microsoft.sql/servers/databases","microsoft.dbforpostgresql/servers","microsoft.azuredata/postgresinstances","microsoft.dbformariadb/servers","microsoft.dbformysql/flexibleservers","microsoft.dbformysql/servers","microsoft.dbforpostgresql/flexibleservers","microsoft.dbforpostgresql/servergroups","microsoft.kusto/clusters/databases","microsoft.sql/managedinstances/databases","microsoft.synapse/workspaces/sqldatabases","ravenhq.db/databases","microsoft.documentdb/databaseaccounts")
| summarize Amount=count() by type

但是当我执行查询时,它显示了两个数据库,即使我只创建了一个,额外的一个是“主”,不应该包括在内,因为资源组中只有一个资源

我也尝试过以下查询:

resources
| where type contains "database" | distinct type
| summarize Amount=count() by type

但问题是它不包括类型名称中没有“数据库”一词的所有数据库,例如“microsoft.azuredata/postgresinstances”

所以问题是,我如何编写一个查询来显示我的仪表板上的所有数据库。

问题的第二部分与前面的数据库类似,是我如何显示所有服务器。 我尝试了以下查询:

resources
| where split(type,"/")[array_length(split(type,"/"))] contains "servers"

即使我有服务器,它也没有给我任何结果。 然后我尝试了:

resources
| where type contains "/server" | distinct type
| summarize Amount=count() by type

那没用,因为它还返回了所有限制工作“服务器”的数据库资源

我试图查看微软的文档,但不知道该怎么做。

【问题讨论】:

    标签: azure dashboard azure-data-explorer azure-resource-graph


    【解决方案1】:

    如果您不想要主数据库(即在 SQL 数据库中存储系统级数据的数据库,您可以简单地将它们过滤掉:

    resources
    | where type in ("microsoft.sql/servers/databases","microsoft.dbforpostgresql/servers","microsoft.azuredata/postgresinstances","microsoft.dbformariadb/servers","microsoft.dbformysql/flexibleservers","microsoft.dbformysql/servers","microsoft.dbforpostgresql/flexibleservers","microsoft.dbforpostgresql/servergroups","microsoft.kusto/clusters/databases","microsoft.sql/managedinstances/databases","microsoft.synapse/workspaces/sqldatabases","ravenhq.db/databases","microsoft.documentdb/databaseaccounts")
    | where name type != "microsoft.sql/servers/databases" or name != "master"
    | summarize Amount=count() by type
    

    关于第二个问题,这应该有效,因为 has 运算符将只匹配整个标记(并且斜线分隔标记):

    resources | where type has "servers"
    

    【讨论】:

    • 非常感谢,它与没有显示“主”的数据库一起工作我有一个关于服务器的后续问题,我尝试了resources | where type has "servers",但随后它也显示了“服务器”的数据库" 包含在名称中,我不希望这样,因为我还想过滤掉实际的服务器,您对此有什么想法吗?
    • 你可以像这样添加一个过滤器:resources | where type has "servers" | where type != 'microsoft.sql/servers/databases'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    • 2019-12-05
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    • 2023-03-22
    相关资源
    最近更新 更多