【prometheus】计算CPU使用率
prometheus版本
版本信息: 2.19
prometheus版本不一样,语法会有些区别,注意查看官方文档:
https://prometheus.io/docs/prometheus/latest/getting_started/
prometheus常用函数
prometheus常用函数
CPU使用率公式
我们知道
CPU的使用率 = (所有非空闲状态CPU使用时间总和 )/(所有状态CPU时间总和)
由下列公式:
CPU使用时间总和 = 所有非空闲状态CPU使用时间总和 + 所有空闲状态CPU使用时间总和
得出:
CPU的使用率 = 1 - (所有空闲状态CPU使用时间总和 )/(所有状态CPU时间总和)
prometheus计算CPU使用率
CPU使用时间总和
输入:node_cpu_seconds_total
✔node_cpu_seconds_total{cpu="1",endpoint="https",instance="192.168.145.12",job="node-exporter",mode="user",namespace="monitoring",pod="node-exporter-v9v68",service="node-exporter"}
可以看出,node_cpu_seconds_total采样数据,包含信息主要由cpu编号、实例名称、各种时间状态,所以需要根据上述key的值通过、计算、过滤、聚合等方式,最终得出我们所需要值。
CPU使用时间5m增量值
5m增量值 = 当前采样点值 - 5m前的采样点值
输入: increase(node_cpu_seconds_total[5m])
CPU空闲使用时间5m增量值
node_cpu_seconds_total的采样数据,是基于实现序列的key/vlue格式,而key是"mode"记录了采样的是CPU的那种状态的时间(user、sys、idle等)
输入:increase(node_cpu_seconds_total{mode=“idle”}[5m])
聚合多核CPU空闲使用时间5m增量值
采样数据:
{cpu="1",endpoint="https",instance="192.168.145.12",job="node-exporter",mode="idle",namespace="monitoring",pod="node-exporter-v9v68",service="node-exporter"}
✔{cpu="1",endpoint="https",instance="192.168.145.11",job="node-exporter",mode="idle",namespace="monitoring",pod="node-exporter-2jwj2",service="node-exporter"}
✔{cpu="1",endpoint="https",instance="192.168.145.10",job="node-exporter",mode="idle",namespace="monitoring",pod="node-exporter-qls6j",service="node-exporter"}
✔{cpu="0",endpoint="https",instance="192.168.145.12",job="node-exporter",mode="idle",namespace="monitoring",pod="node-exporter-v9v68",service="node-exporter"}
✔{cpu="0",endpoint="https",instance="192.168.145.11",job="node-exporter",mode="idle",namespace="monitoring",pod="node-exporter-2jwj2",service="node-exporter"}
✔{cpu="0",endpoint="https",instance="192.168.145.10",job="node-exporter",mode="idle",namespace="monitoring",pod="node-exporter-qls6j",service="node-exporter"}
通过采样数据,可以看到CPU空闲使用时间5m增量值,是每个cpu和都作为一个采样值,而每个虚机\物理机,大部分是多核的,所以需要聚合所有核数的空闲时间。
输入:sum(increase(node_cpu_seconds_total{mode=“idle”}[5m]))
通过结果可以看出,sum函数是将所有CPU核数时间想加,没有按照主机进行聚合,所以这时就需要引入=by (instance)=函数,它会把sum求和到一起的数值按照指定方式进行拆分,instance代表的是机器名。如果不写by (instance)的话就需要在{}中写明需要哪个实例的数据。
输入:sum(increase(node_cpu_seconds_total{mode=“idle”}[5m])) by (instance)
聚合多核CPU总使用时间5m增量值
输入:sum(increase(node_cpu_seconds_total[5m])) by (instance)
计算平均5分钟CPU使用率
输入:1- sum(increase(node_cpu_seconds_total{mode=“idle”}[5m])) by (instance)/sum(increase(node_cpu_seconds_total[5m])) by (instance)
使用prometheus的node_cpu_utilisation值
输入:instance:node_cpu_utilisation:rate1m
【prometheus】计算CPU使用率相关推荐
- 计算CPU使用率【prometheus】
1.CPU使用率公式 我们知道 CPU的使用率 = (所有非空闲状态CPU使用时间总和 )/(所有状态CPU时间总和) 由下列公式: CPU使用时间总和 = 所有非空闲状态CPU使用时间总和 + 所有 ...
- linux 手动控制cpu转速,Linux 手动计算CPU使用率
先声明,本文涉及到的知识是之前搜集到的,现在整理出来分享大家,虽然打上原创的tag,但还是向原创致敬!如果涉及到侵权的问题,请联系我,我会及时更改! 目前linux统计cpu利用率时,所用到的信息,大 ...
- Prometheus 查询语言 PromQL 的 CPU 使用率计算方法
CPU 使用率的计算方法 翻了几篇 Prometheus 的 PromQL 查询 cpu 使用率的文章,说得都不是特别透,结合一篇英文文章终于搞明白了怎么计算这个指标. cpu 模式 一颗 cpu 要 ...
- CPU使用率原理及计算方式
目录 CPU:Cores, and Hyper-Threading 超线程(Hyper-Threading ) 多核(multi-cores) CPU使用率计算 CPU使用率测试 如何计算CPU使用率 ...
- Prometheus节点失联后CPU使用率不准确
现象 测试节点失联自恢的程序时发现一个异常现象,失联的节点cpu使用率超过60%,实际上测试节点什么程序都没跑,cpu使用率接近0. 原因 该节点每分钟刮取一次监控数据,5分钟取得5个数据点,计算CP ...
- 单片机里面的CPU使用率是什么鬼?
打开电脑的任务管理器,看着跳动的CPU使用率,发现很舒服.每一个线程占用了多少CPU清清楚楚,也就能针对性的确认为啥你的电脑跑的慢了. 今天这篇笔记不讲每个任务(或线程)CPU的使用情况,而是单片机整 ...
- cpu使用率_漫话性能:CPU使用率
序言 CPU 使用率是最直观和最常用的系统性能指标,更是我们在排查性能问题时,通常会关注的第一个指标. 节拍率 为了维护 CPU 时间,Linux 通过事先定义的节拍率(内核中表示为 HZ),触发时间 ...
- cpu使用率_单片机里面的CPU使用率是什么鬼?
打开电脑的任务管理器,看着跳动的CPU使用率,发现很舒服.每一个线程占用了多少CPU清清楚楚,也就能针对性的确认为啥你的电脑跑的慢了. 今天这篇笔记不讲每个任务(或线程)CPU的使用情况,而是单片机整 ...
- Linux下内存使用率、CPU使用率、以及运行原理-转
Linux下内存使用率.CPU使用率.以及运行原理 Linux下怎样查看机器配置啊?cpu/内存/硬盘 dmesg 显示开机信息.kernel会将开机信息存储在ring buffer中.您若是开机时来 ...
最新文章
- linux + ffmpeg + eclipse 调试
- 软件缺陷预测的两种定义
- 《解释性机器学习》笔记(五):Rule Fit 规则拟合
- /bin/bash: [xxxx]: command not found
- mysql语句性能开销检测profiling详解
- 什么样的代码是好代码_什么是好代码?
- 架构语言ArchiMate -应用层(Application Layer)
- Qt4_使用SAX读取XML
- 《Spring Recipes》第二章笔记:Customizing Bean Initiali...
- JFinal源码解析--从请求到处理返回流程
- wps或者word点击打印预览时出现空白页,不显示内容
- 《分形艺术,当科学嫁给了艺术》作者:林晨 风达
- 常用计算机技能大全,八个超实用的电脑技能( 快收藏!)
- android 手机安装windows7,安卓手机安装运行Win7系统教程(图文)
- docker制作镜像的方法
- PhpSpreadsheet中文文档 | Spreadsheet操作教程实例
- 红米note7找android,红米 NOTE7 PRO简易测评与去广告
- WPF DataGridTable
- [iOS开发]iOS中的Hash
- 李嘉诚在香港做支付,为何要牵手马云?