-
Notifications
You must be signed in to change notification settings - Fork 24
/
monitoring.bicep
143 lines (131 loc) · 4 KB
/
monitoring.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
param grafanaName string
param workspaceAzureMonitorName string
param workspaceLogAnalyticsName string
param location string
param grafanaAdminObjectId string
@description('ObjectID for an user in AAD you want to grant grafana admin rights. Default is to not provide anything: not grant this permission any individual')
param userGrafanaAdminObjectId string = ''
param dceName string
param dcrName string
param clusterName string
resource workspaceLogAnalytics 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
name: workspaceLogAnalyticsName
location: location
}
resource workspaceAzureMonitor 'microsoft.monitor/accounts@2021-06-03-preview' = {
name: workspaceAzureMonitorName
location: location
}
var azureMonitorWorkspaceResourceId = '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/microsoft.monitor/accounts/${workspaceAzureMonitorName}'
resource grafana 'Microsoft.Dashboard/grafana@2022-08-01' = {
name: grafanaName
location: location
properties: {
grafanaIntegrations: {
azureMonitorWorkspaceIntegrations: [
{
azureMonitorWorkspaceResourceId: azureMonitorWorkspaceResourceId
}
]
}
}
identity: {
type: 'SystemAssigned'
}
sku: {
name: 'Standard'
}
dependsOn: [
workspaceAzureMonitor
]
}
resource grafanaRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
name: '22926164-76b3-42b3-bc55-97df8dab3e41'
scope: subscription()
}
resource amwRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
name: 'b0d8363b-8ddd-447d-831f-62ca05bff136'
scope: subscription()
}
// Add user's as Grafana Admin for the Grafana instance
resource managedRoleAssignmentGrafana 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(resourceGroup().id, grafanaAdminObjectId, 'grafana_role')
scope: grafana
properties: {
roleDefinitionId: grafanaRole.id
principalId: grafanaAdminObjectId
}
}
resource userRoleAssignmentGrafana 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (userGrafanaAdminObjectId != '') {
name: guid(resourceGroup().id, userGrafanaAdminObjectId, 'grafana_role')
scope: grafana
properties: {
roleDefinitionId: grafanaRole.id
principalId: userGrafanaAdminObjectId
}
}
// Provide Grafana access to the AMW instance
resource roleAssignmentLocal 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(resourceGroup().id, grafanaAdminObjectId, 'amw_role')
properties: {
roleDefinitionId: amwRole.id
principalId: grafana.identity.principalId
}
}
resource dce 'Microsoft.Insights/dataCollectionEndpoints@2022-06-01' = {
name: dceName
location: location
kind: 'Linux'
properties: {
}
}
resource dcr 'Microsoft.Insights/dataCollectionRules@2022-06-01' = {
name: dcrName
location: location
kind: 'Linux'
properties: {
dataCollectionEndpointId: dce.id
dataFlows: [
{
destinations: [
'MonitoringAccount1'
]
streams: [
'Microsoft-PrometheusMetrics'
]
}
]
dataSources: {
prometheusForwarder: [
{
name: 'PrometheusDataSource'
streams: [
'Microsoft-PrometheusMetrics'
]
labelIncludeFilter: {
}
}
]
}
description: 'DCR for Azure Monitor Metrics Profile (Managed Prometheus)'
destinations: {
monitoringAccounts: [
{
accountResourceId: azureMonitorWorkspaceResourceId
name: 'MonitoringAccount1'
}
]
}
}
dependsOn: [
workspaceAzureMonitor
]
}
resource variables_clusterName_microsoft_insights_variables_dcra 'Microsoft.ContainerService/managedClusters/providers/dataCollectionRuleAssociations@2022-06-01' = {
name: '${clusterName}/microsoft.insights/${dcrName}'
location: location
properties: {
description: 'Association of data collection rule. Deleting this association will break the data collection for this AKS Cluster.'
dataCollectionRuleId: dcr.id
}
}