使用prometheus监控Linux主机:
1.部署prometheus server:
docker run -d --network host --restart always --name prometheus_server prom/prometheus:v2.37.0
2.部署node exporter:
docker run -d --network host --restart always --name node-exporter prom/node-exporter:v1.3.1
3.修改prometheus server的配置文件
vi /etc/prometheus/prometheus.yml
...
scrape_configs:
...
- job_name: "oldboyedu-linux82-nodes"
static_configs:
- targets: ["10.0.0.102:9100"]
4.重启服务
docker restart prometheus_server
5.查看节点是否被监控
5.1 验证监控目标
Status ---> Targets
5.2 验证数据
node_cpu_seconds_total
配置服务的动态发现(基于二进制部署,不建议使用官方的镜像,有问题!)
1.基于二进制的方式部署prometheus服务端
wget http://192.168.11.253/Docker/day06-/softwares/prometheus-2.36.0.linux-amd64.tar.gz
mkdir /oldboyedu/softwares/prometheus
tar xf prometheus-2.36.0.linux-amd64.tar.gz -C /oldboyedu/softwares/prometheus
2.编写配置文件
vim /oldboyedu/softwares/prometheus/prometheus-2.36.0.linux-amd64/prometheus.yml
...
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "oldboyedu-linux82-nodes"
static_configs:
- targets: ["10.0.0.102:9100"]
- job_name: "oldboyedu-linux82-dongtaifaxian"
file_sd_configs:
- files:
- /tmp/linux82.yml
3.启动node
docker run -dp 19100:9100 --restart unless-stopped -v "/:/host:ro,rslave" --name=node_exporter prom/node-exporter:v1.3.1 --path.rootfs /host
4.动态服务发现脚本
cat > /tmp/linux82.yml <
{
"targets": ["10.0.0.102:9100","10.0.0.102:19100","10.0.0.101:19100"]
}
]
EOF
5.启动服务
./prometheus
6.查看webUI
略。
计算机组成部分:
- 输入设备
- 输出设备
- 控制器
- CPU
一台电脑中:
只有一个CPU。
CPU ---> 多个应用程序。
QQ , 微信, LOL
10ns 10ns 10ns
10ns 10ns 10ns
10ns 10ns 10ns
---> CPU
1秒 ---> 1000000 ns ----> 10ns ---> 100000
---> cpu时间分片。
0.5秒 --->
1秒---》扎一次眼睛, CPU切换了10w次。
--->
1 --->
QQ ---> 10ns + 10ns +10ns ....
微信 ---> 10ns + 10ns +10ns ....
空闲状态 ---> 10ns + 10ns +10ns ....
----> id , user ,system, iowait , ....
1.通过容器启动cadvisor:
docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --publish=8080:8080 --detach=true --name=cadvisor google/cadvisor:latest
2.动态加载配置
[[email protected] ~]# cat /tmp/linux82.yml
[
{
"targets": ["10.0.0.101:8080","10.0.0.102:8080"]
}
]
[[email protected] ~]#
3.grafana手动定制PQL
参考PQL:
container_memory_usage_bytes{image!="",name="cadvisor"}
container_memory_max_usage_bytes{image!="",name="cadvisor"}
container_start_time_seconds{image!="",name="cadvisor"}
container_fs_inodes_total{image != "", name="cadvisor"}
container_network_receive_bytes_total{image != "", name="cadvisor"}
container_network_transmit_packets_total{image != "", name="cadvisor"}
4.验证
见上图。
cat >> /etc/hosts <
10.0.0.152 k8s152.oldboyedu.com
10.0.0.153 k8s153.oldboyedu.com
EOF