Skip to content

Auto-Integration with Azure Monitor

This document provides an automated approach to integrating Azure Monitor with KloudMate using the OpenTelemetry Receiver. The Azure Monitor OpenTelemetry Receiver allows you to scrape telemetry data from Azure Monitor resources and send them to KloudMate for centralized monitoring and analysis.

Ensure the following prerequisites are met before proceeding:

  • Azure CLI installed on your Linux system.
  • An Azure User with the following roles:
    • User Access Administrator
    • Contributor

During this process, the following resources will be provisioned:

  1. Azure AD Application:
    • A Microsoft Entra ID App with a service principal assigned the Reader role for the specified subscription.
  2. Virtual Machine Configuration:- VM Type: Standard_B2s
    • OS Image: Ubuntu 22.04
    • Disk Size: 30 GB
    • Location: East US

Login to your Azure account using the Azure CLI:

az login

1. Create a file named azure-kloudmate.sh and paste the following content inside it:

vim azure-kloudmate.sh

2. Paste the following script into the file:

#!/bin/bash

# Check if App Name is provided
if [ -z "$1" ] || [ -z "$2" ]; then
    echo "Usage: $0 <App_Name> <Subscription_ID>"
    exit 1
fi

APP_NAME="$1"
ROLE="Reader"

# Get Subscription & Tenant ID
SUBSCRIPTION_ID="$2"
TENANT_ID=$(az account show --query tenantId --output tsv)

# Register an App in Azure AD
echo "Creating Azure AD App: $APP_NAME..."
APP_DETAILS=$(az ad app create --display-name "$APP_NAME" --query "{appId: appId, objectId: id}" --output json)
CLIENT_ID=$(echo "$APP_DETAILS" | grep -o '"appId": "[^"]*' | cut -d'"' -f4)
OBJECT_ID=$(echo "$APP_DETAILS" | grep -o '"id": "[^"]*' | cut -d'"' -f4)

# Create a Client Secret
echo "Creating Client Secret..."
SECRET_DETAILS=$(az ad app credential reset --id "$CLIENT_ID" --query "{password: password}" --output json)
CLIENT_SECRET=$(echo "$SECRET_DETAILS" | grep -o '"password": "[^"]*' | cut -d'"' -f4)

# Create a Service Principal for the App
echo "Creating Service Principal..."
az ad sp create --id "$CLIENT_ID" --output none

# Assign Reader Role to the App
echo "Assigning Reader role to the App..."
az role assignment create --assignee "$CLIENT_ID" --role "$ROLE" --scope "/subscriptions/$SUBSCRIPTION_ID"

# Output the credentials
echo "==========================="
echo "App Registration Completed!"
echo "App Name: $APP_NAME"
echo "Client ID: $CLIENT_ID"
echo "Tenant ID: $TENANT_ID"
echo "Subscription ID: $SUBSCRIPTION_ID"
echo "Client Secret (Save it securely!): $CLIENT_SECRET"
echo "==========================="

read -p "Enter Resource Group Name: " RESOURCE_GROUP
read -p "Enter VM Admin Username: " ADMIN_USER
read -s -p "Enter VM Admin Password: " ADMIN_PASSWORD
read -p "Enter Kloudmate Auth-Key: " AUTH_KEY
echo ""

VM_NAME="otel-vm-demo"
LOCATION="eastus"
IMAGE="Ubuntu2204"
SIZE="Standard_B2s"

CLOUD_INIT_FILE="cloud-init.yaml"

cat <<EOF > "$CLOUD_INIT_FILE"
#cloud-config
package_update: true
package_upgrade: true
runcmd:
  - wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.120.0/otelcol-contrib_0.120.0_linux_amd64.deb
  - sudo dpkg -i otelcol-contrib_0.120.0_linux_amd64.deb
  - sudo systemctl enable otelcol-contrib
  - sudo systemctl start otelcol-contrib
  - echo "Updating OpenTelemetry config..."
  - sudo systemctl restart otelcol-contrib
write_files:
  - path: /etc/otelcol-contrib/otelcol-contrib.conf
    content: |
      OTELCOL_OPTIONS="--config=/etc/otelcol-contrib/config.yaml"
      SUBSCRIPTION_ID=${SUBSCRIPTION_ID}
      TENANT_ID=${TENANT_ID}
      CLIENT_ID=${CLIENT_ID}
      CLIENT_SECRET=${CLIENT_SECRET}
      AUTH_KEY=${AUTH_KEY}

  - path: /etc/otelcol-contrib/config.yaml
    content: |
      extensions:
         health_check:
         pprof:
           endpoint: 0.0.0.0:1777
         zpages:
           endpoint: 0.0.0.0:55679

      receivers:
         otlp:
           protocols:
             grpc:
               endpoint: 0.0.0.0:4317
             http:
               endpoint: 0.0.0.0:4318

         azuremonitor:
           subscription_id: ${SUBSCRIPTION_ID}
           tenant_id: ${TENANT_ID}
           client_id: ${CLIENT_ID}
           client_secret: ${CLIENT_SECRET}
           cloud: AzureCloud
           collection_interval: 60s
           initial_delay: 1s

      processors:
         batch:
           send_batch_size: 10000
           timeout: 30s

      exporters:
         debug:
           verbosity: detailed

         otlphttp:
           endpoint: "https://otel.kloudmate.com:4318"
           headers:
             Authorization: ${AUTH_KEY}  # Replace with your actual KloudMate authentication key

      service:
         pipelines:
           metrics:
             receivers: [otlp, azuremonitor]
             processors: [batch]
             exporters: [debug, otlphttp]

         extensions: [health_check, pprof, zpages]
EOF

echo "Creating Azure VM: $VM_NAME..."

az vm create --resource-group "$RESOURCE_GROUP" --name "$VM_NAME" --image "$IMAGE" --size "$SIZE" --admin-username "$ADMIN_USER" --admin-password "$ADMIN_PASSWORD" --custom-data "$CLOUD_INIT_FILE"

3. Make the script executable and run it:

chmod +x azure-kloudmate.sh

4. Execute the script with the required parameters:

./azure-kloudmate.sh <App_Name> <Subscription_ID>

5. Follow the on-screen instructions to complete the setup.

After completing the setup, follow these steps to confirm that KloudMate is receiving Azure metrics:

  1. Log into your KloudMate account.
  2. Navigate to Explorer or Dashboards.
  3. Filter for Azure-specific metrics.
    • If data is flowing correctly, you should see the metrics appearing in real-time.
  4. Troubleshoot if no data appears:
    • Recheck your Azure Monitor configuration.
    • Ensure the required permissions are set correctly.