@@ -6,17 +6,15 @@ Usage(){
6
6
echo " Description:"
7
7
echo " Creates Azure Monitor and Grafana resources to house metrics and dashboards"
8
8
echo " Options:"
9
- echo " -v| Azure VM name (required)"
10
9
echo " -g| Azure resource group (required)"
11
10
echo " -m| Azure monitor resource name (default: footprint)"
12
11
echo " -d| Grafana dashboard resource name. Must be globally unique (default: footprint-<random4char>)"
13
12
echo " -c| Azure Arc resource name. Skips extension install for connected cluster if not provided."
13
+ echo " -r| The resource group name of the Azure Arc cluster. (default: same as Azure resource group)."
14
14
}
15
15
16
- while getopts " :v: g:m:d:c:" opt; do
16
+ while getopts " :g:m:d:c:r :" opt; do
17
17
case $opt in
18
- v) vmName=$OPTARG
19
- ;;
20
18
g) resourceGroup=$OPTARG
21
19
;;
22
20
m) monitorName=$OPTARG
@@ -25,6 +23,8 @@ while getopts ":v:g:m:d:c:" opt; do
25
23
;;
26
24
c) clusterName=$OPTARG
27
25
;;
26
+ r) clusterResourceGroup=$OPTARG
27
+ ;;
28
28
\? ) echo " Invalid option -$OPTARG " >&2
29
29
exit 1
30
30
;;
@@ -37,14 +37,15 @@ while getopts ":v:g:m:d:c:" opt; do
37
37
esac
38
38
done
39
39
40
- if [[ $OPTIND -eq 1 || -z $vmName ]]; then
40
+ if [[ $OPTIND -eq 1 ]]; then
41
41
Usage
42
42
exit 1
43
43
fi
44
44
45
45
randoStr=$( tr -dc a-z0-9 < /dev/urandom | head -c 4; echo)
46
46
grafanaName=${grafanaName:- footprint-$randoStr }
47
47
monitorName=" ${monitorName:- footprint} "
48
+ clusterResourceGroup=${clusterResourceGroup:- $resourceGroup }
48
49
49
50
BASEDIR=$( dirname $0 )
50
51
59
60
location=$( az group show -n $resourceGroup --query location -o tsv)
60
61
subscriptionId=$( az account show --query id -o tsv)
61
62
monitor_resource=$( az resource show --resource-type Microsoft.monitor/accounts --name $monitorName --resource-group $resourceGroup 2> /dev/null | jq -c .)
62
- osType=$( az vm show --name $vmName --resource-group $resourceGroup --query ' storageProfile.osDisk.osType' -o tsv)
63
63
64
64
if [ -z $monitor_resource ]; then
65
65
echo " Creating new Azure Monitor workspace..."
79
79
80
80
grafanaIdentity=$( echo $grafana | jq -r ' .identity.principalId' )
81
81
echo " Grafana identity: $grafanaIdentity "
82
- az role assignment create --assignee $grafanaIdentity --role " Monitoring Data Reader" --scope /subscriptions/$subscriptionId
82
+ az role assignment create --assignee $grafanaIdentity --role " Monitoring Data Reader" --scope /subscriptions/$subscriptionId /resourceGroups/ $resourceGroup
83
83
84
84
if [[ -z $( az grafana data-source show -n $grafanaName --data-source " Azure Managed Prometheus-1" 2> /dev/null | jq .name) ]]; then
85
85
echo " Adding prometheus data source to Grafana..."
@@ -110,15 +110,15 @@ if [[ -z $(az grafana dashboard list -n $grafanaName --query "[?title=='$cluste
110
110
--definition $BASEDIR /../monitoring/mem_by_ns.json
111
111
fi
112
112
113
- if [[ -z $clusterName || -z $( az connectedk8s show -n $clusterName -g $resourceGroup 2> /dev/null | jq .name) ]]; then
113
+ if [[ -z $clusterName || -z $( az connectedk8s show -n $clusterName -g $clusterResourceGroup 2> /dev/null | jq .name) ]]; then
114
114
echo " Arc connected cluster not provided or not found. Skipping azmon-extension create."
115
115
else
116
116
echo " Creating k8s-extension azuremonitor-metrics..."
117
117
workspaceId=$( echo $monitor_resource | jq -r .id)
118
- if [[ -z $( az k8s-extension show --resource-group $resourceGroup --cluster-name $clusterName --cluster-type connectedClusters --name azuremonitor-metrics 2> /dev/null | jq .name) ]]; then
118
+ if [[ -z $( az k8s-extension show --resource-group $clusterResourceGroup --cluster-name $clusterName --cluster-type connectedClusters --name azuremonitor-metrics 2> /dev/null | jq .name) ]]; then
119
119
az k8s-extension create --name azuremonitor-metrics \
120
120
--cluster-name $clusterName \
121
- --resource-group $resourceGroup \
121
+ --resource-group $clusterResourceGroup \
122
122
--cluster-type connectedClusters \
123
123
--extension-type Microsoft.AzureMonitor.Containers.Metrics \
124
124
--configuration-settings azure-monitor-workspace-resource-id=$workspaceId
0 commit comments