最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

[示例]使用python編寫prometheus_export

2020-02-24 16:09 作者:究極完美豆芽  | 我要投稿

環(huán)境:

python3.7

import subprocess
import prometheus_client
import time

request_count = prometheus_client.Counter('request_count', "啟動后到現(xiàn)在收集了幾數(shù)據(jù)")

job_count = prometheus_client.Gauge("job_count", "統(tǒng)計數(shù)量", ["user_name"])


# 執(zhí)行命令
def popen(cmd):
? ?try:
? ? ? ?result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?encoding="utf-8", shell=True, )
? ? ? ?return result.stdout
? ?except Exception as e:
? ? ? ?print(e)
? ? ? ?# 返回-1時為出錯
? ? ? ?return -1


def process_request(sleepTime):
? ?request_count.inc() ?# 數(shù)值+1
? ?job_count.labels(user_name="root").set(11)
? ?job_count.labels(user_name="testuser").set(22)
? ?time.sleep(sleepTime) ?# 睡眠


if __name__ == '__main__':
? ?prometheus_client.start_http_server(8080)
? ?print("啟動完成")
? ?while True:
? ? ? ?process_request(2) ?# 兩秒一次收集一次數(shù)據(jù)


[示例]使用python編寫prometheus_export的評論 (共 條)

分享到微博請遵守國家法律
石渠县| 彝良县| 韶山市| 邵阳市| 屏东县| 卓尼县| 察雅县| 垫江县| 保康县| 柘荣县| 溧水县| 永清县| 彩票| 瓮安县| 泸州市| 曲阜市| 禹城市| 南平市| 鄱阳县| 五原县| 温宿县| 社旗县| 绥芬河市| 巩留县| 奉节县| 高台县| 治县。| 晋中市| 罗平县| 湖州市| 工布江达县| 鄄城县| 岫岩| 岳阳市| 钟山县| 全椒县| 仁怀市| 泊头市| 南乐县| 吉隆县| 佛教|