Displaying Python Metrics in Azure Application Insights

We can capture Python performance metrics in Azure Application Insights. This will let us see our program performance from anywhere that can reach the Azure console. I've used this to capture a variety of Python data manipulation and process timing without having to stand up any metrics databases or dashboards.

I wanted to plot basic internet performance information from data generated from two different machines in two different locations.  The source code is on GitHub here freemansoft/speedtest-app-insights. That project runs speedtest.net measurements and then posts them to Azure Application Insights.  We can create charts for any of the data gathered as part of this process.

Target Graphic

We want to create a graphical tile that shows our connection ping time broken out per test machine. The program code above posts new ping time data every 5 minutes.  This graphic shows the ping results for the last 4 hours.


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.

Create a dashboard graphic that breaks data per machine

  • Log into the Azure Console 
  • Navigate to Application Insights.
  • Click on the Application Insights resource where we registered the data



  • On the next page scroll down until you find Monitoring/Metrics and select that.
  • Select the same resource name we selected before.
  • Use the Metrics Namespace called Log-based metrics


Pick the metric that we want to chart.  
In this example, we select the  ST Ping Time custom metric created by the speedtest application

Lets assume you have multiple machines running your program. In my case, I had machines running at different locations that all reported to the same dashboard.

  • Select Apply Splitting button right next to add filter button.
  • Select Cloud role instance. That name is bound to a property in every metric. It works even for apps not located in Azure or any cloud when using the Python library.

This picture shows that we have bound a metric into this graph and split along the Cloud role instance attribute.

  • There is a button at the top of the panel, right side of the screen that lets you pin this graphic to dashboard.
  • You have the option of creating a new dashboard or adding to an existing one
I'd recommend making a new dashboard for your project. You can add any number of graphics to it.

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

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

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

Almost PaaS Document Parsing with Tika and AWS Elastic Beanstalk