zoukankan      html  css  js  c++  java
  • Prometheus + Grafana

    Prometheus

    简介

    Prometheus(由go语言(golang)开发)是一套开源的监控&报警&时间序列数据库的组合。适合监控docker容器。因为kubernetes(俗称k8s)的流行带动
    了prometheus的发展

    时间序列化数据

    时间序列数据

    按照时间顺序记录系统、设备状态变化的数据被称为时序数据

    时间序列数据特点

    • 性能好

      关系型数据库对于大规模数据的处理性能糟糕。NOSQL可以比较好的处理大规模数据,让依然比不上时间序列数据库

    • 存储成本低

      高效的压缩算法,节省存储空间,有效降低IO

    Prometheus特点

    • 多维度数据模型
    • 灵活的查询语言
    • 不依赖分布式存储,单个服务器节点是自主的
    • 以HTTP方式,通过pull模型拉去时间序列数据
    • 也可以通过中间网关支持push模型
    • 通过服务发现或者静态配置,来发现目标服务对象
    • 支持多种多样的图表和界面展示

    Prometheus架构图

    193492431_2_2020062104302252

    Prometheus安装配置

    架构图

    prometheus

    安装

    # 下载
    wget https://github.com/prometheus/prometheus/releases/download/v2.14.0/prometheus-2.14.0.linux-amd64.tar.gz
    
    # 解压
    tar -zxvf prometheus-2.14.0.linux-amd64.tar.gz -C /usr/local/
    
    # 重命名
    mv /usr/local/prometheus-2.14.0.linux-amd64/ /usr/local/prometheus
    
    # 添加快捷方式
    ln -s /usr/local/prometheus/prometheus /usr/bin/prometheus
    
    # 后台启动
    /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &
    
    # 开机自启动
    vim /etc/rc.d/rc.local
    	/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
    
    chmod +x /etc/rc.d/rc.local 
    
    # 查看端口号
    netstat -aunpt | grep 9090
    

    image-20210616103259811

    下载地址

    node_exporter安装

    # 下载
    wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
    
    # 解压
    tar -xvf node_exporter-0.18.1.linux-amd64.tar.gz -C /usr/local/
    
    # 重命名
    mv /usr/local/node_exporter-0.18.1.linux-amd64/ /usr/local/node_exporter
    
    # 快捷方式
    ln -s /usr/local/node_exporter/node_exporter /usr/bin/node_exporter
    
    # 启动
    nohup /usr/local/node_exporter/node_exporter &
    
    # 查看端口号
    netstat -aunpt | grep 9100
    

    image-20210616104712771

    下载地址

    监控端监控节点服务器状态

    vim /usr/local/prometheus/prometheus.yml
    	- job_name: 'node' # 取一个job名称来代 表被监控的机器
       
          static_configs:
          - targets: ['10.1.1.4:9100'] # 这里改成被监控机器   的IP,后面端口接9100
    # 重启服务
    pkill prometheus
    
    # 查看端口
    netstat -aunpt | grep 9100
    
    # 启动
     /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &
    
    

    image-20210616105535810

    mysql_exporter安装

    # 下载
    wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz	
        
    # 解压
    tar -xvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/
    
    # 重命名
    mv /usr/local/mysqld_exporter-0.12.1.linux-amd64/ /usr/local/mysqld_exporter
    
    # 添加快捷方式
    ln -s /usr/local/mysqld_exporter/mysqld_exporter /usr/bin/mysqld_exporter
    
    # 设置授权帐号
    mysql -uroot -proot
        grant select,replication client,process ON *.* to 'mysql_monitor'@'localhost' identified by 'root';
        flush privileges;
    # 配置连接帐号 
    vim /usr/local/mysqld_exporter/.my.cnf
    	[client]
        user=mysql_monitor
        password=root
    # 启动服务
    nohup /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf &
    
    # 查看端口
    netstat -aunpt | grep 9104
    
    # 开启自启动
    vim /etc/rc.d/rc.local
    	/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
    

    image-20210616111722716

    下载地址

    监控节点监控mysql状态

    vim /usr/local/prometheus/prometheus.yml
    	- job_name: 'mysql' # 取一个job名称来代 表被监控的机器
       
          static_configs:
          - targets: ['10.1.1.4:9104'] # 这里改成被监控机器   的IP,后面端口接9104
    # 重启服务
    pkill prometheus
    
    # 查看端口
    netstat -aunpt | grep 9100
    
    # 启动
     /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &
    

    image-20210616112124227

    Grafana

    简介

    Grafana是一个开源的度量分析和可视化工具,可以通过将采集的数据分析,查询,然后进行可视化的展示,并能实现报警

    官网

    安装

    # 下载rpm
    wget https://dl.grafana.com/oss/release/grafana-6.5.2-1.x86_64.rpm
    
    # 安装
    yum localinstall grafana-6.5.2-1.x86_64.rpm -y
    
    # 启动
    systemctl enable grafana-server.service && systemctl start grafana-server.service
    
    # 查看状态
    systemctl status grafana-server.service
    

    image-20210616113401762

    添加数据源

    image-20210616113650927

    添加模板

    image-20210616113830832

    数据展示

    image-20210616114027762

  • 相关阅读:
    arcgis api 3.x for js 入门开发系列八聚合效果(附源码下载)
    arcgis api 3.x for js 入门开发系列七图层控制(附源码下载)
    arcgis api 3.x for js 入门开发系列六地图分屏对比(附源码下载)
    arcgis api 3.x for js 入门开发系列五地图态势标绘(附源码下载)
    arcgis api 3.x for js 入门开发系列四地图查询(附源码下载)
    Java里面获取当前服务器的IP地址
    Flutter at Google I/O 2018
    Modbus RTU 协议使用汇总
    plsql 创建表空间、用户、赋予权限
    Oracle:ODP.NET Managed 小试牛刀
  • 原文地址:https://www.cnblogs.com/SR-Program/p/14888765.html
Copyright © 2011-2022 走看看