You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -38,14 +38,14 @@ There are several tables containing various data in Resource Graph.
38
38
You do not have to specify a table. If you don't specify a table, it defaults to the resources table.
39
39
40
40
This query:
41
-
41
+
````kusto
42
42
where type =~ 'microsoft.compute/virtualmachines'
43
-
43
+
````
44
44
and this query
45
-
45
+
````kusto
46
46
resources
47
-
| where type =~ 'micrososft.compute/virtualmachines'
48
-
47
+
| where type =~ 'microsoft.compute/virtualmachines'
48
+
````
49
49
Are the same query and produce the same results. I would consider it a better practice to always declare a table, as there are now other tables to choose from than just the resources table.
50
50
51
51
@@ -68,27 +68,27 @@ Are the same query and produce the same results. I would consider it a better pr
68
68
When querying the resources table, every resource has a resource type, in Azure these are your resource providers.
69
69
70
70
To see all available resource types from existing resources
71
-
71
+
````kusto
72
72
resources
73
73
| distinct type
74
-
74
+
````
75
75
As Azure services have been renamed over the years their provider names have stayed the same. For instance microsoft.compute/operationalinsights/workspaces is the provider name for Log Analytics workspaces.
76
76
77
77
**Notable resource type exceptions:
78
-
Azure Kubernetes Services does not have a resource provider. You'll see AKS under Virtual Machine Scale Sets.
79
-
80
78
Azure Security Center and Azure Sentinel are Solutions installed on top of Log Analytics workspace.
79
+
Unitl recently Azure Kubernetes service did not have a provider you could find in resource graph.
81
80
82
81
To query all virtual machines
83
-
82
+
````kusto
84
83
resources
85
84
| where type =~ 'microsoft.compute/virtualmachines'
86
-
85
+
````
87
86
88
87
To query all Log Analytics workspaces, change the resource type to microsoft.operationalinsights/workspaces
89
-
88
+
````kusto
90
89
resources
91
90
| where type =~ 'microsoft.operationalinsights/workspaces'
91
+
````
92
92
93
93
94
94
@@ -108,15 +108,16 @@ These are the most common operators you need when working with dynamic types.
108
108
- tostring()
109
109
110
110
todynamic and parse_json are synonyms, meaning they perform the exact same funtion. You may see someone use one and someone else use the other, there is no right or wrong way.
111
-
111
+
````kusto
112
112
resources
113
113
| where type =~ 'Microsoft.Network/privateEndpoints'
these two queries will produce exactly the same result. Each will produce a new field called 'nics' with the resource ID of the private endpoint nic inside it.
121
122
122
123
Tolower and tostring are self explanatory, mv-expand expands array objects or dynamic type objects into multiple values.
@@ -128,31 +129,31 @@ Tolower and tostring are self explanatory, mv-expand expands array objects or dy
128
129
The easiest properties to exract are the first layer inside a dynamic object. One of the most common things you may want to extract is the Sku of your resources.
129
130
130
131
For Application Services we'll use `microsoft.web/sites` as our resource type
131
-
132
+
````kusto
132
133
resources
133
-
| where type =~`'microsoft.web/sites'`
134
+
| where type =~ 'microsoft.web/sites'
134
135
| extend sku = properties.sku
135
-
136
+
````
136
137
This query creates replaces the sku field, which is empty for App Services, and populates it with the data from inside the properties field.
137
138
138
139
We can also get the current state of our App Service from under the properties field.
139
-
140
+
````kusto
140
141
resources
141
142
| where type =~ `'microsoft.web/sites'`
142
143
| extend State = properties.state
143
-
144
+
````
144
145
Sometimes we can go two layers deep in a dynamic object without any problems. This example will show you how to get the VM Hardware size of your Azure VMs.
145
-
146
+
````kusto
146
147
resources
147
148
| where type =~ 'microsoft.compute/virtualmachines'
148
149
| extend Size = properties.hardwareProfile.vmSize
149
-
150
+
````
150
151
However when we start digging into dynamic types, what gets returned is also dynamic. Sometimes we'll need to convert these to strings. This is especially important when we start joining different resource types by their resource ID. Often these IDs are underneath the properties field.
151
-
152
+
````kusto
152
153
resources
153
154
| where type =~ 'microsoft.compute/virtualmachines'
adding tostring() around properties.hardwareProfile.vmSize will accomplish this goal.
157
158
158
159
@@ -162,45 +163,148 @@ Once you delve deeper into the dynamic type objects, you'll find there are certa
162
163
163
164
Application Gateways have a front end IP configuration. Within the properties field in Resource Graph the front end configuration is inside brackets with curly braces.
164
165
We can get at the data by using addressing the first element of an array
165
-
166
+
````kusto
166
167
resources
167
168
| where type =~ 'microsoft.network/applicationgateways'
But this is inefficient, what if your data changes per resource type, or you just want all the objects in the array and don't know how many will be in each resource.
171
172
172
173
this is when we'll want to use mv-expand
173
174
175
+
````kusto
174
176
resources
175
177
| where type =~ 'microsoft.network/applicationgateways'
Now, publicIpId is addressable dot notation, or another mv-expand to get at the data we want. To get the resource ID of the public IP of the Application Gateway we can add an extend on to the end of our previous query.
179
181
182
+
````kusto
180
183
resources
181
184
| where type =~ 'microsoft.network/applicationgateways'
Continuing with Application Gateway example, underneath the same frontEndConfig is a second data property inside brackets. The http listener. To get the resource ID of the http listener we need to do a second mv-expand.
186
190
191
+
````kusto
192
+
187
193
resources
188
194
| where type =~ 'microsoft.network/applicationgateways'
These practical examples will show real world scenarios you want to use Resource Graph for. Many of them will require joins. Remember that we can only do 3 joins in Resource Graph. Additionally `join kind=leftouter` is the most common join type you'll want to use. Because you cannot assume that just becasue a VM exists that it has a OS disk, or that a disk exists it has a VM it belongs to. Using `leftouter` will allow you to join resources without eliminating resources by using inner unique joins.
212
+
213
+
Summarize count VMs by their VM Size.
214
+
215
+
````Kusto
216
+
Resources
217
+
| where type == "microsoft.compute/virtualmachines"
218
+
| summarize Count=count() by vmSize=tostring(properties.hardwareProfile.vmSize)
219
+
````
220
+
Summarize count VMs by their State
221
+
````Kusto
222
+
Resources
223
+
| where type == "microsoft.compute/virtualmachines"
0 commit comments