Improve exporter metric emission logging
This commit is contained in:
@@ -44,6 +44,29 @@ LAST_CHECK = Gauge(
|
|||||||
"Last time the update check ran (unix timestamp)"
|
"Last time the update check ran (unix timestamp)"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def set_container_update_metric(container_name, compose_image, running_image, project_name, update_flag):
|
||||||
|
"""Set update metric for a container and log the emitted metric payload."""
|
||||||
|
metric_labels = {
|
||||||
|
"container": container_name,
|
||||||
|
"compose_image": compose_image or "unknown",
|
||||||
|
"running_image": running_image,
|
||||||
|
"com_docker_compose_project": project_name,
|
||||||
|
}
|
||||||
|
CONTAINER_UPDATE.labels(**metric_labels).set(update_flag)
|
||||||
|
logger.info(
|
||||||
|
"Metric emitted: docker_container_update_available=%s labels=%s",
|
||||||
|
update_flag,
|
||||||
|
metric_labels,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def set_last_check_metric():
|
||||||
|
"""Set and log the timestamp for the most recent check cycle."""
|
||||||
|
ts = time.time()
|
||||||
|
LAST_CHECK.set(ts)
|
||||||
|
logger.info("Metric emitted: docker_image_update_last_check_timestamp=%s", ts)
|
||||||
|
|
||||||
# --- Persistent Cache ---
|
# --- Persistent Cache ---
|
||||||
def load_cache():
|
def load_cache():
|
||||||
if not os.path.exists(CACHE_FILE):
|
if not os.path.exists(CACHE_FILE):
|
||||||
@@ -380,6 +403,8 @@ def check_containers():
|
|||||||
if client is None:
|
if client is None:
|
||||||
logger.error("Docker client is unavailable; skipping check cycle")
|
logger.error("Docker client is unavailable; skipping check cycle")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
set_last_check_metric()
|
||||||
CONTAINER_UPDATE.clear()
|
CONTAINER_UPDATE.clear()
|
||||||
|
|
||||||
project_name = parse_project_name_from_script(SERVICES_UP_SCRIPT)
|
project_name = parse_project_name_from_script(SERVICES_UP_SCRIPT)
|
||||||
@@ -409,12 +434,13 @@ def check_containers():
|
|||||||
if local_digest and remote_digest and local_digest != remote_digest:
|
if local_digest and remote_digest and local_digest != remote_digest:
|
||||||
update_flag = 1
|
update_flag = 1
|
||||||
|
|
||||||
CONTAINER_UPDATE.labels(
|
set_container_update_metric(
|
||||||
container=container.name,
|
container_name=container.name,
|
||||||
compose_image=compose_image or "unknown",
|
compose_image=compose_image,
|
||||||
running_image=running,
|
running_image=running,
|
||||||
com_docker_compose_project=proj
|
project_name=proj,
|
||||||
).set(update_flag)
|
update_flag=update_flag,
|
||||||
|
)
|
||||||
|
|
||||||
def dump_service_image_mapping():
|
def dump_service_image_mapping():
|
||||||
project_name = parse_project_name_from_script(SERVICES_UP_SCRIPT)
|
project_name = parse_project_name_from_script(SERVICES_UP_SCRIPT)
|
||||||
|
|||||||
Reference in New Issue
Block a user