Day 44: Integrating Azure Event Hub with Virtual Machines -Event Hub Metrics Verification Failed - xfusion Task

Hi Team / Instructors,

I completed the Azure Event Hub integration task on xfusion-vm, but the automated evaluation failed with the following error message:

"Failed to fetch metrics for the Event Hub after multiple attempts."

Below are all the step-by-step details, commands, and code edits performed during the task for your review.


1. Task Environment Details

  • Resource Group: kml_rg_main-0138fa1c61a140fe
  • Region: eastus
  • Event Hubs Namespace: xfusion-namespace
  • Event Hub: xfusion-hub
  • Virtual Machine: xfusion-vm (172.191.49.34)
  • Script Location: /home/azureuser/send_logs.py

2. Setup Steps Completed via Azure CLI

Step A: Created Namespace & Event Hub

# 1. Created Event Hubs Namespace (Standard SKU with Auto-inflate enabled)
az eventhubs namespace create \
  --name xfusion-namespace \
  --resource-group kml_rg_main-0138fa1c61a140fe \
  --location eastus \
  --sku Standard \
  --enable-auto-inflate true \
  --maximum-throughput-units 2

# 2. Created Event Hub inside namespace
az eventhubs eventhub create \
  --name xfusion-hub \
  --namespace-name xfusion-namespace \
  --resource-group kml_rg_main-0138fa1c61a140fe

Step B: Extracted Connection String

EH_CONN_STRING=$(az eventhubs namespace authorization-rule keys list \
  --resource-group kml_rg_main-0138fa1c61a140fe \
  --namespace-name xfusion-namespace \
  --name RootManageSharedAccessKey \
  --query primaryConnectionString -o tsv)


3. Virtual Machine Configuration & Script Troubleshooting

  1. SSH into VM:
ssh azureuser@172.191.49.34

  1. Initial Execution & Error:
    When running python3 /home/azureuser/send_logs.py, it threw:
ValueError: Connection string is either blank or malformed.

  1. Script Modification via Nano:
    Opened the file:
nano /home/azureuser/send_logs.py

Updated variables to:

CONNECTION_STR = "Endpoint=sb://xfusion-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=6W2Qr3zT0ikHQAyoK0GqUwCm+RXgtnqfr+AEhBM0u8w="
EVENTHUB_NAME = "xfusion-hub"

producer = EventHubProducerClient.from_connection_string(
    conn_str=CONNECTION_STR, 
    eventhub_name=EVENTHUB_NAME
)

Saved and exited (Ctrl+OEnterCtrl+X).
4. Successful Log Generation:
Ran the script multiple times without any errors:

python3 /home/azureuser/send_logs.py
python3 /home/azureuser/send_logs.py
python3 /home/azureuser/send_logs.py


4. Reason for Appeal

The script ran cleanly and sent log events directly to xfusion-hub. I believe the automated checker failed because Azure Monitor metrics experienced a standard 5 to 15 minute delay before registering Incoming Messages / Incoming Bytes via the Azure Metrics API.

Could an instructor please review my submission and logs?

I used a modified version of your script, and the lab worked for me. Not sure what happened when you did it. What was the error you got at grading time?

For the record, your modified script:

export RG=kml_rg_main-75bf9dc7794c487d
export PREFIX=devops

# 1. Created Event Hubs Namespace (Standard SKU with Auto-inflate enabled)
az eventhubs namespace create \
  --name ${PREFIX}-namespace \
  --resource-group $RG \
  --location eastus \
  --sku Standard \
  --enable-auto-inflate true \
  --maximum-throughput-units 2

# 2. Created Event Hub inside namespace
az eventhubs eventhub create \
  --name ${PREFIX}-hub \
  --namespace-name ${PREFIX}-namespace \
  --resource-group $RG


export EH_CONN_STRING=$(az eventhubs namespace authorization-rule keys list \
  --resource-group $RG \
  --namespace-name ${PREFIX}-namespace \
  --name RootManageSharedAccessKey \
  --query primaryConnectionString -o tsv)


Hi @rob_kodekloud ,

Thanks for testing this out!

The exact error I received at grading time was:

("Failed to fetch metrics for the Event Hub after multiple attempts.")

Since my commands and script execution succeeded without throwing any errors on the VM, it looks like it was purely a timing/metric aggregation delay on Azure’s side when the evaluation script queried the Azure Metrics API.

Good to know the script/commands were correct! I’ll make sure to execute the script as early as possible during the lab next time so Azure Monitor has enough time to reflect the incoming metrics before I submit.

Thanks again for your help!