adding healthchecks
This commit is contained in:
parent
6a1ecc0b7d
commit
bb22147dd0
|
@ -11,7 +11,7 @@ from flask import render_template, flash, url_for
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from xmrnodes.helpers import determine_crypto, is_onion, make_request
|
from xmrnodes.helpers import determine_crypto, is_onion, make_request
|
||||||
from xmrnodes.forms import SubmitNode
|
from xmrnodes.forms import SubmitNode
|
||||||
from xmrnodes.models import Node
|
from xmrnodes.models import Node, HealthCheck
|
||||||
from xmrnodes import config
|
from xmrnodes import config
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ def index():
|
||||||
)
|
)
|
||||||
if onion:
|
if onion:
|
||||||
nodes = nodes.where(Node.is_tor==True)
|
nodes = nodes.where(Node.is_tor==True)
|
||||||
|
|
||||||
paginated = nodes.paginate(page, itp)
|
paginated = nodes.paginate(page, itp)
|
||||||
total_pages = nodes.count() / itp
|
total_pages = nodes.count() / itp
|
||||||
return render_template(
|
return render_template(
|
||||||
|
@ -93,6 +93,7 @@ def check():
|
||||||
nodes = Node.select().where(Node.validated == True)
|
nodes = Node.select().where(Node.validated == True)
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
|
hc = HealthCheck(node=node)
|
||||||
logging.info(f"Attempting to check {node.url}")
|
logging.info(f"Attempting to check {node.url}")
|
||||||
try:
|
try:
|
||||||
r = make_request(node.url)
|
r = make_request(node.url)
|
||||||
|
@ -103,15 +104,18 @@ def check():
|
||||||
logging.info("success")
|
logging.info("success")
|
||||||
node.available = True
|
node.available = True
|
||||||
node.last_height = r.json()["height"]
|
node.last_height = r.json()["height"]
|
||||||
|
hc.health = True
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
logging.info("fail")
|
logging.info("fail")
|
||||||
node.datetime_failed = now
|
node.datetime_failed = now
|
||||||
node.available = False
|
node.available = False
|
||||||
|
hc.health = False
|
||||||
finally:
|
finally:
|
||||||
node.datetime_checked = now
|
node.datetime_checked = now
|
||||||
node.save()
|
node.save()
|
||||||
|
hc.save()
|
||||||
|
|
||||||
@app.cli.command("validate")
|
@app.cli.command("validate")
|
||||||
def validate():
|
def validate():
|
||||||
|
@ -171,11 +175,14 @@ def import_():
|
||||||
export_dir = f"{config.DATA_DIR}/export.txt"
|
export_dir = f"{config.DATA_DIR}/export.txt"
|
||||||
with open(export_dir, 'r') as f:
|
with open(export_dir, 'r') as f:
|
||||||
for url in f.readlines():
|
for url in f.readlines():
|
||||||
n = url.rstrip()
|
try:
|
||||||
all_nodes.append(n)
|
n = url.rstrip()
|
||||||
logging.info(f"Adding {n}")
|
logging.info(f"Adding {n}")
|
||||||
node = Node(url=n)
|
node = Node(url=n)
|
||||||
node.save()
|
node.save()
|
||||||
|
all_nodes.append(n)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
logging.info(f"{len(all_nodes)} node urls imported and ready to be validated")
|
logging.info(f"{len(all_nodes)} node urls imported and ready to be validated")
|
||||||
|
|
||||||
@app.template_filter("humanize")
|
@app.template_filter("humanize")
|
||||||
|
|
|
@ -7,7 +7,7 @@ db = SqliteDatabase(f"{config.DATA_DIR}/sqlite.db")
|
||||||
|
|
||||||
class Node(Model):
|
class Node(Model):
|
||||||
id = AutoField()
|
id = AutoField()
|
||||||
url = CharField()
|
url = CharField(unique=True)
|
||||||
is_tor = BooleanField(default=False)
|
is_tor = BooleanField(default=False)
|
||||||
available = BooleanField(default=False)
|
available = BooleanField(default=False)
|
||||||
validated = BooleanField(default=False)
|
validated = BooleanField(default=False)
|
||||||
|
@ -22,4 +22,13 @@ class Node(Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
database = db
|
database = db
|
||||||
|
|
||||||
db.create_tables([Node])
|
class HealthCheck(Model):
|
||||||
|
id = AutoField()
|
||||||
|
node = ForeignKeyField(Node, backref='healthchecks')
|
||||||
|
datetime = DateTimeField(default=datetime.utcnow)
|
||||||
|
health = BooleanField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
database = db
|
||||||
|
|
||||||
|
db.create_tables([Node, HealthCheck])
|
||||||
|
|
|
@ -33,3 +33,18 @@ input[type="text"] {
|
||||||
.wownero {
|
.wownero {
|
||||||
background-color: rgb(235, 74, 206);
|
background-color: rgb(235, 74, 206);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dot {
|
||||||
|
height: 10px;
|
||||||
|
width: 10px;
|
||||||
|
border-radius: 50%;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glowing-green {
|
||||||
|
background-color: #00cd00;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glowing-red {
|
||||||
|
background-color: #cd0000;
|
||||||
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
<th>Network</th>
|
<th>Network</th>
|
||||||
<th>Height</th>
|
<th>Height</th>
|
||||||
<th>Last Checked</th>
|
<th>Last Checked</th>
|
||||||
|
<th>History</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -54,6 +55,12 @@
|
||||||
<td>{{ node.nettype }}</td>
|
<td>{{ node.nettype }}</td>
|
||||||
<td>{{ node.last_height }}</td>
|
<td>{{ node.last_height }}</td>
|
||||||
<td>{{ node.datetime_checked | humanize }}</td>
|
<td>{{ node.datetime_checked | humanize }}</td>
|
||||||
|
<td>{% for hc in node.healthchecks %}
|
||||||
|
{% if loop.index > loop.length - 11 %}
|
||||||
|
<span class="dot glowing-{% if hc.health %}green{% else %}red{% endif %}"></span>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
Loading…
Reference in New Issue