• 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站大米运维课堂
  • 相关阅读:
    贪心:SPOJ Backup Files
    杂题 SPOJ MOBILE2
    杂题 UVAoj 10000 Longest Paths
    杂题 UVAoj 107 The Cat in the Hat
    DP(斜率优化):HDU 3507 Print Article
    搜索(DLX): POJ 3074 3076 Sudoku
    DLX模板
    PHP代码优化技巧大盘点
    盘点PHP编程常见失误
    PHP Socket 编程详解
  • 原文地址:https://www.cnblogs.com/sfccl/p/12935442.html
Copyright © 2020-2023  润新知