首页 > 其他分享 >Azure REST API (6) Azure Monitor Metric Exporter

Azure REST API (6) Azure Monitor Metric Exporter

时间:2024-12-27 20:08:48浏览次数:5  
标签:Exporter Monitor metric metrics azure 91c7 Azure name

  《Windows Azure Platform 系列文章目录

 

  一.用户现状及需求

  1.客户团队使用Prometheus Cloud Watch Exporter,把AWS监控指标,与Prometheus整合:

  https://github.com/prometheus/cloudwatch_exporter

  客户团队希望微软云Azure也提供类似的Exporter功能,能把Azure的监控指标(虚拟机、Redis PaaS等,MySQL PaaS数据等),与Prometheus整合

 

  二.说明

  微软目前没有官方提供的Exporter功能,但是查询到第三方开源的解决方案:
  https://github.com/webdevops/azure-metrics-exporter

 

  三.技术实现

  该方案通过基于Azure SDK for Go,实现Azure Monitor Metric Exporter功能

 

  四.实现关键步骤

  1.创建和使用Azure订阅,步骤略

  2.创建Service Principal,并赋权的权限为订阅的Reader。具体步骤略。

  3.安装Azure虚拟机,我们这里以CentOS 7.9为例,具体步骤略

  4.设置环境变量

vi ~/.bashrc

  5.设置Service Principal相关信息

#App ID
export AZURE_CLIENT_ID=XXXXXXXX

#租户ID
export AZURE_TENANT_ID=XXXXXXXX

#App Key
export AZURE_CLIENT_SECRET=XXXXXXXX

  6.设置环境变量生效

source ~/.bashrc

 

  五.安装Prometheus

  1.我这里使用Prometheus 2.50.1,具体安装步骤略

  2.下载与运行Azure Monitor Metric Exporter项目,项目文件在:https://github.com/webdevops/azure-metrics-exporter/releases

  3.我们先下载24.2.0版本:   https://github.com/webdevops/azure-metrics-exporter/releases/download/24.2.0/azure-metrics-exporter.linux.amd64

  4.下载后运行

nohup ./azure-metrics-exporter.linux.amd64 &

  

  六.配置Prometheus yml文件for Azure Storage

  我们编辑prometheus.yml文件,增加下面的内容
  1. job_name,设置job名称
  2. 下面的第7行,是我的订阅ID。请PE团队按照实际情况修改
  3. 下面的第11行,是指标名称。我们这里查询的是BlobCapacity,存储容量大小
  4. 请注意下图使用的端口号,在第21行,为8080

  具体指标可以参考文档:https://github.com/webdevops/azure-metrics-exporter

  - job_name: azure-metrics-storageaccount-connections
    scrape_interval: 1m
    metrics_path: /probe/metrics/list
    params:
      name: ["my_own_metric_name"]
      subscription:
      - 166157a8-9ce9-400b-91c7-1d42482b83d6
      resourceType: ["Microsoft.Storage/storageAccounts"]
      metricNamespace: ["Microsoft.Storage/storageAccounts/blobServices"]
      metric:
      - BlobCapacity
      interval: ["PT1H"]
      timespan: ["PT1H"]
      aggregation:
      - average
      - count
      # by blobtype (dimension support)
      # metricFilter: ["BlobType eq '*'"]
      metricTop: ["10"]
    static_configs:
    - targets: ["localhost:8080"]

 

 

  七.配置Prometheus yml文件for Azure MySQL Flexible Server

  1. 以下是配置Azure MySQL Flexible Server的Prometheus配置文件

  2. 具体的Metric可以参考:https://learn.microsoft.com/en-us/azure/azure-monitor/reference/supported-metrics/microsoft-dbformysql-flexibleservers-metrics

  

  - job_name: azure-metrics-databases
    scrape_interval: 1m
    metrics_path: /probe/metrics/list
    params:
      name: ["azure-database"]
      subscription:
      - 166157a8-9ce9-400b-91c7-1d42482b83d6
      #filter: ["resourceType eq 'Microsoft.DBforMySQL/servers'"]
      resourceType: ["Microsoft.DBforMySQL/flexibleServers"]
      #metricNamespace: ["Microsoft.DBforMySQL/flexibleServers"]
      metric:
      - cpu_percent
      - memory_percent
      interval: ["PT1M"]
      timespan: ["2024-08-09T07:00:00Z/2024-08-09T08:00:00Z"]
      aggregation:
      - average
      #- count
      # by blobtype (dimension support)
      # metricFilter: ["BlobType eq '*'"]
      metricTop: ["10"]
    static_configs:
    - targets: ["localhost:8080"]

 

 

  八.Azure Postgre SQL Flexible Server

  1.以下是配置Azure PGSQL Flexible Server的Prometheus配置文件

  2.主要监控的指标有两个:CPU利用率和内存利用率

  3.具体的Metric可以参考:https://learn.microsoft.com/en-us/azure/azure-monitor/reference/supported-metrics/microsoft-dbforpostgresql-flexibleservers-metrics

  - job_name: azure-metrics-pgsql
    scrape_interval: 1m
    metrics_path: /probe/metrics/list
    params:
      name: ["azure-pgsql"]
      subscription:
      - 166157a8-9ce9-400b-91c7-1d42482b83d6
      resourceType: ["Microsoft.DBforPostgreSQL/flexibleServers"]
      metric:
      - cpu_percent
      - memory_percent
      interval: ["PT1M"]
      #P7D表示最近7天
      timespan: ["P7D"]
      aggregation:
      - average
      #- count
      metricTop: ["20"]
    static_configs:
    - targets: ["localhost:8080"]

 

 

  九.根据PGSQL Flexible Server名称等于某个值

  1. 以下是配置Azure PGSQL Flexible Server的Prometheus配置文件
  2. 显示类型为:PGSQL Flexible Server
  3. 筛选PGSQL的Server Name为:等于leipgsql01
  4. 这里用的是OData的运算符eq,也就是equal,等于某个值

  - job_name: azure-metrics-pgsql
    scrape_interval: 1m
    metrics_path: /probe/metrics/list
    params:
      name: ["azure-pgsql"]
      subscription:
      - 166157a8-9ce9-400b-91c7-1d42482b83d6
      filter: ["resourceType eq 'Microsoft.DBforPostgreSQL/flexibleServers' and name eq 'leipgsql01'"]
      #filter: ["resourceName eq 'leipgsql01'"]
      #resourceType: ["Microsoft.DBforPostgreSQL/flexibleServers"]
      #metricNamespace: ["Microsoft.DBforMySQL/flexibleServers"]
      metric:
      - cpu_percent
      - memory_percent
      interval: ["PT1M"]
      #timespan: ["2024-12-26T03:00:00Z/2024-12-28T08:00:00Z"]
      timespan: ["P7D"]
      aggregation:
      - average
      #- count
      # by blobtype (dimension support)
      # metricFilter: ["BlobType eq '*'"]
      metricTop: ["20"]
    static_configs:
    - targets: ["localhost:8080"]
  1. 执行结果,可以看到只显示Server Name为leipgsql01的指标:cpu_percent,memory_percent
# HELP azure_pgsql Azure monitor insight metric
# TYPE azure_pgsql gauge
azure_pgsql{aggregation="average",interval="PT1M",metric="cpu_percent",resourceGroup="sig-rg",resourceID="/subscriptions/166157a8-9ce9-400b-91c7-1d42482b83d6/resourcegroups/sig-rg/providers/microsoft.dbforpostgresql/flexibleservers/leipgsql01",resourceName="leipgsql01",subscriptionID="166157a8-9ce9-400b-91c7-1d42482b83d6",subscriptionName="leizhang-non-prod",tag_owner="",timespan="P7D",unit="Percent"} 10.5
azure_pgsql{aggregation="average",interval="PT1M",metric="memory_percent",resourceGroup="sig-rg",resourceID="/subscriptions/166157a8-9ce9-400b-91c7-1d42482b83d6/resourcegroups/sig-rg/providers/microsoft.dbforpostgresql/flexibleservers/leipgsql01",resourceName="leipgsql01",subscriptionID="166157a8-9ce9-400b-91c7-1d42482b83d6",subscriptionName="leizhang-non-prod",tag_owner="",timespan="P7D",unit="Percent"} 65.5

 

 

  十.根据PGSQL Flexible Server名称不等于某个值

  1. 以下是配置Azure PGSQL Flexible Server的Prometheus配置文件
  2. 显示类型为:PGSQL Flexible Server
  3. 筛选PGSQL的Server Name为:不等于leipgsql01
  4. 这里用的是OData的运算符ne,也就是not equal,不等于某个值

- job_name: azure-metrics-pgsql
    scrape_interval: 1m
    metrics_path: /probe/metrics/list
    params:
      name: ["azure-pgsql"]
      subscription:
      - 166157a8-9ce9-400b-91c7-1d42482b83d6
      filter: ["resourceType eq 'Microsoft.DBforPostgreSQL/flexibleServers' and name ne 'leipgsql01'"]
      #filter: ["resourceName eq 'leipgsql01'"]
      #resourceType: ["Microsoft.DBforPostgreSQL/flexibleServers"]
      #metricNamespace: ["Microsoft.DBforMySQL/flexibleServers"]
      metric:
      - cpu_percent
      - memory_percent
      interval: ["PT1M"]
      #timespan: ["2024-12-26T03:00:00Z/2024-12-28T08:00:00Z"]
      timespan: ["P7D"]
      aggregation:
      - average
      #- count
      # by blobtype (dimension support)
      # metricFilter: ["BlobType eq '*'"]
      metricTop: ["20"]
    static_configs:
    - targets: ["localhost:8080"]

 

 

  十一.根据PGSQL Flexible Server名称包含某个值

  1. 以下是配置Azure PGSQL Flexible Server的Prometheus配置文件
  2. 显示类型为:PGSQL Flexible Server
  3. 筛选PGSQL的Server Name为:包含lei
  4. 这里用的是OData的运算符substringof

  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
  - job_name: azure-metrics-pgsql
    scrape_interval: 1m
    metrics_path: /probe/metrics/list
    params:
      name: ["azure-pgsql"]
      subscription:
      - 166157a8-9ce9-400b-91c7-1d42482b83d6
      filter: ["resourceType eq 'Microsoft.DBforPostgreSQL/flexibleServers' and substringof('lei',name)"]
      #filter: ["resourceName eq 'leipgsql01'"]
      #resourceType: ["Microsoft.DBforPostgreSQL/flexibleServers"]
      #metricNamespace: ["Microsoft.DBforMySQL/flexibleServers"]
      metric:
      - cpu_percent
      - memory_percent
      interval: ["PT1M"]
      #timespan: ["2024-12-26T03:00:00Z/2024-12-28T08:00:00Z"]
      timespan: ["P7D"]
      aggregation:
      - average
      #- count
      # by blobtype (dimension support)
      # metricFilter: ["BlobType eq '*'"]
      metricTop: ["20"]
    static_configs:
    - targets: ["localhost:8080"]

 

  十二.启动Prometheus

  1.我们执行命令:

./prometheus --config.file=prometheus.yml

  2.Prometheus的默认端口为9090

  3.打开浏览器,查看http://ip:9090,如下图。点击Status, Target

  4.下图展示的azure-metric-storageaccount-connection,就是我们之前配置的

  5.我们打开上图的Exporter端口,显示结果为,包含我订阅下所有存储账户名称和存储账户的容量大小

# HELP my_own_metric_name Azure monitor insight metric
# TYPE my_own_metric_name gauge
my_own_metric_name{aggregation="average",interval="PT1H",metric="BlobCapacity",resourceGroup="cdn-rg",resourceID="/subscriptions/166157a8-9ce9-400b-91c7-1d42482b83d6/resourcegroups/cdn-rg/providers/microsoft.storage/storageaccounts/leicdnoriginalstorage",resourceName="leicdnoriginalstorage",subscriptionID="166157a8-9ce9-400b-91c7-1d42482b83d6",subscriptionName="leizhang-non-prod",tag_owner="",timespan="PT1H",unit="Bytes"} 33835
my_own_metric_name{aggregation="average",interval="PT1H",metric="BlobCapacity",resourceGroup="cloud-shell-storage-southeastasia",resourceID="/subscriptions/166157a8-9ce9-400b-91c7-1d42482b83d6/resourcegroups/cloud-shell-storage-southeastasia/providers/microsoft.storage/storageaccounts/cs110032002647d220b",resourceName="cs110032002647d220b",subscriptionID="166157a8-9ce9-400b-91c7-1d42482b83d6",subscriptionName="leizhang-non-prod",tag_owner="",timespan="PT1H",unit="Bytes"} 0
my_own_metric_name{aggregation="average",interval="PT1H",metric="BlobCapacity",resourceGroup="fw-hybrid-test",resourceID="/subscriptions/166157a8-9ce9-400b-91c7-1d42482b83d6/resourcegroups/fw-hybrid-test/providers/microsoft.storage/storageaccounts/niostoragetest01",resourceName="niostoragetest01",subscriptionID="166157a8-9ce9-400b-91c7-1d42482b83d6",subscriptionName="leizhang-non-prod",tag_owner="",timespan="PT1H",unit="Bytes"} 0
my_own_metric_name{aggregation="average",interval="PT1H",metric="BlobCapacity",resourceGroup="lab-rg",resourceID="/subscriptions/166157a8-9ce9-400b-91c7-1d42482b83d6/resourcegroups/lab-rg/providers/microsoft.storage/storageaccounts/leiadls",resourceName="leiadls",subscriptionID="166157a8-9ce9-400b-91c7-1d42482b83d6",subscriptionName="leizhang-non-prod",tag_owner="",timespan="PT1H",unit="Bytes"} 1104
my_own_metric_name{aggregation="average",interval="PT1H",metric="BlobCapacity",resourceGroup="lab-rg",resourceID="/subscriptions/166157a8-9ce9-400b-91c7-1d42482b83d6/resourcegroups/lab-rg/providers/microsoft.storage/storageaccounts/leilabstorage01",resourceName="leilabstorage01",subscriptionID="166157a8-9ce9-400b-91c7-1d42482b83d6",subscriptionName="leizhang-non-prod",tag_owner="",timespan="PT1H",unit="Bytes"} 34272

 

  6.我们还可以执行:

nohup ./azure-metrics-exporter.linux.amd64 --development.webui &

 

  7.Azure metric exporter提供web 界面进行查询。以我的环境为例,打开链接:http://20.52.9.41:8080/query。我们可以在下面进行调试:

 

标签:Exporter,Monitor,metric,metrics,azure,91c7,Azure,name
From: https://www.cnblogs.com/threestone/p/18636566

相关文章

  • 工作坊报名|使用 TEN Framework 与 Azure,探索你的多模态交互新场景
    活动背景GPT-4oRealtimeAPI发布,语音AI正在进入一场新的爆发。AI的实时语音和视觉互动能力将为我们带来更多全新创意和应用场景。实时音频交互:允许应用程序实时接收并响应语音和文本输入。自然语音生成:减少AI语音的机械感,使对话更加人性化。多语言能力:促进多语言之间......
  • 观测云宣布正式上架微软 Azure Marketplace
    我们自豪地宣布,观测云现已正式上架微软AzureMarketplace!观测云的客户现在可以使用高效、值得信赖的Azure云平台,享受简化的部署和管理体验。AzureMarketplace是一个专为购买和销售经过认证的、可在Azure平台上运行的云解决方案而设计的市场。它将寻求创新型云解决方......
  • Set-MMAgent -MaxOperationAPIFiles 的主要功能是设置 Microsoft Monitoring Agent (M
    mmagentApplicationLaunchPrefetching:FalseApplicationPreLaunch    :FalseMaxOperationAPIFiles    :8192MemoryCompression      :FalseOperationAPI        :FalsePageCombining        :FalsePS......
  • Azure Databricks - [02] 常用SQL
    查看当前所在catalog:selectcurrent_catalog();创建catalog:createcatalogifnotexistsharley_test;创建表createtableifnotexistslakehouse_sit.default.harley_overtime(idintcomment'序号',typeintcomment'1:加班,0:调休',overtime_dates......
  • 【Azure Logic App】使用Logic App来定制Monitor Alert邮件内容遇见无法获取SearchRes
    问题描述在使用AzureMonitor获取自定义告警指标并发出告警邮件时,默认的告警邮件内容不满足需要,需要把自定义查询语句的结果也直接显示在邮件中。查阅官方文档(CustomizealertnotificationsbyusingLogicApps),可以通过LogicApp来自定义Alert邮件内容。但是,在实验中,遇见......
  • 【Azure Batch Account】批处理服务是否可以固定出口访问IP地址呢?
    问题描述使用AzureBatchAccount服务(批处理),所访问的资源受防火墙保护。现在需要把BatchAccount服务池中的实例地址IP加入到防火墙白名单中,但是由于BatchAccount被没有指定的出口访问IP地址,所以需要把BatchAccount服务的全部IP地址加入到白名单中,但是,它的范围的确太多了!如......
  • rocketmq-exporter编译部署
    #下载ApacheMavenwgethttps://dlcdn.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gztar-xvfapache-maven-3.9.6-bin.tar.gzmvapache-maven-3.9.6/usr/local/maven#将maven加入到环境变量vim/etc/profile#最底部配置exportMAVEN_HOME=/usr/loc......
  • 多显示器 Win + D 只隐藏当前桌面窗口 – ShowDesktop Per Monitor
    现在的电脑都可以同时连接多个不同的显示器,这样在一台电脑进行操作的时候,其他显示器也会显示出同样的内容,比如按下快捷键“Win+D”就可以对当前桌面的所有窗口进行隐藏,再按一次可恢复。这个快捷键非常好用,平时工作当中可能是我用得最频繁的一个快捷组合键了。但是最近遇到一......
  • node_exporter部署和漏洞修复【非常详细】
    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录1.介绍2.安装3.配置为系统服务:4.开启认证(修复未授权访问问题)4.1TLS证书生成4.2**basicauth认证生成**4.3编写配置文件4.4配置为系统服务4.5验证4.6配置到Prometheus5.pprof漏洞修复......
  • 【Azure Developer】使用cmd脚本循环执行curl请求
    问题描述在测试ApplicationInsights的每日上限(DailyCap)功能,想通过最简单的curl脚本来循环发送请求,验证日志摄入量大道设置的300MB(0.03GB)后,是否可以通过调大DailyCap限制值马上恢复数据的摄入! 问题解答一个简单的CMD脚本示例,它会循环执行 curl 命令:@echooff......