prometheus安装

news2024/10/5 21:24:02

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_env
  idc: linux_idc
  system_type: openEuler
targets: ["192.168.1.171:9100","192.168.1.172:9100",'192.168.1.173:9100']

redis.yml

- labels:
    env: redis_env
    idc: redis_idc
    system_type: openEuler
  targets:
    - 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_exporter
      Documentation=https://prometheus.io/
      After=network.target
      [Service]
      Type=simple
      User=root
      Group=root
      ExecStart=/usr/local/bin/node_exporter
      Restart=on-failure
      [Install]
      WantedBy=multi-user.target
      EOF
    
  • 启动

    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_env
        idc: linux_idc
        system_type: openEuler
      targets: ["192.168.1.253:9104"]
    
    - job_name: mysql # To get metrics about the mysql exporter’s targets
        basic_auth:
          username: admin
          password: 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.coloradmin.cn/o/1463431.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

二.西瓜书——线性模型、决策树

第三章 线性模型 1.线性回归 “线性回归”(linear regression)试图学得一个线性模型以尽可能准确地预测实值输出标记. 2.对数几率回归 假设我们认为示例所对应的输出标记是在指数尺度上变化&#xff0c;那就可将输出标记的对数作为线性模型逼近的目标&#xff0c;即 由此&…

unity-firebase-Analytics分析库对接后数据不显示原因,及最终解决方法

自己记录一下unity对接了 FirebaseAnalytics.unitypackage&#xff08;基于 firebase_unity_sdk_10.3.0 版本&#xff09; 库后&#xff0c;数据不显示的原因及最终显示解决方法&#xff1a; 1. 代码问题&#xff08;有可能是代码写的问题&#xff0c;正确的代码如下&#xff…

分布式系统一致性与共识算法

分布式系统的一致性是指从系统外部读取系统内部的数据时&#xff0c;在一定约束条件下相同&#xff0c;即数据&#xff08;元数据&#xff0c;日志数据等等&#xff09;变动在系统内部各节点应该是一致的。 一致性模型分为如下几种&#xff1a; ① 强一致性 所有用户在任意时…

vue源码分析之nextTick源码分析-逐行逐析-错误分析

nextTick的使用背景 在vue项目中&#xff0c;经常会使用到nextTick这个api&#xff0c;一直在猜想其是怎么实现的&#xff0c;今天有幸研读了下&#xff0c;虽然源码又些许问题&#xff0c;但仍值得借鉴 核心源码解析 判断当前环境使用最合适的API并保存函数 promise 判断…

【RL】Actor-Critic Methods

Lecture 10: Actor-Critic Methods The simplest actor-critic (QAC) 回顾 policy 梯度的概念&#xff1a; 1、标量指标 J ( θ ) J(\theta) J(θ)&#xff0c;可以是 v ˉ π \bar{v}_{\pi} vˉπ​ 或 r ˉ π \bar{r}_{\pi} rˉπ​。 2、最大化 J ( θ ) J(\theta)…

计算机服务器中了DevicData勒索病毒怎么办?DevicData勒索病毒解密数据恢复

网络技术的发展与更新为企业提供了极大便利&#xff0c;让越来越多的企业走向了正规化、数字化&#xff0c;因此&#xff0c;企业的数据安全也成为了大家关心的主要话题&#xff0c;但网络是一把双刃剑&#xff0c;即便企业做好了安全防护&#xff0c;依旧会给企业的数据安全带…

Prometheus+Grafana 监控

第1章Prometheus 入门 Prometheus 受启发于 Google 的 Brogmon 监控系统&#xff08;相似的 Kubernetes 是从 Google的 Brog 系统演变而来&#xff09;&#xff0c;从 2012 年开始由前 Google 工程师在 Soundcloud 以开源软件的 形式进行研发&#xff0c;并且于 2015 年早期对…

如何在Linux搭建Inis网站,并发布至公网实现远程访问【内网穿透】

如何在Linux搭建Inis网站&#xff0c;并发布至公网实现远程访问【内网穿透】 前言1. Inis博客网站搭建1.1. Inis博客网站下载和安装1.2 Inis博客网站测试1.3 cpolar的安装和注册 2. 本地网页发布2.1 Cpolar临时数据隧道2.2 Cpolar稳定隧道&#xff08;云端设置&#xff09;2.3.…

论文阅读:How Do Neural Networks See Depth in Single Images?

是由Technische Universiteit Delft(代尔夫特理工大学)发表于ICCV,2019。这篇文章的研究内容很有趣,没有关注如何提升深度网络的性能&#xff0c;而是关注单目深度估计的工作机理。 What they find&#xff1f; 所有的网络都忽略了物体的实际大小&#xff0c;而关注他们的垂直…

全球最强开源大模型一夜易主!谷歌Gemma 7B碾压Llama 2 13B,今夜重燃开源之战

一声炸雷深夜炸响&#xff0c;谷歌居然也开源LLM了&#xff1f;&#xff01; 这次&#xff0c;重磅开源的Gemma有2B和7B两种规模&#xff0c;并且采用了与Gemini相同的研究和技术构建。 有了Gemini同源技术的加持&#xff0c;Gemma不仅在相同的规模下实现SOTA的性能。 而且更令…

嵌入式学习-qt-Day3

嵌入式学习-qt-Day3 一、思维导图 二、作业 完善对话框&#xff0c;点击登录对话框&#xff0c;如果账号和密码匹配&#xff0c;则弹出信息对话框&#xff0c;给出提示”登录成功“&#xff0c;提供一个Ok按钮&#xff0c;用户点击Ok后&#xff0c;关闭登录界面&#xff0c;跳…

Transformer 架构—Encoder-Decoder

文章目录 前言 一、Encoder 家族 1. BERT 2. DistilBERT 3. RoBERTa 4. XML 5. XML-RoBERTa 6. ALBERT 7. ELECTRA 8. DeBERTa 二、Decoder 家族 1. GPT 2. GPT-2 3. CTRL 4. GPT-3 5. GPT-Neo / GPT-J-6B 三、Encoder-Decoder 家族 1. T5 2. BART 3. M2M-100 4. BigBird 前言 …

SpringBoot---集成MybatisPlus

介绍 使用SpringBoot集成MybatisPlus框架。 第一步&#xff1a;添加MybatisPlus依赖 <dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.4</version> </dependenc…

MIT6.S081学习——一、环境搭建、资料搜集

MIT6.S081学习——一、环境搭建、资料搜集 1、环境准备2、资料搜集2、环境搭建2.1 Linux环境准备2.2 环境搭建2.2.1 根据官网指导代码进行相关工具的安装2.2.2 下载并且编译QEMU 3、VSCode远程连接Ubuntu3.1 安装remote-ssh3.1.1 安装插件3.1.2 配置config文件 3.2 Ubuntu安装S…

springcloud:2.OpenFeign 详细讲解

OpenFeign 是一个基于 Netflix 的 Feign 库进行扩展的工具,它简化了开发人员在微服务架构中进行服务间通信的流程,使得编写和维护 RESTful API 客户端变得更加简单和高效。作为一种声明式的 HTTP 客户端,OpenFeign 提供了直观的注解驱动方式,使得开发人员可以轻松定义和调用…

Redis突现拒绝连接问题处理总结

一、问题回顾 项目突然报异常 [INFO] 2024-02-20 10:09:43.116 i.l.core.protocol.ConnectionWatchdog [171]: Reconnecting, last destination was 192.168.0.231:6379 [WARN] 2024-02-20 10:09:43.120 i.l.core.protocol.ConnectionWatchdog [151]: Cannot reconnect…

win32 汇编读文件

做了2个小程序&#xff0c;没有读成功&#xff1b;文件打开了&#xff1b; .386.model flat, stdcalloption casemap :noneinclude windows.inc include user32.inc includelib user32.lib include kernel32.inc includelib kernel32.lib include Comdlg32.inc includelib …

Pormise---如何解决javascript中回调的信任问题?【详解】

如果阅读有疑问的话&#xff0c;欢迎评论或私信&#xff01;&#xff01; 本人会很热心的阐述自己的想法&#xff01;谢谢&#xff01;&#xff01;&#xff01; 文章目录 回调中的信任问题回调给我们带来的烦恼&#xff1f;调用过早调用过晚调用的次数太少或太多调用回调时未能…

数据结构之链表经典算法QJ题目

目录 单链表经典算法题目1. 单链表相关经典算法OJ题&#xff1a;移除链表元素思路一&#xff1a;思路二&#xff1a; 2. 单链表相关经典算法QI题&#xff1a;链表的中间节点思路一思路二 3. 单链表相关经典算法QJ题&#xff1a;反转链表思路一思路二 4. 单链表相关经典算法QJ题…

pytest 框架自动化测试

随笔记录 目录 1. 安装 2. 安装pytest 相关插件 2.1 准备阶段 2.2 安装 2.3 验证安装成功 3. pytest测试用例的运行方式 3.1 主函数模式 3.1.1 主函数执行指定文件 3.1.2 主函数执行指定模块 3.1.3 主函数执行某个文件中的某个类、方法、函数 3.1.4 主函数执行生…