From ff5cbcbcc625b93f17443adffef652739bc7b50c Mon Sep 17 00:00:00 2001 From: ubuntu Date: Tue, 4 Dec 2018 16:18:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=9C=A8=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E4=B8=8B=E6=9F=A5=E7=9C=8BServerStatus=E7=9A=84?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/ssview.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 web/ssview.py diff --git a/web/ssview.py b/web/ssview.py new file mode 100755 index 00000000..8e1f2670 --- /dev/null +++ b/web/ssview.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# coding: utf-8 +# Update by : https://github.com/cppla/ServerStatus +# 支持Python版本:2.7 to 3.5; requirements.txt: requests, PrettyTable +# 时间: 20180828 +''' +maybe better by youself +''' + +import os +import sys +import requests +import time +from prettytable import PrettyTable + +cp = 'clear' if 'linux' in sys.platform else 'cls' + +def sscmd(address): + while True: + r = requests.get( + url=address, + headers={ + "User-Agent": "ServerStatus/20181203", + } + ) + jsonR = r.json() + + ss = PrettyTable( + [ + "Flight", + "节点名", + # "虚拟化", + "位置", + "在线时间", + "负载", + "网络", + "流量", + "处理器", + "内存", + "硬盘" + ], + ) + for i in jsonR["servers"]: + ss.add_row( + [ + "%s" % 'MH361' if i["ip_status"] is True else 'MH370', + "%s" % i["name"], + # "%s" % i["type"], + "%s" % i["location"], + "%s" % i["uptime"], + "%s" % (i["load_1"]), + "%.2fM|%.2fM" % (float(i["network_rx"]) / 1000 / 1000, float(i["network_tx"]) / 1000 / 1000), + "%.2fG|%.2fG" % ( + float(i["network_in"]) / 1024 / 1024 / 1024, float(i["network_out"]) / 1024 / 1024 / 1024), + "%d%%" % (i["cpu"]), + "%d%%" % (float(i["memory_used"]) / i["memory_total"] * 100), + "%d%%" % (float(i["hdd_used"]) / i["hdd_total"] * 100), + ] + ) + os.system(cp) + print(ss) + time.sleep(1) + +if __name__ == '__main__': + default = 'https://tz.cloudcpp.com/json/stats.json' + ads = sys.argv[1] if len(sys.argv)==2 else default + sscmd(ads) \ No newline at end of file