restart at failure
This commit is contained in:
parent
4723789261
commit
62da4a9f11
@ -29,9 +29,33 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/html")
|
||||
self.end_headers()
|
||||
self.wfile.write(bytes(config.exporter_prefix + "expoter_duration_seconds_sum " + str(int((datetime.now() - startTime).total_seconds())) + "\n", "utf-8"))
|
||||
self.wfile.write(bytes(config.exporter_prefix + "exporter_request_count " + str(request_count) + "\n", "utf-8"))
|
||||
self.wfile.write(bytes(config.exporter_prefix + "exporter_scrape_healthy " + str(int(scrape_healthy)) + "\n", "utf-8"))
|
||||
self.wfile.write(
|
||||
bytes(
|
||||
config.exporter_prefix
|
||||
+ "expoter_duration_seconds_sum "
|
||||
+ str(int((datetime.now() - startTime).total_seconds()))
|
||||
+ "\n",
|
||||
"utf-8",
|
||||
)
|
||||
)
|
||||
self.wfile.write(
|
||||
bytes(
|
||||
config.exporter_prefix
|
||||
+ "exporter_request_count "
|
||||
+ str(request_count)
|
||||
+ "\n",
|
||||
"utf-8",
|
||||
)
|
||||
)
|
||||
self.wfile.write(
|
||||
bytes(
|
||||
config.exporter_prefix
|
||||
+ "exporter_scrape_healthy "
|
||||
+ str(int(scrape_healthy))
|
||||
+ "\n",
|
||||
"utf-8",
|
||||
)
|
||||
)
|
||||
|
||||
for metric in node_metrics:
|
||||
# print(metric)
|
||||
@ -45,7 +69,7 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||
global scrape_healthy
|
||||
request_count = request_count + 1
|
||||
# print("Request: " + self.path)
|
||||
if (self.path.startswith("/metrics")):
|
||||
if self.path.startswith("/metrics"):
|
||||
# if (datetime.now() - lastMqttReception) > timedelta(hours=7):
|
||||
# scrape_healthy = False
|
||||
self.get_metrics()
|
||||
@ -54,9 +78,16 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||
self.send_header("Content-type", "text/html")
|
||||
self.end_headers()
|
||||
self.wfile.write(bytes("<html>", "utf-8"))
|
||||
self.wfile.write(bytes("<head><title>VEGAPULS Air exporter</title></head>", "utf-8"))
|
||||
self.wfile.write(
|
||||
bytes("<head><title>VEGAPULS Air exporter</title></head>", "utf-8")
|
||||
)
|
||||
self.wfile.write(bytes("<body>", "utf-8"))
|
||||
self.wfile.write(bytes('<h1>ttn-vegapulsair exporter based on data from LoRaWAN TTN node.</h1>', "utf-8"))
|
||||
self.wfile.write(
|
||||
bytes(
|
||||
"<h1>ttn-vegapulsair exporter based on data from LoRaWAN TTN node.</h1>",
|
||||
"utf-8",
|
||||
)
|
||||
)
|
||||
self.wfile.write(bytes('<p><a href="/metrics">Metrics</a></p>', "utf-8"))
|
||||
self.wfile.write(bytes("</body>", "utf-8"))
|
||||
self.wfile.write(bytes("</html>", "utf-8"))
|
||||
@ -78,7 +109,9 @@ def update_metrics(payload, metadata):
|
||||
|
||||
if "Inclination_degree" in payload:
|
||||
print("set Inclination_degree: " + str(int(payload["Inclination_degree"])))
|
||||
node_metrics.append("inclination_degree " + str(int(payload["Inclination_degree"])))
|
||||
node_metrics.append(
|
||||
"inclination_degree " + str(int(payload["Inclination_degree"]))
|
||||
)
|
||||
|
||||
if "MvLinProcent" in payload:
|
||||
print("set MvLinProcent: " + str(int(payload["MvLinProcent"])))
|
||||
@ -98,7 +131,9 @@ def update_metrics(payload, metadata):
|
||||
|
||||
if "PacketIdentifier" in payload:
|
||||
print("set PacketIdentifier: " + str(int(payload["PacketIdentifier"])))
|
||||
node_metrics.append("packet_identifier " + str(int(payload["PacketIdentifier"])))
|
||||
node_metrics.append(
|
||||
"packet_identifier " + str(int(payload["PacketIdentifier"]))
|
||||
)
|
||||
|
||||
if "RemainingPower" in payload:
|
||||
print("set RemainingPower: " + str(int(payload["RemainingPower"])))
|
||||
@ -163,8 +198,9 @@ def on_disconnect(client, userdata, flags, reason_code, properties):
|
||||
client.reconnect()
|
||||
|
||||
def main():
|
||||
while True:
|
||||
try:
|
||||
print("starting ...")
|
||||
|
||||
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
||||
mqttc.on_connect = on_connect
|
||||
mqttc.on_subscribe = on_subscribe
|
||||
@ -172,7 +208,9 @@ def main():
|
||||
mqttc.on_disconnect = on_disconnect
|
||||
mqttc.username_pw_set(config.ttn_user, config.ttn_key)
|
||||
mqttc.tls_set()
|
||||
mqttc.connect(config.ttn_region.lower() + ".cloud.thethings.network", 8883, 60)
|
||||
mqttc.connect(
|
||||
config.ttn_region.lower() + ".cloud.thethings.network", 8883, 60
|
||||
)
|
||||
mqttc.subscribe("#", 0) # all device uplinks
|
||||
|
||||
# run mqtt in thread forever
|
||||
@ -190,6 +228,9 @@ def main():
|
||||
webServer.server_close()
|
||||
print("Server stopped.")
|
||||
poll_mqtt_thread.join()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
time.sleep(60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user