zoukankan      html  css  js  c++  java
  • prometheus监控linux进程

    参考:https://blog.csdn.net/myy1066883508/article/details/106687682

    目的:需要监控linux系统上所有进程所占用的内存以及cpu

     描述:通过脚本抓取数据推到pushgateway上,然后pashgateway通过http把数据传给prometheus。

    1、安装pushgateway

    wget https://github.com/prometheus/pushgateway/releases/download/v0.8.0/pushgateway-0.8.0.linux-amd64.tar.gz
    
    tar xvzf pushgateway-0.8.0.linux-amd64.tar.gz   -C /usr/local
    

    2、启动pushgateway

    cd  /usr/local/pushgateway-0.8.0.linux-amd64
    ./pushgateway --persistence.file="/usr/local/pushgateway-0.8.0.linux-amd64/log" --persistence.interval=5m &

    说明:--persistence.file指定存储文件,不指定的话,重启pushgateway数据就没了

     3、编辑prometheus.yml文件

    - job_name: 'cpu-memory'
        honor_labels: true
        static_configs:
        - targets: ['172.16.68.169:9091']

    4、在监听服务器上编写shell文件,收集进程信息

    vim cup.sh

    #!/bin/bash z=$(ps aux) while read -r z do var=$var$(awk '{print "cpu_usage{process=""$11"", pid=""$2""}", $3z}'); done <<< "$z" echo "$var" |curl -X POST -H "Content-Type: text/plain" --data-binary @- http://172.16.68.169:9091/metrics/job/top/instance/machine
    vim memory.sh
    
    #!/bin/bash
    z=$(ps aux)
    while read -r z
    do
    var=$var$(awk '{print "memory_usage{process=""$11"", pid=""$2""}", $4z}');
    done <<< "$z"
    echo "$var" |curl -X POST -H "Content-Type: text/plain" --data-binary @-  http://172.16.68.169:9091/metrics/job/top/instance/machine

     5、启动脚本文件

    # while   sleep 1;do ./top.sh ;done 
    # while   sleep 1;do ./memory.sh ;done
    

    6、验证数据

    http://172.16.68.169.9091

     http://172.16.68.169:9090

  • 相关阅读:
    CSS优化,提高性能的方法有哪些?
    稀疏数组(SparseArray)(Go)
    Go
    Vue 实战-6 rest 重置表单不生效原因
    Go
    Vue 实战-5 批量导出 excel功能
    Vue 实战-4 表格展开行
    Vue 实战-3 vue 中使用watch 监听 el-input属性值
    Vue 实战-2 输入框加搜索图标
    Vue 实战-1 去掉 input [number] 默认增减箭头样式
  • 原文地址:https://www.cnblogs.com/lina-2159/p/13686683.html
Copyright © 2011-2022 走看看