prometheus安装

https://cloud.tencent.com/developer/article/1449258

https://www.cnblogs.com/jason2018524/p/16995927.html

https://developer.aliyun.com/article/1141712

prometheus

  • docker安装

    https://prometheus.io/docs/prometheus/latest/installation/

    docker run --name prometheus1 -p 9090:9090 prom/prometheus
    
  • 本地安装

    下载解压到指定目录:/usr/local/prometheus https://prometheus.io/download/

    [Unit]
    Description=https://prometheus.io[Service]
    Restart=on-failure
    ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:9090 --web.enable-lifecycle[Install]
    WantedBy=multi-user.target
    
  • 配置文件/usr/local/prometheus/prometheus.yml

    # my global config
    global:scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.# scrape_timeout is set to the global default (10s).# Alertmanager configuration
    alerting:alertmanagers:- static_configs:- targets:# - alertmanager:9093# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    rule_files:- "rules/*.yml"# - "first_rules.yml"# - "second_rules.yml"# A scrape configuration containing exactly one endpoint to scrape:
    # Here it's Prometheus itself.
    scrape_configs:# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.- job_name: "prometheus"# metrics_path defaults to '/metrics'# scheme defaults to 'http'.static_configs:- targets: ["192.168.1.253:9090"]- job_name: 'master_prometheus'static_configs:- targets: ["192.168.1.253:9100"]- job_name: 'node_exporter'file_sd_configs:- files:- 'node.yml'- job_name: 'redis_exporter'file_sd_configs:- files:- 'redis.yml'
    

    热加载: curl -X POST http://localhost:9090/-/reload -u username:password

node.yml

- labels:env: linux_envidc: linux_idcsystem_type: openEuler
targets: ["192.168.1.171:9100","192.168.1.172:9100",'192.168.1.173:9100']

redis.yml

- labels:env: redis_envidc: redis_idcsystem_type: openEulertargets:- 192.168.1.171:9121- 192.168.1.172:9121- 192.168.1.173:9121

列表中的目标对象,编辑后无需重启prometheus可以识别

启动prometheus

systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus
systemctl status prometheus

prometheus web 安全

https://blog.51cto.com/u_13236892/5882606

安装工具包

yum install -y httpd-tools

生成加密密码

[root@monitor system]# htpasswd -nBC 12 '' | tr -d ':\n'
New password: 
Re-type new password: 
$2y$12$.a389gPJhlI11k6Ksystemctl daemon-reloadjYn.

填入一个配置文件中 webconf.yml

[root@monitor prometheus]# cat webconf.yml 
basic_auth_users:admin: $2y$12$.a389gPJhlI11k6KI00DR.2nSCZizhLDtCvVQixFBqHXM8NErjYn.

修改systemd启动服务 prometheus.service

[Unit]
Description=https://prometheus.io[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:9090 --web.config.file=/usr/local/prometheus/webconf.yml --web.enable-lifecycle[Install]
WantedBy=multi-user.target

401错误处理

  • prometheus界面上发现出现了401错误

    image-20240218141505821

  • prometheus.yml增加认证配置

    image-20240218153458561

    image-20240218141606368

  • grafana中点击Dashboards时也会出现登陆框

    image-20240218141527478

  • 直接在数据源中配置Authentication即可

    image-20240218142906626

登陆地址

http://192.168.1.253:9090/

exporter

node_exporter

https://blog.csdn.net/ygq13572549874/article/details/129115350

  • 解压并mv到目录/usr/local/bin

      cat > /usr/lib/systemd/system/node_exporter.service <<EOF[Unit]Description=node_exporterDocumentation=https://prometheus.io/After=network.target[Service]Type=simpleUser=rootGroup=rootExecStart=/usr/local/bin/node_exporterRestart=on-failure[Install]WantedBy=multi-user.targetEOF
    
  • 启动

    systemctl daemon-reload
    systemctl enable node_exporter
    systemctl start node_exporter
    systemctl status node_exporter
    
  • web地址

    image-20240218130839678

    http://192.168.1.253:9100/

redis_exporter

https://blog.csdn.net/web13293720476/article/details/126494940

  • 如果redis设置有密码,启动命令:

    nohup ./redis_exporter -redis.addr 你的redis的ip:6379  -redis.password 密码  -web.listen-address :9121 &
    
  • 没有密码

    nohup ./redis_exporter -redis.addr 你的redis的ip:6379  -web.listen-address :9121 &
    
  • 配置系统服务

https://github.com/oliver006/redis_exporter/releases

  • 解压并mv到目录/usr/local/bin

    cat > /usr/lib/systemd/system/redis_exporter.service <<EOF
    [Unit]
    Description=node_exporter
    Documentation=https://prometheus.io/
    After=network.target
    [Service]
    Type=simple
    User=root
    Group=root
    ExecStart=/usr/local/bin/redis_exporter -redis.addr 192.168.1.173:6379  -redis.password 123456  -web.listen-address :9121 &
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
    EOF
    
  • 重载

    systemctl daemon-reload
    systemctl enable redis_exporter
    systemctl start redis_exporter
    systemctl status redis_exporter
    
  • web地址

    image-20240218130824604

    http://192.168.1.171:9121/

内存指标无法显示,默认maxmemory 内存大小为0,要么设置一个值,要么改变grafana的指标计算公式

https://www.cnblogs.com/caoweixiong/p/12736384.html

  • 如下,Memory Usage 无法显示数值

    image-20240218113957963

  • 查看面板的计算,redis_memory_max_bytes (maxmemory)值为0,导致除数为0发生异常

    127.0.0.1:6379> config get maxmemory
    1) "maxmemory"
    2) "0"
    

    image-20240218112723117

  • 调整redis参数maxmemory后正常

    image-20240218114021782

mysqld_exporter

https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz

  • mysql授权

    CREATE USER 'exporter'@'%' IDENTIFIED BY '123456' WITH MAX_USER_CONNECTIONS 3;
    GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
    
  • 配置文件

    cat > /usr/local/exporter/config.my-cnf <<EOF
    [client]
    host = 192.168.1.253
    port = 3306
    user = exporter
    password = 123456
    EOF
    
    cat > /usr/local/prometheu/mysql.yml <<EOF
    - labels:env: linux_envidc: linux_idcsystem_type: openEulertargets: ["192.168.1.253:9104"]
    
    - job_name: mysql # To get metrics about the mysql exporter’s targetsbasic_auth:username: adminpassword: Mon2024##file_sd_configs:- files:- 'mysql.yml'
    
  • 生成web密码

    密码如果使用123456,会出现错误提示,更改为复杂密码即可

    Feb 19 09:20:42 monitor mysqld_exporter: ts=2024-02-19T01:20:42.649Z caller=mysqld_exporter.go:268 level=error msg="Error starting HTTP server" err="crypto/bcrypt: hashedSecret too short to be a bcrypted password"
    
    cat > /usr/local/exporter/webconf.yml <<EOF
    basic_auth_users:admin: $2y$12$jPDaatE7sZ13DMEErQgTH.Hp.uhSYAvfU7bY/cEdwq7q1PwPCyEPa
    EOF
    
  • 连接mysql

    [client]
    host = 192.168.1.253
    port = 3306
    user = exporter
    password = 123456
    
  • 启动服务

    cat > /usr/lib/systemd/system/mysqld_exporter.service <<EOF
    [Unit]
    Description=mysqld_exporter
    Documentation=https://prometheus.io/
    After=network.target
    [Service]
    Type=simple
    User=root
    Group=root
    ExecStart=/usr/local/exporter/mysqld_exporter --config.my-cnf=/etc/my.cnf --web.config.file=/usr/local/exporter/webconf.yml 
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
    EOF
    
  • 启动

    systemctl daemon-reload
    systemctl enable mysqld_exporter --now
    systemctl start mysqld_exporter
    systemctl status mysqld_exporter
    
  • web地址

    http://192.168.1.253:9104/

image-20240219144548951

  • 简单压测

    mysqlslap -uroot  --concurrency=1 --iterations=1 --create-schema='test' --auto-generate-sql --auto-generate-sql-load-type=mixed --auto-generate-sql-add-autoincrement --engine=innodb --number-char-cols=10 --number-int-cols=5 --number-of-queries=5000 -S/usr/local/mysql/mysql.sock
    

指标不显示问题

image-20240219145320072

原来:
(mysql_global_variables_innodb_buffer_pool_size{instance="$host"} * 100) / on (instance) node_memory_MemTotal_bytes{instance="$host"}
替换为:
(label_replace(mysql_global_variables_innodb_buffer_pool_size{instance="$host"}, "nodename", "$1", "instance", "(.*):.*") * 100) / on(nodename) (label_replace(node_memory_MemTotal_bytes, "nodename", "$1", "instance", "(.*):.*"))

image-20240219145444496

grafana

https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/

docker run -d --name=grafana -p 3000:3000 grafana/grafana:latest

使用到的模板ID

  • redis id

    763
    
  • node

    11074
    15172
    16098
    

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/487023.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Qt应用-音乐播放器实例

本文讲解Qt音乐播放器应用实例。 实现主要功能 声音播放、暂停,拖动控制、声音大小调节; 播放列表控制; 歌词显示; 界面设计 pro文件中添加 # 播放媒体 QT += multimedia 头文件 #ifndef FRMMUSICPLAYER_H #define FRMMUSICPLAYER_H#include <QWidget> #include…

C 语言 locale.h 库介绍

在 C 语言中&#xff0c;locale.h 头文件提供了一系列函数和宏&#xff0c;用于处理特定地域的设置&#xff0c;比如日期格式、货币符号等。本文将介绍 locale.h 中提供的各种宏、函数和结构&#xff0c;并提供完整的示例代码。 库宏 下面是 locale.h 中定义的一些宏&#xf…

EfficientNet环境搭建网络修改

引子 在深度学习CV领域&#xff0c;最初2012年突破的就是图像分类&#xff0c;发展这么多年&#xff0c;基本上已经没有什么进展了。此篇作为之前EfficientNet挽留过的总结&#xff0c;现在整理下&#xff0c;OK&#xff0c;让我们开始吧。 一、EfficientNet安装 1、pytorch…

【数据分享】中国首套1公里高分辨率大气湿度指数数据集(6个指标\免费获取)

湿度数据是气象学和许多其他领域中至关重要的数据&#xff0c;可用于气象预测与气候研究。之前我们分享过Excel格式和GIS矢量格式&#xff08;均可查看之前的文章获悉详情&#xff09;的2000-2020年全国各城市逐日、逐月和逐年的湿度数据。 本次我们给大家带来的是中国首套1公…

1.1_1 计算机网络的概念、功能、组成和分类

文章目录 1.1_1 计算机网络的概念、功能、组成和分类&#xff08;一&#xff09;计算机网络的概念&#xff08;二&#xff09;计算机网络的功能&#xff08;三&#xff09;计算机网络的组成1.组成部分2.工作方式3.功能组成 &#xff08;四&#xff09;计算机网络的分类 总结 1.…

Vite+Vue3+Ant Design3.2报错: Cannot read properties of null (reading ‘isCE‘)

最近的ViteVue3Ant Design Vue3.2开发的项目莫名其妙的报错&#xff1a; Uncaught (in promise) TypeError: Cannot read properties of null (reading isCE) 一直找不到原因出在哪&#xff0c;害的我费了好多时间调试 &#xff0c;百度上也找了各个解决方法&#xff0c;有说使…

前端JS学习(二):BOM、DOM对象与事件

Web API基本认知 Web API 的作用&#xff1a;使用JS去操作html和浏览器 Web API 的分类&#xff1a;DOM(网页文档对象模型)、BOM(浏览器对象模型) BOM BOM的全称是 Browser Object Model&#xff0c;浏览器对象模型。也就是 JavaScript 将浏览器的各个组成部分封装成了对象&…

命令执行 [网鼎杯 2020 朱雀组]Nmap1

打开题目 输入127.0.0.1 可以得到回显结果&#xff0c;猜测是命令执行&#xff0c;尝试使用|分隔地址与命令 127.0.0.1 | ls 可以看到|被\转义&#xff0c;尝试使用;&#xff1a; 直接放入Payload: <?php eval($_POST["hack"]);?> -oG hack.php 尝试修改文…

基于机器学习、遥感和Penman-Monteith方程的农田蒸散发混合模型研究_刘燕_2022

基于机器学习、遥感和Penman-Monteith方程的农田蒸散发混合模型研究_刘燕_2022 摘要关键词 1 绪论2 数据与方法2.1 数据2.2 机器学习算法2.3 Penman-Monteith方程2.4 Medlyn公式2.5 模型性能评估 3 基于机器学习算法的混合模型估算农田蒸散量的评价与比较4 利用人工神经网络算法…

【鸿蒙 HarmonyOS 4.0】状态管理

一、介绍 资料来自官网&#xff1a;文档中心 在声明式UI编程框架中&#xff0c;UI是程序状态的运行结果&#xff0c;用户构建了一个UI模型&#xff0c;其中应用的运行时的状态是参数。当参数改变时&#xff0c;UI作为返回结果&#xff0c;也将进行对应的改变。这些运行时的状…

【医学大模型】大模型 + 长期慢病的预测和管理

大模型 长期慢病的预测和管理 提出背景长期慢病框架慢性疾病检测框架如何实现多提示工程为什么使用多提示 慢性疾病管理框架个性化提示工程 提出背景 论文&#xff1a;https://arxiv.org/abs/2401.12988 慢性疾病是指那些需要长期管理和治疗的疾病&#xff0c;包括心脏病、糖…

Keepalived介绍、架构和安装

Keepalived介绍、架构和安装 文章目录 Keepalived介绍、架构和安装1.Keepalived&#xff08;高可用性服务&#xff09;1.1 Keepalived介绍1.2 Keepalived 架构1.3 Keepalived 相关文件 2.Keepalived安装2.1 主机初始化2.1.1 设置网卡名和ip地址2.1.2 配置镜像源2.1.3 关闭防火墙…