open falcon 插件 脚本 ogg示例
最近在研究 小米的open falcon
研究了端口、进程、报警等功能后,需要学习 自定义插件或自定义push数据
这里结合oracle ogg 写了个示例程序
1.获取ogg监控数据并push的脚本
#!/usr/bin/python
import os
import commands
import subprocess
import requests
import time
import json
import socket
endpoint=socket.gethostname()
child1=subprocess.Popen(['/u01/ggs/ggsci'],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
(stdout,stderr)=child1.communicate(input=b'info all')
#print(stdout.decode())
result=stdout.decode()
#endpoint="hz-ds-sbqz-199-136-39"
ts=int(time.time())
stoppedCount=len(stdout.decode().split("STOPPED"))-1
runningCount=len(stdout.decode().split("RUNNING"))-1
abendedCount=len(stdout.decode().split("ABENDED"))-1
payload = [
    {
        "endpoint": endpoint,
        "metric": "ogg.stopped.count",
        "timestamp": ts,
        "step": 60,
        "value": stoppedCount,
        "counterType": "GAUGE",
        "tags": "idc=zhanghui,loc=272228000",
    },
    {
        "endpoint": endpoint,
        "metric": "ogg.running.count",
        "timestamp": ts,
        "step": 60,
        "value": runningCount,
        "counterType": "GAUGE",
        "tags": "idc=zhanghui,loc=272228000",
    },
    {
        "endpoint": endpoint,
        "metric": "ogg.abended.count",
        "timestamp": ts,
        "step": 60,
        "value": abendedCount,
        "counterType": "GAUGE",
        "tags": "idc=zhanghui,loc=272228000",
    }
]
r = requests.post("http://10.199.140.23:1988/v1/push", data=json.dumps(payload))
print r.text
2.定时执行脚本的sh ,也可以有其他方式,这个比较简单
#! /bin/bash while [ true ]; do ./ogg.py sleep 60 #60s per time done
3.使用说明
1.chmod a+x ogg.py 2.chmod a+x ogg.sh 3.nohup ./ogg.sh & 4.查看状态:ps -ef |grep ogg
4.一些图



github地址: https://github.com/hutuchong518/open-falcon-test
 
                     
                    
                 
                    
                 
                
            
         
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号