mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
Add Prometheus Service Discovery for online devices (#3788)
This commit is contained in:
parent
b3cca5dcb6
commit
a5e3cd1a42
1 changed files with 28 additions and 0 deletions
|
@ -644,6 +644,33 @@ def _ping_func(filename, address):
|
|||
return filename, rc == 0
|
||||
|
||||
|
||||
class PrometheusServiceDiscoveryHandler(BaseHandler):
|
||||
@authenticated
|
||||
def get(self):
|
||||
entries = _list_dashboard_entries()
|
||||
self.set_header("content-type", "application/json")
|
||||
sd = []
|
||||
for entry in entries:
|
||||
if entry.web_port is None:
|
||||
continue
|
||||
labels = {
|
||||
"__meta_name": entry.name,
|
||||
"__meta_esp_platform": entry.target_platform,
|
||||
"__meta_esphome_version": entry.storage.esphome_version,
|
||||
}
|
||||
for integration in entry.storage.loaded_integrations:
|
||||
labels[f"__meta_integration_{integration}"] = "true"
|
||||
sd.append(
|
||||
{
|
||||
"targets": [
|
||||
f"{entry.address}:{entry.web_port}",
|
||||
],
|
||||
"labels": labels,
|
||||
}
|
||||
)
|
||||
self.write(json.dumps(sd))
|
||||
|
||||
|
||||
class MDNSStatusThread(threading.Thread):
|
||||
def run(self):
|
||||
global IMPORT_RESULT
|
||||
|
@ -993,6 +1020,7 @@ def make_app(debug=get_bool_env(ENV_DEV)):
|
|||
(f"{rel}import", ImportRequestHandler),
|
||||
(f"{rel}secret_keys", SecretKeysRequestHandler),
|
||||
(f"{rel}rename", EsphomeRenameHandler),
|
||||
(f"{rel}prometheus-sd", PrometheusServiceDiscoveryHandler),
|
||||
],
|
||||
**app_settings,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue