《Windows Azure Platform 系列文章目录》
1.之前接触一些客户,使用Prometheus Cloud Watch Exporter,把AWS监控指标,与Prometheus整合
https://github.com/prometheus/cloudwatch_exporter
客户希望微软云Azure也提供类似的功能,能把Azure的监控指标(虚拟机、Redis PaaS等,MySQL PaaS数据等),与Prometheus整合
2.目前查询下来,没有官网提供的Exporter功能,但是查询到第三方开源的解决方案:
https://github.com/webdevops/azure-metrics-exporter
3.该开源方案基于Azure SDK for Go,实现Azure Monitor Metirc Exporter功能。具体的部署方式如下:
4.创建Service Principle,并赋权,建议授予Azure Contributor权限,给整个订阅
5.安装虚拟机,本文以Azure CentOS 7.9环境为例。具体创建步骤略。
6.我们根据上面创建的Service Principle,在CentOS 7.9上设置环境变量。根据实际情况修改下面的内容:
AZURE_CLIENT_ID=""
AZURE_TENANT_ID=""
AZURE_CLIENT_SECRET=""
7.安装Prometheus
我这里使用Prometheus 2.50.1
具体安装步骤略。
8.下载与运行Azure Monitor Metric Exporter项目
项目文件在:https://github.com/webdevops/azure-metrics-exporter/releases
我们先下载24.2.0版本:
下载后运行:
nohup ./azure-metrics-exporter.linux.amd64 &
9.我们编辑prometheus.yml文件,增加下面的内容
(1) job_name,设置job名称
(2)下面的subscription,是我演示环境的订阅ID。请按照实际情况修改
(3)metricNamespace和metric,请按照实际需要的指标名称进行修改
(4)请注意下图使用的地址和端口号,为localhost: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"]
10.我们执行下面的命令,启动Prometheus
./prometheus --config.file=prometheus.yml
11.Prometheus的默认端口为:9090
12.打开浏览器,查看http://ip:9090,如下图。点击Status, Target
13.下图展示的azure-metric-storageaccount-connection,就是我们在Step 9中配置的
14.我们打开上图的exporter端口,这里以我的演示环境为例。链接地址略。
15.显示结果为,包含我订阅下所有存储账户名称,及存储账户的容量大小:
# 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
这就是我的环境i的5个存储对象,如下图:
16.Azure Monitor Metric Exporter还提供调试的功能,我们可以执行:
nohup ./azure-metrics-exporter.linux.amd64 --development.webui &
17.Azure metric exporter提供web 界面进行查询。以我的环境为例,打开链接:http://20.52.9.41:8080/query。我们可以在下面进行调试: