Skip to content

Commit 42f6475

Browse files
authored
Make configure-azmon-grafana.sh can be run standalone (#6)
1 parent 96e83c7 commit 42f6475

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

.github/workflows/build-monitoring.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ jobs:
4646
- name: Create Azure Monitor and Grafana resources
4747
run: bash ${GITHUB_WORKSPACE}/scripts/configure-azmon-grafana.sh -v $vmName -g $resourceGroup -m $monitorName -d $grafanaName -c $clusterName
4848
- name: Configure hostmemusage collection
49-
run: bash ${GITHUB_WORKSPACE}/scripts/configure-vm-hostmemusage-collector.sh -g $resourceGroup -v $vmName -l $logAnalytics -m $monitorName
49+
run: bash ${GITHUB_WORKSPACE}/scripts/configure-vm-hostmemusage-collector.sh -g $resourceGroup -l $logAnalytics -m $monitorName

scripts/configure-azmon-grafana.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ Usage(){
66
echo "Description:"
77
echo " Creates Azure Monitor and Grafana resources to house metrics and dashboards"
88
echo "Options:"
9-
echo " -v| Azure VM name (required)"
109
echo " -g| Azure resource group (required)"
1110
echo " -m| Azure monitor resource name (default: footprint)"
1211
echo " -d| Grafana dashboard resource name. Must be globally unique (default: footprint-<random4char>)"
1312
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)."
1414
}
1515

16-
while getopts ":v:g:m:d:c:" opt; do
16+
while getopts ":g:m:d:c:r:" opt; do
1717
case $opt in
18-
v) vmName=$OPTARG
19-
;;
2018
g) resourceGroup=$OPTARG
2119
;;
2220
m) monitorName=$OPTARG
@@ -25,6 +23,8 @@ while getopts ":v:g:m:d:c:" opt; do
2523
;;
2624
c) clusterName=$OPTARG
2725
;;
26+
r) clusterResourceGroup=$OPTARG
27+
;;
2828
\?) echo "Invalid option -$OPTARG" >&2
2929
exit 1
3030
;;
@@ -37,14 +37,15 @@ while getopts ":v:g:m:d:c:" opt; do
3737
esac
3838
done
3939

40-
if [[ $OPTIND -eq 1 || -z $vmName ]]; then
40+
if [[ $OPTIND -eq 1 ]]; then
4141
Usage
4242
exit 1
4343
fi
4444

4545
randoStr=$(tr -dc a-z0-9 </dev/urandom | head -c 4; echo)
4646
grafanaName=${grafanaName:-footprint-$randoStr}
4747
monitorName="${monitorName:-footprint}"
48+
clusterResourceGroup=${clusterResourceGroup:-$resourceGroup}
4849

4950
BASEDIR=$(dirname $0)
5051

@@ -59,7 +60,6 @@ fi
5960
location=$(az group show -n $resourceGroup --query location -o tsv)
6061
subscriptionId=$(az account show --query id -o tsv)
6162
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)
6363

6464
if [ -z $monitor_resource ]; then
6565
echo "Creating new Azure Monitor workspace..."
@@ -79,7 +79,7 @@ fi
7979

8080
grafanaIdentity=$(echo $grafana | jq -r '.identity.principalId')
8181
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
8383

8484
if [[ -z $(az grafana data-source show -n $grafanaName --data-source "Azure Managed Prometheus-1" 2>/dev/null | jq .name) ]]; then
8585
echo "Adding prometheus data source to Grafana..."
@@ -110,15 +110,15 @@ if [[ -z $(az grafana dashboard list -n $grafanaName --query "[?title=='$cluste
110110
--definition $BASEDIR/../monitoring/mem_by_ns.json
111111
fi
112112

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
114114
echo "Arc connected cluster not provided or not found. Skipping azmon-extension create."
115115
else
116116
echo "Creating k8s-extension azuremonitor-metrics..."
117117
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
119119
az k8s-extension create --name azuremonitor-metrics \
120120
--cluster-name $clusterName \
121-
--resource-group $resourceGroup \
121+
--resource-group $clusterResourceGroup \
122122
--cluster-type connectedClusters \
123123
--extension-type Microsoft.AzureMonitor.Containers.Metrics \
124124
--configuration-settings azure-monitor-workspace-resource-id=$workspaceId

0 commit comments

Comments
 (0)