当前位置: 首页 > 工具软件 > Openpush > 使用案例 >

open-falcon python自定义push数据

赵英资
2023-12-01


)

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 后台运行输出
 类似资料: