这不比探针酷?——Grafana+Prometheus+qcloud-exporter实现多地域监控Lighthouse

腾讯云轻量无忧计划 新老用户同享优惠 低至15元/月起 终身续费同价 更赠送一年顶级域名,并享长期续费优惠

活动链接:https://cloud.tencent.com/act/lighthouse

(活动将于2021.12.31结束)


Grafana简介

Grafana是一个完全开源的度量分析与可视化平台,可对来自各种各种数据源的数据进行查询、分析、可视化处理以及配置告警。

  • Grafana支持的数据源:
    • 官方:Graphite,InfluxDB,OpenTSDB,Prometheus,Elasticsearch,MySQL等;
    • 插件:open-falcon、zabbix...

Prometheus简介

Prometheus(普罗米修斯)是一个名字非常酷的开源监控系统。

它支持多维度的指标数据模型,服务端通过HTTP协议定时拉取数据后,通过灵活的查询语言,实现监控的目的。

腾讯云监控 Exporter v2(tencentcloud-exporter)

通过qcloud exporter将云监控支持的产品监控指标自动批量导出


本文使用的操作系统为Centos7.6

1.安装Grafana

wget https://dl.grafana.com/oss/release/grafana-8.3.0-1.x86_64.rpm
sudo yum install grafana-8.3.0-1.x86_64.rpm
开机自启
sudo systemctl enable grafana-server
启动
sudo systemctl start grafana-server
查看状态
sudo systemctl status grafana-server

2.下载tencentcloud-exporter

下载已经编译好的exporter
wget https://github.com/tencentyun/tencentcloud-exporter/releases/download/v2.5.0/qcloud-exporter-v2.5.0-linux-amd64.tar.gz
解压
tar xzvf qcloud-exporter-v2.5.0-linux-amd64.tar.gz

3.下载Prometheus

下载
wget https://github.com/prometheus/prometheus/releases/download/v2.32.0-rc.0/prometheus-2.32.0-rc.0.linux-amd64.tar.gz
解压
tar -xzvf prometheus-2.32.0-rc.0.linux-amd64.tar.gz 

4.编写一些配置文件

创建lh-region文件夹
mkdir lh-region&&cd lh-region

既然是多地域 那就让python来处理一下吧

vim region.py
#exporter配置文件
#别忘记修改access_key与secret_key
​
region = ['ap-beijing', 'ap-chengdu', 'ap-guangzhou', 'ap-hongkong', 'ap-shanghai', 'ap-singapore','na-siliconvalley','eu-moscow', 'ap-tokyo', 'ap-nanjing','ap-mumbai','eu-frankfurt']
​
for i in range(12):
    file = open('{0}.yml'.format(region[i]), 'w')
    ini = '''credential:
  access_key: 'SecretId'
  secret_key: 'SecretKey'
  region: '{0}'
rate_limit: 10
products:
  - namespace: QCE/LIGHTHOUSE
    all_metrics: true
    all_instances: true
'''.format(region[i])
    print(ini,file=file)
Prometheus配置文件
在prometheus.yml末尾粘贴以下代码
​
  - job_name: "ap-beijing"
    static_configs:
      - targets: ["localhost:9100"]
  - job_name: "ap-chengdu"
    static_configs:
      - targets: ["localhost:9101"]
  - job_name: "ap-guangzhou"
    static_configs:
      - targets: ["localhost:9102"]
  - job_name: "ap-hongkong"
    static_configs:
      - targets: ["localhost:9103"]
  - job_name: "ap-shanghai"
    static_configs:
      - targets: ["localhost:9104"]
  - job_name: "ap-singapore"
    static_configs:
      - targets: ["localhost:9105"]
  - job_name: "na-siliconvalley"
    static_configs:
      - targets: ["localhost:9106"]
  - job_name: "eu-moscow"
    static_configs:
      - targets: ["localhost:9107"]
  - job_name: "ap-tokyo"
    static_configs:
      - targets: ["localhost:9108"]
  - job_name: "ap-nanjing"
    static_configs:
      - targets: ["localhost:9109"]
  - job_name: "ap-mumbai"
    static_configs:
      - targets: ["localhost:9110"]
  - job_name: "eu-frankfurt"
    static_configs:
      - targets: ["localhost:9111"]

5.启动exporter

新建一个名为nohup的文件夹用来存放输出文件

cd &&mkdir nohup
nohup ./qcloud_exporter --config.file lh-region/ap-beijing.yml --web.listen-address 127.0.0.1:9100 &> nohup/ap-beijing.out&
nohup ./qcloud_exporter --config.file lh-region/ap-chengdu.yml --web.listen-address 127.0.0.1:9101 &> nohup/ap-chengdu.out&
nohup ./qcloud_exporter --config.file lh-region/ap-guangzhou.yml --web.listen-address 127.0.0.1:9102 &> nohup/ap-guangzhou.out&
nohup ./qcloud_exporter --config.file lh-region/ap-hongkong.yml --web.listen-address 127.0.0.1:9103 &> nohup/ap-hongkong.out&
nohup ./qcloud_exporter --config.file lh-region/ap-shanghai.yml --web.listen-address 127.0.0.1:9104 &> nohup/ap-shanghai.out&
nohup ./qcloud_exporter --config.file lh-region/ap-singapore.yml --web.listen-address 127.0.0.1:9105 &> nohup/ap-singapore.out&
nohup ./qcloud_exporter --config.file lh-region/na-siliconvalley.yml --web.listen-address 127.0.0.1:9106 &> nohup/na-siliconvalley.out&
nohup ./qcloud_exporter --config.file lh-region/eu-moscow.yml --web.listen-address 127.0.0.1:9107 &> nohup/eu-moscow.out&
nohup ./qcloud_exporter --config.file lh-region/ap-tokyo.yml --web.listen-address 127.0.0.1:9108 &> nohup/ap-tokyo.out&
nohup ./qcloud_exporter --config.file lh-region/ap-nanjing.yml --web.listen-address 127.0.0.1:9109 &> nohup/ap-nanjing.out&
nohup ./qcloud_exporter --config.file lh-region/ap-mumbai.yml --web.listen-address 127.0.0.1:9110 &> nohup/ap-mumbai.out&
nohup ./qcloud_exporter --config.file lh-region/eu-frankfurt.yml --web.listen-address 127.0.0.1:9111 &> nohup/eu-frankfurt.out&

6.启动Prometheus

cd prometheus-2.32.0-rc.0.linux-amd64&&nohup ./prometheus --config.file=prometheus.yml &> /root/nohup/prometheus.out &

7.前往Ganfana

浏览器输入http://ip:3000前往ganfana主页面

初始用户名与密码均为admin

接下来配置数据源http://ip:3000/datasources/new

选择Prometheus(就是第一个)

填写名字和url 并记录下地址栏后面的数据源id

Url填写http://localhost:9090

Save & test 显示Data source is working 即添加成功

之后去导入仪表盘

http://ip:3000/dashboard/import

上传json文件(json文件以放在下面 自取即可 无需上传到服务器)

前往仪表盘界面http://ip:3000/dashboards

单击刚刚导入的仪表盘

点击上方的小齿轮进入设置

按步骤修改

(此为第三步需要填写的原数据源id EMngyg2nk)

保存之后返回 选择地域和需要查看的服务器id即可查看数据


该文章已同步投稿于腾讯云文档中心,腾讯云社区,bilibili,知乎。

本站文章资源均来源自网络,除非特别声明,否则均不代表站方观点,并仅供查阅,不作为任何参考依据!
如有侵权请及时跟我们联系,本站将及时删除!
如遇版权问题,请查看 本站版权声明
THE END
分享
二维码
海报
这不比探针酷?——Grafana+Prometheus+qcloud-exporter实现多地域监控Lighthouse
腾讯云轻量无忧计划 新老用户同享优惠 低至15元/月起 终身续费同价 更赠送一年顶级域名,并享长期续费优惠
<<上一篇
下一篇>>