当前位置: 首页 > article >正文

K8S学习之基础三十七:prometheus监控node资源

Prometheus v2.2.1

​ 编写yaml文件,包含创建ns、configmap、deployment、service

# 创建monitoring空间
vi prometheus-ns.yaml 
apiVersion: v1
kind: Namespace
metadata:name: monitor-sa# 创建SA并绑定权限
kubectl create serviceaccount monitor -n monitor-sa
kubectl create clusterrolebinding monitor-clusterrolebinding -n monitor-sa --clusterrole=cluster-admin  --serviceaccount=monitor-sa:monitor
kubectl create clusterrolebinding monitor-clusterrolebinding-1  -n monitor-sa --clusterrole=cluster-admin   --user=system:serviceaccount:monitor-sa:monitor# 创建cm、deployment、svc
apiVersion: v1
kind: ConfigMap
metadata:labels:app: prometheusname: prometheus-confignamespace: monitor-sa
data:prometheus.yml: |global:scrape_interval: 15sscrape_timeout: 10sevaluation_interval: 1mscrape_configs:- job_name: 'kubernetes-node'kubernetes_sd_configs:- role: noderelabel_configs:- source_labels: [__address__]regex: '(.*):10250'replacement: '${1}:9100'target_label: __address__action: replace- action: labelmapregex: __meta_kubernetes_node_label_(.+)- job_name: 'kubernetes-node-cadvisor'kubernetes_sd_configs:- role:  nodescheme: httpstls_config:ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crtbearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/tokenrelabel_configs:- action: labelmapregex: __meta_kubernetes_node_label_(.+)- target_label: __address__replacement: kubernetes.default.svc:443- source_labels: [__meta_kubernetes_node_name]regex: (.+)target_label: __metrics_path__replacement: /api/v1/nodes/${1}/proxy/metrics/cadvisor- job_name: 'kubernetes-apiserver'kubernetes_sd_configs:- role: endpointsscheme: httpstls_config:ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crtbearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/tokenrelabel_configs:- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_po
rt_name]action: keepregex: default;kubernetes;https- job_name: 'kubernetes-service-endpoints'kubernetes_sd_configs:- role: endpointsrelabel_configs:- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]action: keepregex: true- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]action: replacetarget_label: __scheme__regex: (https?)- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]action: replacetarget_label: __metrics_path__regex: (.+)- source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]action: replacetarget_label: __address__regex: ([^:]+)(?::\d+)?;(\d+)replacement: $1:$2- action: labelmapregex: __meta_kubernetes_service_label_(.+)- source_labels: [__meta_kubernetes_namespace]action: replacetarget_label: kubernetes_namespace- source_labels: [__meta_kubernetes_service_name]action: replacetarget_label: kubernetes_name 
---
apiVersion: apps/v1
kind: Deployment
metadata:name: prometheus-servernamespace: monitoringlabels:app: prometheus
spec:replicas: 1selector:matchLabels:app: prometheuscomponent: server#matchExpressions:#- {key: app, operator: In, values: [prometheus]}
---
apiVersion: v1
kind: Service
metadata:name: prometheusnamespace: monitor-salabels:app: prometheusannotations:        # 增加注解,可被prometheus监控到prometheus.io/scrape: "true"    
spec:type: NodePortports:- port: 9090targetPort: 9090protocol: TCPselector:app: prometheuscomponent: server[root@mast01 prometheus]# kubectl get pod -n monitor-sa
NAME                         READY   STATUS    RESTARTS   AGE
prometheus-dfdfb9d79-h4tk4   1/1     Running   0          22h
[root@mast01 prometheus]# kubectl get svc -n monitor-sa
NAME         TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
prometheus   NodePort   10.109.44.37   <none>        9090:30090/TCP   22h
[root@mast01 prometheus]# curl 10.109.44.37:9090
<a href="/graph">Found</a>.[root@mast01 prometheus]# kubectl get ep -n monitor-sa
NAME         ENDPOINTS            AGE
prometheus   10.244.140.67:9090   22h
[root@mast01 prometheus]# curl 172.16.80.131:30090
<a href="/graph">Found</a>.

浏览器访问 172.16.80.131:30090

node-exporter组件安装和配置

​ node-exporter可以采集机器(物理机、虚拟机、云主机等)的监控指标数据,能够采集到的指标包括CPU, 内存,磁盘,网络,文件数等信息。

# 上传node-exporter.tar.gz到harbor
docker load -i node-exporter.tar.gz
docker tag prom/node-exporter:v0.16.0 172.16.80.140/node-exporter/node-exporter:v0.16.0
docker push 172.16.80.140/node-exporter/node-exporter:v0.16.0
# 创建daemon控制器的yaml
[root@mast01 prometheus]#  vi node-export.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:name: node-exporternamespace: monitor-salabels:name: node-exporter
spec:selector:matchLabels:name: node-exportertemplate:metadata:labels:name: node-exporterspec:hostPID: truehostIPC: truehostNetwork: truecontainers:- name: node-exporterimage: 172.16.80.140/node-exporter/node-exporter:v0.16.0imagePullPolicy: IfNotPresentports:- containerPort: 9100resources:requests:cpu: 0.15securityContext:privileged: trueargs:- --path.procfs- /host/proc- --path.sysfs- /host/sys- --collector.filesystem.ignored-mount-points- '"^/(sys|proc|dev|host|etc)($|/)"'volumeMounts:- name: devmountPath: /host/dev- name: procmountPath: /host/proc- name: sysmountPath: /host/sys- name: rootfsmountPath: /rootfstolerations:- key: "node-role.kubernetes.io/control-plane"operator: "Exists"effect: "NoSchedule"volumes:- name: prochostPath:path: /proc- name: devhostPath:path: /dev- name: syshostPath:path: /sys- name: rootfshostPath:path: /
# hostNetwork、hostIPC、hostPID都为True时,表示这个Pod里的所有容器,会直接使用宿主机的网络,直接与宿主机进行IPC(进程间通信)通信,可以看到宿主机里正在运行的所有进程。加入了hostNetwork:true会直接将我们的宿主机的9100端口映射出来,从而不需要创建service 在我们的宿主机上就会有一个9100的端口

​ 该yaml会在每个节点上部署一个node-exporter

[root@mast01 prometheus]# netstat -an | grep 9100
tcp6       0      0 :::9100                 :::*                    LISTEN
[root@mast01 prometheus]# kubectl get pods -n monitor-sa -owide
NAME                 READY STATUS  RESTARTS AGE IP            NODE   NOMINATED NODE   READINESS GATES
node-exporter-5ms5j  1/1   Running 0        7s  172.16.80.133 node02 <none>    <none>
node-exporter-dgg2z  1/1   Running 0        9s  172.16.80.131 mast01 <none>    <none>
node-exporter-k4mf5  1/1   Running 0        6s  172.16.80.132 node01 <none>    <none>

​ 通过curl可获取主机信息

[root@mast01 prometheus]# curl http://172.16.80.131:9100/metrics | more% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0.00010856
go_gc_duration_seconds{quantile="0.25"} 0.00010856
go_gc_duration_seconds{quantile="0.5"} 0.000879866
go_gc_duration_seconds{quantile="0.75"} 0.000879866
go_gc_duration_seconds{quantile="1"} 0.000879866
go_gc_duration_seconds_sum 0.000988426
go_gc_duration_seconds_count 2
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 6
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.9.6"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 1.863448e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 5.928912e+06
......
curl http://172.16.80.131:9100/metrics | grep node_cpu_seconds   # 显示cpu使用情况% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100 91593  100 91593    0     0  6934k      0 --:--:-- # HELP node_cpu_seconds_total Seconds the cpus spent in each mode.
--:--# TYPE node_cpu_seconds_total counter     # counter类型,只增不减
:--node_cpu_seconds_total{cpu="0",mode="idle"} 74516.69-node_cpu_seconds_total{cpu="0",mode="iowait"} 13.52
-:node_cpu_seconds_total{cpu="0",mode="irq"} 0
--node_cpu_seconds_total{cpu="0",mode="nice"} 0.03
:-node_cpu_seconds_total{cpu="0",mode="softirq"} 76.96
- node_cpu_seconds_total{cpu="0",mode="steal"} 0
74node_cpu_seconds_total{cpu="0",mode="system"} 601.74
53node_cpu_seconds_total{cpu="0",mode="user"} 1234.91
knode_cpu_seconds_total{cpu="1",mode="idle"} 74511.08node_cpu_seconds_total{cpu="1",mode="iowait"} 24.89
node_cpu_seconds_total{cpu="1",mode="irq"} 0
node_cpu_seconds_total{cpu="1",mode="nice"} 0.18
node_cpu_seconds_total{cpu="1",mode="softirq"} 86.84
node_cpu_seconds_total{cpu="1",mode="steal"} 0
node_cpu_seconds_total{cpu="1",mode="system"} 598.25
node_cpu_seconds_total{cpu="1",mode="user"} 1217.33curl http://172.16.80.131:9100/metrics | grep node_load # 最近一分钟内负载使用情况% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0# HELP node_load1 1m load average.
# TYPE node_load1 gauge   # gauge类型,可增可减
node_load1 0.27
# HELP node_load15 15m load average.
# TYPE node_load15 gauge
node_load15 0.42
# HELP node_load5 5m load average.
# TYPE node_load5 gauge
node_load5 0.43
100 91584  100 91584    0     0  8262k      0 --:--:-- --:--:-- --:--:-- 8943k

通过prometheus,可以看到监控对象

image-20250319141749504

image-20250319141206344

image-20250319141321144

Graph选择对应指标和周期,可以打印出指标图形

image-20250319141536902

prometheus热加载:

svc配置修改后,prometheus并不会马上更新配置,可以通过reload这个svc对应pod的配置,这样比较安全快速的使prometheus进行了热加载,并不会对其他产生影响

# 获取svc对应的pod的ip
kubectl get pods -owide
# 热加载
curl -X POST http://podip:9090/-/reload

如果直接删除prometheus,加载配置,也可以达到更新目的,但这种暴力加载会使监控数据丢失,不建议使用

相关文章:

K8S学习之基础三十七:prometheus监控node资源

Prometheus v2.2.1 ​ 编写yaml文件&#xff0c;包含创建ns、configmap、deployment、service # 创建monitoring空间 vi prometheus-ns.yaml apiVersion: v1 kind: Namespace metadata:name: monitor-sa# 创建SA并绑定权限 kubectl create serviceaccount monitor -n monito…...

#mapreduce打包#maven:could not resolve dependencies for project

打包报错&#xff1a; #报错信息&#xff1a; [ERROR] Failed to execute goal on project mapreduce_teacher1: Could not resolve dependencies for project org.example:mapreduce_teacher1:jar:1.0-SNAPSHOT: Failed to collect dependencies at org.apache.hive:hive-exe…...

QT软件匠心开发,塑造卓越设计服务

在当今这个数字化飞速发展的时代&#xff0c;软件已经成为我们生活中不可或缺的一部分。而QT&#xff0c;作为一款跨平台的C图形用户界面应用程序开发框架&#xff0c;凭借其强大的功能和灵活性&#xff0c;在众多软件开发工具中脱颖而出。我们深知&#xff0c;在软件开发领域&…...

田间机器人幼苗视觉检测与护苗施肥装置研究(大纲)

田间机器人幼苗视觉检测与护苗施肥装置研究 基于多光谱视觉与精准施肥的农业机器人系统设计 第一章 绪论 1.1 研究背景与意义 农业智能化需求&#xff1a; 传统幼苗检测依赖人工&#xff0c;效率低且易遗漏弱苗/病苗施肥不精准导致资源浪费和环境污染 技术挑战&#xff1a;…...

生物化学笔记:医学免疫学原理 免疫系统的组成与功能+克隆选择学说

免疫系统的组成与功能 克隆选择学说 克隆选择学说&#xff08;Clonal Selection Theory&#xff09;是免疫学的核心理论之一&#xff0c;由 麦克法兰伯内特&#xff08;Frank Macfarlane Burnet&#xff09; 在 1957 年提出&#xff0c;用于解释特异性免疫反应的机制。 基本概…...

Android 15 获取网络切片信息的标准接口

相关术语 简称全称中文说明URSPUE Route Selection Policy用户路由选择策略URSP 是 5G 核心网(PCF)下发给 UE 的策略,用于指导应用流量如何路由到不同的网络切片或 PDU 会话。其包含多个规则,每条规则由 优先级、业务描述符(Traffic Descriptor) 和 路由选择描述符(Rout…...

MySql创建分区表并且按月分区

前言 在mysql中&#xff0c;按月份分区&#xff0c;再使用分区字段时间来查询数据将会很快&#xff0c;因为这样只需要扫描指定的分区。因此&#xff0c;在处理大量数据时&#xff0c;使用分区表是一个非常好的选择。 1、创建表&#xff0c;并使用RANGE COLUMNS分区 按创建时间…...

招聘面试季--一文顿悟,Java中字节流和字符流的区别及使用场景上的差异

‌一、核心区别‌ ‌特性‌‌字节流‌‌字符流‌‌数据单位‌以字节&#xff08;8-bit&#xff09;为单位处理数据&#xff08;如0xA1&#xff09;以字符&#xff08;16-bit Unicode&#xff09;为单位处理数据&#xff08;如A, 你&#xff09;‌基类‌InputStream / OutputSt…...

使用【docker】+【shell】脚本半自动化部署微服务项目

一.前言 以下是一个基于 ‌Docker Shell脚本‌ 的半自动化部署方案&#xff0c;包含镜像构建、容器管理、网络配置和日志监控等核心功能&#xff0c;适用于大多数Web应用或微服务项目。 二‌.目录结构 三.脚本代码实现 1.‌Shell脚本实现 (deploy.sh) #!/bin/bash# 设置颜…...

uni-app——计时器和界面交互API

API 基本概要 概念说明 API&#xff08;应用程序接口&#xff09;是预先定义的方法集合&#xff0c;用于实现特定功能。在 uni-app 中&#xff0c;通过全局对象 uni 调用 API&#xff0c;例如 uni.getSystemInfoSync 获取设备信息。 API 分类与调用规则 事件监听型 以 on 开…...

使用 GitHub 可重用工作流和 GitHub Actions 简化 DevOps

在当今的 DevOps 环境中&#xff0c;自动化是开发团队能够更快地交付功能并维护高质量代码库的关键。这就是像 GitHub Actions 这样的工具变得不可或缺的地方&#xff0c;因为它能够直接在存储库中自动化、自定义和执行 GitHub 工作流程。 当然&#xff0c;随着项目的规模和存…...

深入理解MySQL日志机制

目录 1. MySQL日志概述 2. 错误日志&#xff08;Error Log&#xff09; 2.1 错误日志的作用 2.2 错误日志的配置 2.3 查看错误日志 3. 二进制日志&#xff08;Binary Log&#xff09; 3.1 二进制日志的作用 3.2 二进制日志的配置 3.3 查看二进制日志 3.4 二进制日志的…...

Sql Server 索引性能优化 分析以及分表

定位需优化语句 根据工具 skywking 或者开启慢查询日志 找到 慢sql 的语句根据 执行过程 来 判断 慢的原因 row filter 指标 看查了多少数据 比例多少 type 看下是单表 还是 join联表 比如 执行步骤多 没索引 优化方向 减少执行次数索引 没索引考虑加索引 加索引 尽量选择 i…...

vue使用element-ui自定义样式思路分享【实操】

前言 在使用第三方组件时&#xff0c;有时候组件提供的默认样式不满足我们的实际需求&#xff0c;需要对默认样式进行调整&#xff0c;这就需要用到样式穿透。本篇文章以vue3使用element-ui的Tabs组件&#xff0c;对Tabs组件的添加按钮样式进行客制化为例。 确定需要修改的组…...

2020年全国职业院校技能大赛改革试点赛高职组“云计算”竞赛赛卷第二场次题目:容器云平台部署与运维

2020年全国职业院校技能大赛改革试点赛高职组 “云计算”竞赛赛卷 第二场次题目:容器云平台部署与运维 说明:本任务提供有2台服务器master和node,都安装了centos7.5操作系统,在/opt/centos目录下有CentOS-7-x86_64-DVD-1804系统光盘文件所有文件,在/opt/containerk8s目…...

PowerBI 条形图,解决数据标签在条形内部看不清的问题

比如下面的条形图&#xff1a; 最上面两行&#xff0c;数据标签显示在了条形内部&#xff0c;哪怕设置了值为黑色 字体也会自动切换为白色&#xff0c;如果设计要求条形的颜色是浅色&#xff0c;就会导致数据看不清晰。 解决方法一&#xff1a; 将数据标签位置设置为端外 效果…...

下载与快速上手 NVM:Node.js 版本管理工具

一、准备工作&#xff1a;卸载旧版 Node.js 重要提示&#xff1a;在安装 NVM 前&#xff0c;请先彻底删除已安装的 Node.js&#xff0c;避免路径冲突&#xff1a; 检查安装路径 bash where node常见路径&#xff1a; C:\Program Files\nodejs\C:\Users\用户名\AppData\Local\n…...

网络防火墙(Firewall)、Web防火墙(WAF)、入侵检测系统(IDS)、入侵防御系统(IPS)对比总结

目录 一、Firewall、WAF、IDS、IPS四种设备简介 二、Firewall、WAF、IDS、IPS四种设备的角色定位 三、防火墙&#xff08;Firewall&#xff09;与入侵检测系统&#xff08;IPS&#xff09;的区别 四、入侵检测系统&#xff08;IDS&#xff09;与入侵防御系统&#xff08;IP…...

Unity | 游戏数据配置

目录 一、ScriptableObject 1.创建ScriptableObject 2.创建asset资源 3.asset资源的读取与保存 二、Excel转JSON 1.Excel格式 2.导表工具 (1)处理A格式Excel (2)处理B格式Excel 三、解析Json文件 1.读取test.json文件 四、相关插件 在游戏开发中,策划…...

IT工具 | node.js 进程管理工具 PM2 大升级!支持 Bun.js

P(rocess)M(anager)2 是一个 node.js 下的进程管理器&#xff0c;内置负载均衡&#xff0c;支持应用自动重启&#xff0c;常用于生产环境运行 node.js 应用&#xff0c;非常好用&#x1f44d; &#x1f33c;概述 2025-03-15日&#xff0c;PM2发布最新版本v6.0.5&#xff0c;这…...

VulnHub-Web-Machine-N7通关攻略

一、信息收集 第一步&#xff1a;确定靶机IP为192.168.0.107 第二步&#xff1a;扫描后台及开放端口 第三步&#xff1a;进行敏感目录及文件扫描 http://192.168.0.107/index.html (CODE:200|SIZE:1620) http://192.168.0.107/server-status (CODE:403|SIZ…...

发现一个好用的Vue.js内置组件

目录 一、这个好用的内置组件是什么&#xff1f; 二、这个组件的主要功能 三、怎么使用&#xff1f; 四、使用注意事项 五、我的使用场景 一、这个好用的内置组件是什么&#xff1f; 今天在优化我的平台应用时&#xff0c;发现一个好用的组件标签--<keep-alive>。 …...

论华为 Pura X 折叠屏性能检测

在科技浪潮中&#xff0c;折叠屏手机以其创新形态掀起市场热潮。华为 Pura X 作为华为最新折叠手机&#xff0c;承载前沿科技与精湛工艺&#xff0c;成为行业焦点。它融合先进折叠屏技术与优质材质&#xff0c;致力于打破传统手机使用边界&#xff0c;为用户开启全新体验。但产…...

生成PDF文件:从html2canvas和jsPdf渲染到Puppeteer矢量图

刚刚实现而已&#xff1a;第一次明白&#xff0c;双击或file:///打开html文件&#xff0c;居然和从localhost:3000打开同一个html文件有本质的区别。 字体居然还能以Base64代码嵌入到网页&#xff0c;只是太大太笨。 需要安装node.js&#xff0c;npm安装更多依赖&#xff1a;…...

在 Elasticsearch 中探索基于 NVIDIA 的 GPU 加速向量搜索

作者&#xff1a;来自 Elastic Chris Hegarty 及 Hemant Malik 由 NVIDIA cuVS 提供支持&#xff0c;此次合作旨在为开发者在 Elasticsearch 中的向量搜索提供 GPU 加速。 在 Elastic Engineering 组织内&#xff0c;我们一直致力于优化向量数据库的性能。我们的使命是让 Lucen…...

Junit在测试过程中的使用方式,具体使用在项目测试中的重点说明

JUnit 是一个广泛使用的 Java 单元测试框架,主要用于编写和运行可重复的测试。以下是 JUnit 在项目测试中的使用方式和重点说明: 1. 基本使用 场景:测试一个简单的 Java 类。 示例: import org.junit.Test; import static org.junit.Assert.*;public class CalculatorTe…...

关于CNN,RNN,GAN,GNN,DQN,Transformer,LSTM,DBN你了解多少

以下是神经网络中常见的几种模型的简要介绍&#xff1a; 1. ​CNN (Convolutional Neural Network, 卷积神经网络) ​用途: 主要用于图像处理和计算机视觉任务。​特点: 通过卷积核提取局部特征&#xff0c;具有平移不变性&#xff0c;能够有效处理高维数据&#xff08;如图像…...

asp.net 4.5在医院自助系统中使用DeepSeek帮助医生分析患者报告

环境&#xff1a; asp.net 4.5Visual Studio 2015本地已经部署deepseek-r1:1.5b 涉及技术 ASP.NET MVC框架用于构建Web应用程序。使用HttpWebRequest和HttpWebResponse进行HTTP请求和响应处理。JSON序列化和反序列化用于构造和解析数据。SSE&#xff08;服务器发送事件&#xf…...

HeyGem.ai 全离线数字人生成引擎加入 GitCode:开启本地化 AIGC 创作新时代

在人工智能技术飞速演进的时代&#xff0c;数据隐私与创作自由正成为全球开发者关注的焦点。硅基智能旗下开源项目 HeyGem.ai 近日正式加入 GitCode&#xff0c;以全球首个全离线数字人生成引擎的颠覆性技术&#xff0c;重新定义人工智能生成内容&#xff08;AIGC&#xff09;的…...

密码协议与网络安全——引言

三个基本概念 计算机安全&#xff08;Computer Security&#xff09;&#xff1a;对于一个自动化的信息系统&#xff0c;采取保护措施确保信息系统资源&#xff08;包括硬件、软件、固件、信息、数据和通信&#xff09;的保密性、完整性和可用性。 网络安全&#xff08;Netwo…...