open-falcon python自定义push数据

open-falcon 自定义push数据


)

1,open-falcon 自定义push数据

#!/usr/bin/python3
'''
从网站https://filscan.io/,爬取数据用于监控
运行
nohup python3 -u /storage/script/agent-push/height.py > /storage/script/agent-push/height_py.log &
'''

import requests
import json
import time

while True:
    url = requests.get('https://filscan.io:8700/v0/filscan/BaseInformation')
    data = url.text

    '''
    json.loads(json_str) json字符串转换成字典
    json.dumps(dict) 字典转换成json字符串
    '''
    data_dict = json.loads(data)
    height = data_dict['data']['tipset_height']
    print (height)

    reward = data_dict['data']['pledge_collateral']
    print (reward)

    ts = int(time.time())
    payload = [
        {
            "endpoint": "zzx-desktop",
            "metric": "filscan_height",
            "timestamp": ts,
            "step": 60,
            "value": height,
            "counterType": "GAUGE",
            "tags": "",
        },

        {
            "endpoint": "zzx-desktop",
            "metric": "filscan_reward",
            "timestamp": ts,
            "step": 60,
            "value": reward,
            "counterType": "GAUGE",
            "tags": "",
        },
    ]

    r = requests.post("http://127.0.0.1:1988/v1/push", data=json.dumps(payload))

    print (r.text)
    time.sleep(60)
  • 运行
nohup python3 -u /storage/script/agent-push/height.py > /storage/script/agent-push/height_py.log &

参考:

  1. 【Linux】 nohup linux 后台运行输出
发布了630 篇原创文章 · 获赞 162 · 访问量 108万+

猜你喜欢

转载自blog.csdn.net/u010953692/article/details/104187480