Querying Python Metrics as customMetrics and custom attributes as customDimensions in Azure Application Insight

Azure Application Insights can be a collection point for Python Metrics that you can query and filter against.  We can send Open Census metrics from anywhere in the world into Azure Application Insights. This lets us see our program metrics from any browser that can reach the Azure console.  Application Monitor gives us a zero admin performance console.

OpenCensus metrics are recorded in Application Insights as customMetrics. Every metric sent is a row in Application Insights. The Azure OpenCensus Azure Exporter adds a standard set of attributes that appear in App Insights as CustomDimensions.  We can add additional custom dimensions (attributes) to any metrics record sent Azure Application Insights.

All metrics are actually captured in a customMetrics table that we can query against.

Execution pre-requisites

  1. You have an Azure login
  2. You have created an Azure Application Insights Application key https://docs.microsoft.com/en-us/azure/azure-monitor/app/create-new-resource
  3. You have pushed data to Application Insights.  I used https://github.com/freemansoft/speedtest-app-insights

Video walkthrough

Data Capture Notes

Our test program generates custom metrics which we can see in the Metrics section as aggregates and in the Logs section as individual events. Metrics, Tracing, and Logs are all captured in the form of individual events in the Logs section of Application Insights.

Querying Metrics in the Application Insights Logs

  • Log in to the Azure portal 
  • Open up the Application Insights  resource that contains your data
  • Scroll down the left-hand side until you find Monitoring / Logs

  • Close the sample query pane on the right
  • You should end up with a query screen that was behind the overlay pane.


    • Type customMetrics into the query field and delete any extra terms that may have been added.
    • Set the time window for your query in the dropdown on the right.
    • Press on the Run button.
    • You should see a list of individual events.

    You may not see a custom dimensions column in the result table.  

    Do the following if there is no custom dimensions column
    • Click on the Columns drop list and scroll until you see custom dimensions in the list item.
    • Select that column.
    • The column will appear in future queries.

    All of the values in the customDimensions field are stored in a single JSON string.  You can see here how two custom speedtest tags were stored in Azure Application Insights as a JSON blob in the cusomDimensions field.

    References

    Python Metrics and logs in Azure Applications Insights
    • https://joe.blog.freemansoft.com/2022/11/querying-python-transactions-and-spans.html
    • https://joe.blog.freemansoft.com/2021/03/querying-python-logs-azure-application.html
    • https://joe.blog.freemansoft.com/2021/03/querying-python-metrics-custom-tags-as.html
    • https://joe.blog.freemansoft.com/2021/03/displaying-python-metrics-in-azure.html
    • https://joe.blog.freemansoft.com/2021/03/monitor-internet-broadband-service-with.html
    Microsoft Guides
    • https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python
    • https://docs.microsoft.com/en-us/azure/azure-monitor/app/create-new-resource
    • https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-azure
    Python Data generator 
    • https://github.com/freemansoft/speedtest-app-insights
    Created 3/2021

    Comments

    Popular posts from this blog

    Understanding your WSL2 RAM and swap - Changing the default 50%-25%

    Installing the RNDIS driver on Windows 11 to use USB Raspberry Pi as network attached

    DNS for Azure Point to Site (P2S) VPN - getting the internal IPs