1
0
mirror of https://github.com/r4sas/Niflheim-api synced 2025-03-13 05:51:45 +00:00

add 24 hours node count

This commit is contained in:
R4SAS 2020-01-02 17:05:12 +00:00
parent 70a54c45b5
commit d9216c95df
3 changed files with 38 additions and 4 deletions

View File

@ -12,8 +12,13 @@ DB_USER = "yggindex"
DB_NAME = "yggindex"
DB_HOST = "localhost"
# count peer alive if it was available not more that amount of seconds ago
# I'm using 1 hour beause of running crawler every 15 minutes
ALIVE_SECONDS = 3600 # 1 hour
def age_calc(ustamp):
if (time.time() - ustamp) <= 14400 :
if (time.time() - ustamp) <= ALIVE_SECONDS :
return True
else:
return False

View File

@ -16,7 +16,7 @@ DB_NAME = "yggindex"
DB_HOST = "localhost"
# count peer alive if it was available not more that amount of seconds ago
# I'm using 1 hour beause of running cron job every 15 minutes
# I'm using 1 hour beause of running crawler every 15 minutes
ALIVE_SECONDS = 3600 # 1 hour
@ -74,6 +74,30 @@ class nodesInfo(Resource):
return nodeinfo
# alive nodes count for latest 24 hours
class nodes24h(Resource):
def get(self):
dbconn = psycopg2.connect(host=DB_HOST,\
database=DB_NAME,\
user=DB_USER,\
password=DB_PASSWORD)
cur = dbconn.cursor()
nodes = {}
cur.execute("SELECT * FROM timeseries ORDER BY unixtstamp DESC LIMIT 24")
for i in cur.fetchall():
nodes[i[1]] = i[0]
dbconn.commit()
cur.close()
dbconn.close()
nodeinfo = {}
nodeinfo['nodes24h'] = nodes
return nodeinfo
@app.route("/")
def fpage():
dbconn = psycopg2.connect(host=DB_HOST,\
@ -98,6 +122,7 @@ def fpage():
#sort out the api request here for the url
api.add_resource(nodesCurrent, '/current')
api.add_resource(nodesInfo, '/nodeinfo')
api.add_resource(nodes24h, '/nodes24h')
if __name__ == '__main__':
app.run(host='::', port=3000)

View File

@ -23,11 +23,15 @@
Get a current list of active and online nodes:<br />
<div class="apireq">
<a href="/current">http://[31a:fb8a:c43e:ca59::2]/current</a>
<a href="/current" target="_blank">http://[31a:fb8a:c43e:ca59::2]/current</a>
</div>
Nodeinfo from all current active nodes:<br />
<div class="apireq">
<a href="/nodeinfo">http://[31a:fb8a:c43e:ca59::2]/nodeinfo</a>
<a href="/nodeinfo" target="_blank">http://[31a:fb8a:c43e:ca59::2]/nodeinfo</a>
</div>
Active nodes count for last 24 hours:<br />
<div class="apireq">
<a href="/nodes24h" target="_blank">http://[31a:fb8a:c43e:ca59::2]/nodes24h</a>
</div>
<div class="wide"></div>