• 【Prometheus】Prometheus+Grafana部署


    Prometheus

    概述

    官网https://prometheus.io/docs/introduction/overview/

    Prometheus 是一款基于时序数据库的开源监控告警系统,非常适合Kubernetes集群的监控。Prometheus的基本原理是通过HTTP协议周期性抓取被监控组件的状态,任意组件只要提供对应的HTTP接口就可以接入监控。不需要任何SDK或者其他的集成过程。这样做非常适合做虚拟化环境监控系统,比如VM、Docker、Kubernetes等。输出被监控组件信息的HTTP接口被叫做exporter 。目前互联网公司常用的组件大部分都有exporter可以直接使用,比如Varnish、Haproxy、Nginx、MySQL、Linux系统信息(包括磁盘、内存、CPU、网络等等)。Promethus有以下特点:

    • 支持多维数据模型:由度量名和键值对组成的时间序列数据
    • 内置时间序列数据库TSDB
    • 支持PromQL查询语言,可以完成非常复杂的查询和分析,对图表展示和告警非常有意义
    • 支持HTTP的Pull方式采集时间序列数据
    • 支持PushGateway采集瞬时任务的数据
    • 支持服务发现和静态配置两种方式发现目标
    • 支持接入Grafana

    部署

    Docker方式

    部署Prometheus
    #下载配置文件
    https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus.yml
    
    #运行prometheus
    docker run --name myPrometheus \
    -d -p 9090:9090 \
    -v /root/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
    prom/prometheus
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    测试访问
    在这里插入图片描述

    #若提示图中Warning内容
    #更新一下服务器的时间
    ntpdate ntp.aliyun.com
    
    • 1
    • 2
    • 3

    在这里插入图片描述

    监控计算机资源信息-部署node_exporter
    #下载符合操作系统的tar包,我这里是arm版本的虚拟机
    https://github.com/prometheus/node_exporter/releases
    #解压
    tar zxvf node_exporter-0.18.0.linux-arm64.tar.gz 
    #前台方式启动,默认9100端口
    ./node_exporter
    
    #后台方式启动,使用nohup命令
    # 忽略输入并把输出追加到“nohup.out“ 增加 > /dev/null 2>&1
    nohup ./node_exporter --web.listen-address=":9100" > /dev/null 2>&1 &
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    在这里插入图片描述
    在这里插入图片描述

    增加监控信息

    编辑prometheus.yml,增加监控宿主机myCentOS

    # 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:
      # - "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=` to any timeseries scraped from this config.
      - job_name: "prometheus"
    
        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.
    
        static_configs:
          - targets: ["localhost:9090"]
      - job_name: "myCentOS"
        static_configs:
          - targets: ["10.211.55.88:9100"]    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    重启prometheus容器
    在这里插入图片描述

    Linux

    。。。

    k8s

    。。。

    Grafana

    概述

    官网https://grafana.com/docs/grafana/latest/introduction/

    Grafana 开源软件使您能够查询、可视化、警报和探索存储在任何位置的指标、日志和跟踪。Grafana OSS 为您提供了将时间序列数据库 (TSDB) 数据转换为富有洞察力的图形和可视化的工具。Grafana OSS 插件框架还使您能够连接其他数据源(例如 NoSQL/SQL 数据库)、票务工具(例如 Jira 或 ServiceNow)以及 CI/CD 工具(例如 GitLab)。

    部署

    Docker方式

    docker pull grafana/grafana
    
    docker run --name myGrafana \
    -d -p 3000:3000 \
    grafana/grafana
    
    • 1
    • 2
    • 3
    • 4
    • 5

    测试访问,默认账号密码admin
    在这里插入图片描述

    配置数据源

    在这里插入图片描述
    选择普罗米修斯
    在这里插入图片描述
    设置name url,保存即可
    在这里插入图片描述
    在这里插入图片描述

    配置dashboard

    直接使用官网模版
    https://grafana.com/grafana/dashboards

    搜索node
    在这里插入图片描述
    copy id

    点加号,选择import,粘贴ID->load
    选择数据源
    在这里插入图片描述
    在查询这里选择要查看的监控job
    在这里插入图片描述
    效果如下,我的虚拟机监控信息
    在这里插入图片描述

    Linux

    。。。

    k8s

    。。。

    前人栽树

    https://blog.csdn.net/liu_chen_yang/article/details/131049402
    https://zhuanlan.zhihu.com/p/344743604
    https://zhuanlan.zhihu.com/p/267966193

  • 相关阅读:
    Gitlab部署流程
    macOS Monterey12.5.1 配置vim
    血氧仪方案组成结构设计分析
    关于FPGA对 DDR4 (MT40A256M16)的读写控制 3
    walking机器人仿真教程-rosbag录制和播放
    RxJava 复刻简版之四,线程切换
    创建Vue3工程
    【Vue】Vuex 用法案例(一篇足以)
    用户上下文打通+本地缓存Guava
    c++高级篇(一) —— 初识Linux下的进程控制
  • 原文地址:https://blog.csdn.net/qq_36762765/article/details/132872079