How to use Python code to obtain monitoring indicator values of Azure Redis
Problem Description
Through the Metrics monitoring page, we can know the running status and various indicators of the current resources (such as Redis). What if we need to download indicators locally or generate JSON data and import it to a third-party monitoring platform? Can Azure export various indicator data through Python code or Powershell script?
Solution
Yes! PowerShell command can use Get-AzMetric or az monitor metrics list command to obtain the Metrics value of the resource.
Get-AzMetric:Gets the metric values of a resource. https://docs.microsoft.com/en-us/powershell/module /az.monitor/get-azmetric?view=azps-5.4.0&viewFallbackFrom=azps-5.2.0
## az monitor metrics list: List the metric values for a resource. https://docs.microsoft.com/en-us/cli/azure/monitor/metrics?view=azure-cli-latest#az_monitor_metrics_list
And Using Python code, you can use Metrics' REST API to implement
Metrics – List: Lists the metric values for a resource. https://docs .microsoft.com/en-us/rest/api/monitor/metrics/list
- Register the application in AAD to obtain the Access Token for accessing Redis Metrics in Python code: (Apply The program is registered to the Microsoft identity platform: https://docs.azure.cn/zh-cn/active-directory/develop/quickstart-register-app)
Note: You must first log in to Azure to use Powershell. Use the command Connect-AzAccount -Environment AzureChinaCloud or az cloud set –name AzureChinaCloud and az login.
To use Python code, you need to first obtain the Token to access Redis Metrics. To obtain the Token, you can register an application in Azure AD, and then give the application the reader permission in Redis access control to read Metris data.
Execution stepsPythonStep 1: Register AAD application, copy application ID, client access password- Log in to the Azure platform, enter the AAD page, click
App registrations: https://portal.azure.cn/?l=en.en-us#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps
- Click the "
New Registration" button, enter the application name, leave other values as default, click Save
- After the creation is successful, enter the application page , import it to the "
Certificates & secrets" page, create the Client Secret you need to use and copy it. In the third step, you need to use
- to copy the ## on the application page. #Tenant ID, Applicaiton ID
needs to be used in the third step of the code
Step 2: Grant permission to obtain Metrics
In the Access control (IAM) page of Redis, search through the application name in step 1 and grant permission to Monitoring Reader
Note: If permission is not granted, a similar error will be reported in the code:
The above is the detailed content of How to use Python code to obtain monitoring indicator values of Azure Redis. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The correct way to implement efficient key-value pair storage in Go language How to achieve the best performance when developing key-value pair memory similar to Redis in Go language...

go...

Two solutions for data consistency between MySQL and Redis: delayed double deletion and first modifying the database and then deleting cache are used to handle data consistency problems in MySQL and Redis, ...

Modifying XML content requires programming, because it requires accurate finding of the target nodes to add, delete, modify and check. The programming language has corresponding libraries to process XML and provides APIs to perform safe, efficient and controllable operations like operating databases.

Issues of defining string constant enumeration in protobuf When using protobuf, you often encounter situations where you need to associate the enum type with string constants...

In Go language, how to achieve efficient key-value pair memory is a question worth discussing. Many developers may think of using maps to implement this...

For small XML files, you can directly replace the annotation content with a text editor; for large files, it is recommended to use the XML parser to modify it to ensure efficiency and accuracy. Be careful when deleting XML comments, keeping comments usually helps code understanding and maintenance. Advanced tips provide Python sample code to modify comments using XML parser, but the specific implementation needs to be adjusted according to the XML library used. Pay attention to encoding issues when modifying XML files. It is recommended to use UTF-8 encoding and specify the encoding format.

Modifying XML with SAX is an event-based strategy involving the following steps: Read XML content and listen for element events. Determine whether the element needs to be modified. Modify in text events. Write the modified content in the end element event.
