cadvisor監控:
curl -k https://10.10.10.95:10250/metrics -H "Authorization: Bearer token-qz4w7:b5s2kwwsh8v47xq8gl7b97zrjgjkb7srr78n2wxrmmvlvc8gqgd7fr"
cadvisor中獲取到的典型監控指標如下:
指標名稱 類型 含義
container_cpu_load_average_10s gauge 過去10秒容器CPU的平均負載
container_cpu_usage_seconds_total counter 容器在每個CPU內核上的累積占用時間 (單位:秒)
container_cpu_system_seconds_total counter System CPU累積占用時間(單位:秒)
container_cpu_user_seconds_total counter User CPU累積占用時間(單位:秒)
container_fs_usage_bytes gauge 容器中文件系統的使用量(單位:字節)
container_fs_limit_bytes gauge 容器可以使用的文件系統總量(單位:字節)
container_fs_reads_bytes_total counter 容器累積讀取數據的總量(單位:字節)
container_fs_writes_bytes_total counter 容器累積寫入數據的總量(單位:字節)
container_memory_max_usage_bytes gauge 容器的最大內存使用量(單位:字節)
container_memory_usage_bytes gauge 容器當前的內存使用量(單位:字節
container_spec_memory_limit_bytes gauge 容器的內存使用量限制
machine_memory_bytes gauge 當前主機的內存總量
container_network_receive_bytes_total counter 容器網絡累積接收數據總量(單位:字節)
container_network_transmit_bytes_total counter 容器網絡累積傳輸數據總量(單位:字節)
4.當能夠正常采集到cAdvisor的樣本數據后,可以通過以下表達式計算容器的CPU使用率:
(1)sum(irate(container_cpu_usage_seconds_total{image!=""}[1m])) without (cpu)
容器CPU使用率
(2)container_memory_usage_bytes{image!=""}
查詢容器內存使用量(單位:字節):
(3)sum(rate(container_network_receive_bytes_total{image!=""}[1m])) without (interface)
查詢容器網絡接收量(速率)(單位:字節/秒):
(4)sum(rate(container_network_transmit_bytes_total{image!=""}[1m])) without (interface)
容器網絡傳輸量 字節/秒
(5)sum(rate(container_fs_reads_bytes_total{image!=""}[1m])) without (device)
容器文件系統讀取速率 字節/秒
(6)sum(rate(container_fs_writes_bytes_total{image!=""}[1m])) without (device)
容器文件系統寫入速率 字節/秒
5.cadvisor 常用容器監控指標
(1)網絡流量
sum(rate(container_network_receive_bytes_total{name=~".+"}[1m])) by (name)
##容器網絡接收的字節數(1分鍾內),根據名稱查詢 name=~".+"
sum(rate(container_network_transmit_bytes_total{name=~".+"}[1m])) by (name)
##容器網絡傳輸的字節數(1分鍾內),根據名稱查詢 name=~".+"
(2)容器 CPU相關
sum(rate(container_cpu_system_seconds_total[1m]))
###所用容器system cpu的累計使用時間(1min鍾內)
sum(irate(container_cpu_system_seconds_total{image!=""}[1m])) without (cpu)
###每個容器system cpu的使用時間(1min鍾內)
sum(rate(container_cpu_usage_seconds_total{name=~".+"}[1m])) by (name) * 100
#每個容器的cpu使用率
sum(sum(rate(container_cpu_usage_seconds_total{name=~".+"}[1m])) by (name) * 100)
#總容器的cpu使用率
relabel的保留:
- job_name: 'kubernetes-service-endpoints'
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
action: keep
regex: true
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
action: replace
target_label: __scheme__
regex: (https?)
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
- source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
action: replace
target_label: __address__
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
- action: labelmap
regex: __meta_kubernetes_service_label_(.+)
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: kubernetes_namespace
- source_labels: [__meta_kubernetes_service_name]
action: replace
target_label: kubernetes_name
如果在service的annotation里發現prometheus.io/scrape為true,就抓取。 ( [__meta_kubernetes_service_annotation_prometheus_io_scrape] )