Pve使用外部监控Grafana+Prometheus

pve本身虚拟机监控,监控内容很少,也不能全部一眼查看,了解全部。所以为了更加详细的了解实况,用上了外部监控,Grafana+Prometheus

看看这个图,高不高级。图小。就右击,在新窗口查看。

Proxmox可以使用很多的外部监控器,本文就用的是Grafana+Prometheus

首先说一下,Grafana是什么?他就是一个通用的WEB监控器。需要其他的数据源,才能实现监控。数据源就像,下面的图一样,有Prometheus,Graphite等等。对于Prometheus数据源来说,他有很多种工具,来获取信息,本文写的就是图上的2种,proxmox-pve-exporter Node exporter

本文基于Grafana+Prometheus+pve-exporter。其中2个工具安装到pve主机上,Grafana Server和Prometheus Server可以单独安装,也可以一起安装,本文是一起安装在一个虚拟机上的。

下面说步骤

一:部署Grafana服务器。

我这边把Grafanna和prometheus放在一个服务器上

添加源

tee /etc/apt/sources.list.d/grafana.list<<EOF
deb https://packages.grafana.com/oss/deb stable main
EOF

获取gpg签名

curl https://packages.grafana.com/gpg.key |  apt-key add -

更新软件源并下载


apt update && apt install -y apt-transport-https grafana
systemctl enable --now grafana-server

输入服务器IP:3000即可查看grafana是否正常运行。默认账密为admin/admin

二:部署Prometheus

创建Prometheus基本环境

groupadd --system prometheus
useradd -s /sbin/nologin --system -g prometheus prometheus
mkdir /var/lib/prometheus
for i in rules rules.d files_sd; do mkdir -p /etc/prometheus/${i}; done

下载并安装

mkdir -p /tmp/prometheus && cd /tmp/prometheus
curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest \
  | grep browser_download_url \
  | grep linux-amd64 \
  | cut -d '"' -f 4 \
  | wget -qi -
tar xvf prometheus*.tar.gz
cd prometheus*/
mv prometheus promtool /usr/local/bin/
mv prometheus.yml  /etc/prometheus/prometheus.yml
mv consoles/ console_libraries/ /etc/prometheus/
cd ~/
rm -rf /tmp/prometheus

创建systemed文件

tee /etc/systemd/system/prometheus.service<<EOF

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus \
  --web.console.templates=/etc/prometheus/consoles \
  --web.console.libraries=/etc/prometheus/console_libraries \
  --web.listen-address=0.0.0.0:9090 \
  --web.external-url=

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target
EOF

修改systemed文件权限

for i in rules rules.d files_sd; do chown -R prometheus:prometheus /etc/prometheus/${i}; done
for i in rules rules.d files_sd; do chmod -R 775 /etc/prometheus/${i}; done
chown -R prometheus:prometheus /var/lib/prometheus/

使其开机启动

systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus

此时进入浏览器,输入服务器ip:9090即可进入prometheus页面

如果要更改端口号,请修改systemed文件,把9090改成其他的

三:在PVE主机上安装proxmox-pve-exporter

创建用户

groupadd --system prometheus
useradd -s /sbin/nologin --system -g prometheus prometheus
mkdir /etc/prometheus/
apt install python python-pip
pip install prometheus-pve-exporter

创建配置文件

vi /etc/prometheus/pve.yml

填入下面内容

default:
	user: root@pam
	password: your_password_here
	verify_ssl: false

设置一下权限

chown -R prometheus:prometheus /etc/prometheus/
chmod -R 775 /etc/prometheus/

创建systemed

tee /etc/systemd/system/prometheus-pve-exporter.service<<EOF
[Unit]
Description=Prometheus exporter for Proxmox VE
Documentation=https://github.com/znerol/prometheus-pve-exporter

[Service]
Restart=always
User=prometheus
ExecStart=/usr/local/bin/pve_exporter /etc/prometheus/pve.yml

[Install]
WantedBy=multi-user.target
EOF

设置开机启动

systemctl daemon-reload
systemctl start prometheus-pve-exporter
systemctl enable prometheus-pve-exporter

此时输入pve_ip:9221/pve 。就可以进入一个页面

四:将proxmox-pve-exporter 添加到 Prometheus

在Prometheus 主机上

vi /etc/prometheus/prometheus.yml

在最后写入

- job_name: 'proxmox'
  metrics_path: /pve
  static_configs:
  - targets: ['10.13.14.2:9221']

注意,在target处,替换自己的pve_ip。同时注意格式,对齐。

重启一下服务

systemctl restart prometheus

此时在浏览器输入prometheus的地址ip:9090

点开上面的【status】——【targets】,可以看到刚才添加的以上线

五:在Grafana上添加Prometheus数据源

浏览器打开Grafana server ip:3000,初始账号密码admin/admin

第一次登陆之后,会修改密码,修改之后,进入下面页面

点击左边齿轮图标——data source,如下图

点击ADD添加数据源,然后添加Prometheus

根据下图所示,Name可以自定义,url这里,填写Prometheus的地址,2处选择get,最后点击save and test

配置成功之后,就会出现下面这样的,绿色提示

六:在Grafana上添加一个别人的模板

在下图中,输入模板id,点击旁边的load,就可以自动下载

使用 10347模板,

点击左边load,会花时间下载json。下载之后,如下图所示,记得在红圈中,选择自己的datasource,然后点击import

点击之后,出现这样的。

基于更多的模板,可以去 https://grafana.com/grafana/dashboards/ 搜索。注意监控程序-数据源是否符合要求,

六:使用node-exporter监控程序

上面介绍的是Prometheus+proxmox-pve-exporter预览更改 (在新窗口中打开)

这里介绍 Prometheus +node-exporter

6.1 在PVE主机上安装 node-exporter

下载并安装

wget -P /tmp https://github.com/prometheus/node_exporter/releases/download/v1.4.0-rc.0/node_exporter-1.4.0-rc.0.linux-amd64.tar.gz
tar -xzvf /tmp/node_exporter-1.4.0-rc.0.linux-amd64.tar.gz -C /tmp
mv /tmp/node_exporter-1.4.0-rc.0.linux-amd64.tar.gz /usr/local/bin/

创建用户,以及systemed

useradd -rs /bin/false node_exporter

填入下面内容

tee /etc/systemd/system/node_exporter.service<<EOF
[Unit] Description=Node Exporter After=network.target [Service] User=node_exporter Group=node_exporter Type=simple ExecStart=/usr/local/bin/node_exporter [Install] WantedBy=multi-user.target
EOF

设置开机启动

systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter

此时浏览器输入pve_ip:9100,即可进入页面

点击Metrics,可以看到数据信息。

6.2 在Prometheus Server上。添加这个node exporter

vi /etc/prometheus/prometheus.yml

填入以下内容,注意更改自己的ip,注意格式

- job_name: 'node_exporter_metrics'
  scrape_interval: 5s
  static_configs:
    - targets: ['10.13.14.2:9100']

加上刚才设置的prometheus-pve-exporter,配置文件如下

重启prometheus服务

systemctl restart prometheus.service

此时访问prometheus服务器ip:9090的target,可以查看多了一个

6.3 在Grafana上添加基于node_exporter的模板

推荐模板ID为8919,中文的。

还是选择刚才的数据源

选择刚才的数据源。

完结

我也是才了解到Grafana这个东西,可能有些没说明白,还是需要朋友自己多了解了解。

相关文章: http://einverne.github.io/post/2020/05/use-prometheus-and-grafana-monitor-proxmox.html
http://einverne.github.io/post/2020/04/prometheus-monitoring-system-and-tsdb.html

https://foxi.buduanwang.vip/virtualization/pve/615.html/

评论

  1. 阿萨帝
    Windows Chrome 112.0.0.0
    1年前
    2023-4-16 23:05:12

    图片看不了呀?什么情况

  2. 匿名
    Windows Chrome 89.0.4389.114
    3年前
    2021-6-21 8:39:05

    您好,图片显示不出来了,帮忙后台看下。

  3. 匿名
    Macintosh Chrome 87.0.4280.141
    3年前
    2021-1-18 15:45:17

    chwon -R prometheus:prometheus /etc/prometheus/ -> "chown" -R prometheus:prometheus /etc/prometheus/

    • 佛西 博主
      Windows Edge 88.0.705.53
      3年前
      2021-1-29 23:07:44

      thanks


Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/wwwroot/foxi.buduanwang.vip_80/wwwroot/wp-content/themes/argon-theme-master/functions.php on line 1383

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇