zoukankan      html  css  js  c++  java
  • prometheus配置pushgateway功能测试

    一、环境:

    1、prometheus服务器ip:192.168.0.208

    2、node-exporter客户机ip:192.168.0.202

    二、测试设计考虑:

      pushgateway类似一台信息收集中转机,其部署位置不受任何限制。本次测试,考虑把pushgateway部署在node-exporter客户机上,在prometheus服务器上编制信息收集和推送程序。

          信息数据流程:

      1、prometheus服务器作为信息数据采集点,通过采集和推送程序向pushgateway端推送所采集的信息数据。

      2、prometheus服务器作为prometheus服务端,从pushgateway端拉取所需信息数据用于处理和展示。

    二、配置过程

    1、pushgateway服务端的安装

    (1)pushgateway的image下载和安装

    [root@DL ~]# docker search pushgateway      #查询可用pushgateway镜像

    NAME DESCRIPTION STARS OFFICIAL AUTOMATED
    prom/pushgateway The Prometheus Pushgateway allows ephemeral … 45 [OK]

    [root@DL ~]# docker pull prom/pushgateway

    (2)pushgateway服务的运行:

    [root@DL ~]# docker run -d --name=pg -p 9091:9091 prom/pushgateway

    2、prometheus服务器的配置

    (1)prometheus服务器对pushgateway的监控配置

    [root@ELK prometheus]# vi prometheus.yml

    ...


    - job_name: 'pushgateway'


    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.


    static_configs:
    - targets: ['192.168.0.202:9091']

    配置完成后需要重启一下prometheus服务:docker restart prometheus

    (2)数据采集和推送程序的编制

    以采集netstat命令中处于wait状态的连接数为例:

    [root@ELK prometheus]# vi node-exporter-shell.sh
    #!/bin/bash
    instance_name=`hostname -f | cut -d'.' -f1` #本机机器名 变量 用于之后的标签

    if [[ $instanc_name == "localhost" ]];then #要求机器名不能是localhost,不然标签就没有区分了
    echo "Must FQDN hostname"
    exit 1
    fi

    # For waiting connections

    label="count_netstat_wait_connections" #定义一个新的key
    count_netstat_wait_connections=`netstat -an | grep -i wait | wc -l` #定义一个新的数值netstat中wait的数量

    echo "$label:$count_netstat_wait_connections"
    echo "$label $count_netstat_wait_connections" | curl --data-binary @- http://192.168.0.202:9091/metrics/job/pushgateway/instance/$instance_name   #推送键值对到pushgateway服务端

    (3)数据采集程序的定时运行设置

    [root@ELK prometheus]# crontab -e
    * * * * * sleep 10;cd /root/prometheus; ./node-exporter-shell.sh    #设置每10秒采集和推送一次数据

     三、测试

    1、web访问:http://192.168.0.202:9091/ 可看到pushgateway的实时push状态

    2、web访问:http://192.168.0.202:9091/metrics 可看到采集数据的键值对

    # TYPE count_netstat_wait_connections untyped
    count_netstat_wait_connections{instance="ELK",job="pushgateway"} 0


    数据采集和推送程序来源:B站大米运维课堂
  • 相关阅读:
    基于ZYNQ SOC视频处理的常规设计
    Alinx黑金没有实现利用一个VDMA完成视频流读写的例程
    Vitis软件平台、vitis实例、裸机SOC(SDK)程序移植
    ZYNQ PS端IIC接口使用-笔记
    用信号量实现生产者&消费者模型
    C语言 -- 内存对齐
    排序算法---希尔排序
    排序算法---直接插入排序
    网络套接字编程介绍---UDP通信
    C++实现__搜索二叉树
  • 原文地址:https://www.cnblogs.com/sfccl/p/12935442.html
Copyright © 2011-2022 走看看