prometheus之二:cAdvisor
一、cAdvisor的安装
1、docker拉取cadvisor镜像*
docker pull docker.io/google/cadvisor
2、运行一个容器,并配置
docker run \ --volume=/:/rootfs:ro \ --volume=/var/run:/var/run:rw \ --volume=/sys:/sys:ro \ --volume=/var/lib/docker/:/var/lib/docker:ro \ --publish=8090:8080 \ --detach=true \ --name=cadvisor \ google/cadvisor:latest
3、打卡网页查看
localhost:8090/containers/
4、修改configmap文件如下
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-config
namespace: kube-ops
data:
prometheus.yml: |
global:
scrape_interval: 15s
scrape_timeout: 15s
scrape_configs:
- job_name: 'nodes'
static_configs:
- targets: ['localhost:9090']
- job_name: 'container'
static_configs:
- targets: ['192.168.48.100:8090']
5、重新加载prometheus.yaml
kill -HUP pid
6、界面访问http://192.168.48.200:30132/targets,如图
二、Prometheus 中查看容器的 CPU,内存,网络流量等数据
CPU 使用率查询:
sum by (name) (rate(container_cpu_usage_seconds_total{image!=""}[1m])) / scalar(count(node_cpu{mode="user"})) * 100
内存使用量查询
sum by (name)(container_memory_usage_bytes{image!=""})
网络入口流量
sum by (name) (rate(container_network_receive_bytes_total{image!=""}[1m]))
网络出口流量
sum by (name) (rate(container_network_transmit_bytes_total{image!=""}[1m]))
磁盘使用量
sum by (name) (container_fs_usage_bytes{image!=""})