How can I enable edgehub_messages_sent_total in Metrics Collector to detect offline IoT Edge devices?

Levin Schickle 0 Reputation points
2025-12-01T14:07:08.21+00:00

When I use Log Analytics to retrieve offline devices from my IoT Hub via the Metrics Collector, the default query for “device offline or not sending messages” returns no results. It seems that no entries for edgehub_messages_sent_total are being collected.

How can I configure the Metrics Collector so that this parameter becomes available, allowing me to identify offline IoT Edge devices?

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2025-12-01T14:07:21.2133333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To enable the edgehub_messages_sent_total metric in the Metrics Collector for detecting offline IoT Edge devices, you need to ensure that the Metrics Collector module is properly configured to collect and transport metrics from your IoT Edge devices to Azure Monitor. Here are the steps you should follow:

    1. Deploy the Metrics Collector Module: Make sure that the metrics-collector module is included in your IoT Edge deployment. This module is responsible for collecting metrics from other modules, including the edgehub module.
    2. Configure the Metrics Collector: In the configuration of the metrics-collector module, you need to set the appropriate environment variables. Ensure that the ResourceId is set to your IoT hub resource ID, and the UploadTarget is set to AzureMonitor. This configuration allows the metrics to be sent to Azure Monitor.
    3. Check the Route Configuration: Ensure that the metrics are routed correctly. If you want to send metrics to Log Analytics, you may not need to set up a specific route to upstream, but ensure that the metrics collector is configured to send data to the correct Log Analytics workspace.
    4. Review Query in Log Analytics: Once the metrics are being collected, you can use Log Analytics to query for the edgehub_messages_sent_total metric. You might need to adjust your query to ensure it captures the relevant data points for offline devices. The default query for detecting offline devices may need to be modified to include checks for the absence of messages sent.
    5. Monitor the Metrics: After making these configurations, monitor the metrics in Azure Monitor to ensure that edgehub_messages_sent_total is being populated. It may take some time for the data to appear after the configurations are applied.

    By ensuring that the metrics collector is properly set up and configured, you should be able to detect offline IoT Edge devices using the edgehub_messages_sent_total metric.


    References:

    0 comments No comments

  2. Anshika Varshney 3,795 Reputation points Microsoft External Staff Moderator
    2025-12-02T16:08:56.86+00:00

    Hi Levin Schickle,

    Thanks for raising the question about enabling EdgeHub “messages sent total” metrics so that you can detect offline IoT Edge devices. Here’s what you can do to configure the Metrics Collector properly:

    Verify Port Mapping: Ensure that your EdgeHub container's configuration exposes port 9600. This can be done by adding a port mapping in the createOptions. For example:

    "createOptions": { "HostConfig": { "PortBindings": { "9600/tcp": [{ "HostPort": "9601" }] } }

    **Configure the Metrics Collector**: To route metrics to IoT Hub or Log Analytics, configure the Metrics Collector module to send metrics as device-to-cloud (D2C) messages. You can do this by setting the `UploadTarget` environment variable to `IoTMessage` in the collector's configuration. Make sure to include a route in your module configuration, such as:
    
    
    ```dockerfile
    FROM /messages/modules/replace-with-collector-module-name/* INTO $upstream
    
    

    Ensure Compatibility: Double-check that you’re running compatible versions of the Metrics Collector and the IoT Edge runtime. If they don't match, consider upgrading.

    Access Metrics: After you've set up your configurations correctly, you should be able to access metrics at http://edgeHub:9600/metrics, including the edgehub_messages_sent_total.

    References:

    Please let me know if there are any remaining questions or additional details, I can help with, I’ll be glad to provide further clarification or guidance.

    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    Thankyou!

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.