forkeado de spla/fediverse
Human friendly uptime
This commit is contained in:
pare
8c7b01cbc7
commit
72279e5e3c
S'han modificat 2 arxius amb 39 adicions i 2 eliminacions
|
@ -3,3 +3,4 @@ psycopg2-binary>=2.8.4
|
|||
aiohttp>=3.6.2
|
||||
aiodns>=2.0.0
|
||||
matplotlib>=3.3.4
|
||||
humanfriendly>=9.2
|
||||
|
|
40
uptime.py
40
uptime.py
|
@ -1,6 +1,7 @@
|
|||
import time
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
import humanfriendly
|
||||
from mastodon import Mastodon
|
||||
import psycopg2
|
||||
|
||||
|
@ -64,6 +65,40 @@ def get_uptime():
|
|||
|
||||
conn.close()
|
||||
|
||||
def get_percentage(uptime_servers, software):
|
||||
|
||||
try:
|
||||
|
||||
conn = None
|
||||
|
||||
conn = psycopg2.connect(database=fediverse_db, user=fediverse_db_user, password="", host="/var/run/postgresql", port="5432")
|
||||
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute("select count(server) from fediverse where alive and software=(%s)", (software,))
|
||||
|
||||
row = cur.fetchone()
|
||||
|
||||
if row is not None:
|
||||
|
||||
soft_total_servers = row[0]
|
||||
|
||||
cur.close()
|
||||
|
||||
soft_uptime_percent = round((uptime_servers * 100) / soft_total_servers, 1)
|
||||
|
||||
return (soft_uptime_percent)
|
||||
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
|
||||
print(error)
|
||||
|
||||
finally:
|
||||
|
||||
if conn is not None:
|
||||
|
||||
conn.close()
|
||||
|
||||
def mastodon():
|
||||
|
||||
# Load secrets from secrets file
|
||||
|
@ -129,7 +164,7 @@ if __name__ == '__main__':
|
|||
|
||||
toot_text = '\nAlive servers: ' + str(alive_servers)
|
||||
toot_text += '\n\n'
|
||||
toot_text += "Best #fediverse's server uptime:\n" + str(max_uptime)
|
||||
toot_text += "Best #fediverse's server uptime:\n" + humanfriendly.format_timespan(max_uptime)
|
||||
toot_text += '\n'
|
||||
toot_text += 'Servers with best uptime: ' + str(best_servers)
|
||||
toot_text += '\n\n'
|
||||
|
@ -137,7 +172,8 @@ if __name__ == '__main__':
|
|||
i = 0
|
||||
while i < len(software_lst):
|
||||
|
||||
toot_text += ':' + str(software_lst[i]) + ': ' + str(servers_lst[i]) + '\n'
|
||||
soft_percent = get_percentage(servers_lst[i], software_lst[i])
|
||||
toot_text += ':' + str(software_lst[i]) + ': ' + str(servers_lst[i]) + ' (' + str(soft_percent) + '%)\n'
|
||||
|
||||
if len(toot_text) > 480:
|
||||
break
|
||||
|
|
Loading…
Referencia en una nova incidència