如何用prometheus监控ECS虚拟机上的信息
windows主机上安装上prometheus程序,用prometheus来监控华为云上面的ECS虚拟机电脑(linux系统)的内存、cpu等信息。
prometheus提供统一监控管理,但是搜集被监控的虚拟机电脑的信息需要使用node-exporter等软件在被监控的机器上安装后自动搜集,prometheus的配置文件只负责配置被监控虚拟机的ip地址、端口,获取方式等。
一、在任意windows主机上安装prometheus
下载prometheus
https://prometheus.io/download/
启动prometheus
解压包prometheus-2.9.2.windows-amd64.tar.gz后,双击prometheus.exe即可启动
查看默认的本地监控状态
二、在被监控的ECS linux虚拟机上安装启动node exporter
安装node exporter
# wget https://github.com/prometheus/node_exporter/releases/download/v0.18.0/node_exporter-0.18.0.linux-386.tar.gz # tar -zxvf node_exporter-0.18.0.linux-386.tar.gz # mkdir /usr/local/prometheus # mkdir /usr/local/prometheus/node_exporter # mv node_exporter-0.18.0.linux-386 /usr/local/prometheus/node_exporter
创建linux用户
该新linux用户存储目录为/var/lib/prometheus
# groupadd prometheus # useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
创建Systemd服务
$ vim /etc/systemd/system/node_exporter.service [Unit] Description=node_exporter After=network.target [Service] Type=simple User=prometheus ExecStart=/usr/local/prometheus/node_exporter/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target
启动node exporter
# systemctl start node_exporter # systemctl status node_exporter ● node_exporter.service - node_exporter Loaded: loaded (/etc/systemd/system/node_exporter.service; disabled; vendor preset: enabled) Active: active (running) since Tue 2019-05-14 15:50:56 CST; 6s ago Main PID: 15434 (node_exporter) Tasks: 5 Memory: 1.3M CPU: 9ms CGroup: /system.slice/node_exporter.service └─15434 /usr/local/prometheus/node_exporter/node_exporter May 14 15:50:56 ecs-ecff-0003 node_exporter[15434]: time="2019-05-14T15:50:56+08:00" level=info msg=" - sockstat" source="node_exporter.go:104" May 14 15:50:56 ecs-ecff-0003 node_exporter[15434]: time="2019-05-14T15:50:56+08:00" level=info msg=" - stat" source="node_exporter.go:104" May 14 15:50:56 ecs-ecff-0003 node_exporter[15434]: time="2019-05-14T15:50:56+08:00" level=info msg=" - textfile" source="node_exporter.go:104" May 14 15:50:56 ecs-ecff-0003 node_exporter[15434]: time="2019-05-14T15:50:56+08:00" level=info msg=" - time" source="node_exporter.go:104" May 14 15:50:56 ecs-ecff-0003 node_exporter[15434]: time="2019-05-14T15:50:56+08:00" level=info msg=" - timex" source="node_exporter.go:104" May 14 15:50:56 ecs-ecff-0003 node_exporter[15434]: time="2019-05-14T15:50:56+08:00" level=info msg=" - uname" source="node_exporter.go:104" May 14 15:50:56 ecs-ecff-0003 node_exporter[15434]: time="2019-05-14T15:50:56+08:00" level=info msg=" - vmstat" source="node_exporter.go:104" May 14 15:50:56 ecs-ecff-0003 node_exporter[15434]: time="2019-05-14T15:50:56+08:00" level=info msg=" - xfs" source="node_exporter.go:104" May 14 15:50:56 ecs-ecff-0003 node_exporter[15434]: time="2019-05-14T15:50:56+08:00" level=info msg=" - zfs" source="node_exporter.go:104" May 14 15:50:56 ecs-ecff-0003 node_exporter[15434]: time="2019-05-14T15:50:56+08:00" level=info msg="Listening on :9100" source="node_exporter.go:170"
三、配置prometheus
在默认的windows机器上的prometheus.yml文件中新增监控结点
scrape_configs: - job_name: 'file-zj' file_sd_configs: - files: - '/data/targets.json' //被监控信息存在的文件的路径,是相对路径
在/data/targets.json文件中新增监控结点,其中ecs-xxx-0003为虚拟机主机名,9101为端口号
{ "targets": [ "ecs-xxx-0003:9101"], "labels": { "job": "linux-remote-exporter" } }
过一会儿再刷新http://127.0.0.1:9090/targets ,新的监控结点就显示出来了。
切换到http://127.0.0.1:9090/graph 中可查看具体的ecs虚拟机上cpu、内存等监控信息
- 点赞
- 收藏
- 关注作者
评论(0)