def expose_info() -> None: """Exposes a gauge with info label values.""" telemetry.info({ "interval_seconds": str(s.INTERVAL), }) info_interval = telemetry.gauge("info_interval_seconds", "Configured interval in seconds.") info_interval.set(s.INTERVAL)
from typing import Callable, List from loguru import logger from prometheus_ecs_discoverer import s, telemetry, toolbox # Copyright 2018, 2019 Signal Media Ltd. Licensed under the Apache License 2.0 # Modifications Copyright 2020 Tim Schwenke. Licensed under the Apache License 2.0 HITS = telemetry.gauge("cache_hits", "Number of cache hits just before moving window.", ("cache_name", )) MISSES = telemetry.gauge("cache_misses", "Number of cache misses just before moving window.", ("cache_name", )) CURRENT_CACHE_ENTRIES = telemetry.gauge("current_cache_entries", "Number of current cache entries.", ("cache_name", )) NEXT_CACHE_ENTRIES = telemetry.gauge("next_cache_entries", "Number of next cache entries.", ("cache_name", )) class SlidingCache: """Cache consisting out of two slots with a sliding window. Data is a nested dictionary. Works by taking a list of keys and first checking the cached dict for corresponding entries. Keys without matching entries are passed on to a fetch function. Other data is thrown away. How to use:
from prometheus_ecs_discoverer import s, telemetry, toolbox from prometheus_ecs_discoverer.caching import SlidingCache # Copyright 2018, 2019 Signal Media Ltd. Licensed under the Apache License 2.0 # Modifications Copyright 2020 Tim Schwenke. Licensed under the Apache License 2.0 """ The only place in this package that directly interacts with the AWS API. Contains the cached fetcher that ensures that expensive calls to the AWS API are cached. """ # Telemetry ==================================================================== CLUSTERS = telemetry.gauge("clusters", "Fetched clusters.") CINSTANCES = telemetry.gauge( "container_instances", "Fetched container instances.", ("cluster",) ) TASKS = telemetry.gauge("tasks", "Fetched tasks.", ("cluster",)) DURATION = telemetry.histogram( "api_requests_duration_seconds", "Duration of requests to the AWS API.", ("method",) ) # ============================================================================== class CachedFetcher: """Works with the AWS API and leverages a sliding cache. Reduces the amount of request made to the AWS API helping to stay below the
from prometheus_ecs_discoverer import s, telemetry, toolbox from prometheus_ecs_discoverer.fetching import CachedFetcher # Copyright 2018, 2019 Signal Media Ltd. Licensed under the Apache License 2.0 # Modifications Copyright 2020 Tim Schwenke. Licensed under the Apache License 2.0 """Contains most of the business logic of the Prometheus ECS discoverer. Queries the AWS API / cache and tries to build up a collection of target objects that represent targets for Prometheus. """ # ============================================================================== # Telemetry TASK_INFOS = telemetry.gauge("task_infos", "Discovered and built task infos.") TARGETS = telemetry.gauge("targets", "Discovered and built targets.") TDEFINITIONS = telemetry.gauge("task_definitions", "Fetched task definitions.") TARGETS_MARKED = telemetry.gauge( "targets_marked", "Discovered targets that are marked as Prometheus targets.") targets_marked_counter = 0 # Counter per round. TARGETS_MARKED_REJECTED = telemetry.gauge( "targets_marked_rejected", "Discovered targets marked as Prometheus targets that have been rejected.", ) targets_marked_rejected_counter = 0 # Counter per round. # ==============================================================================
def test_gauge(): gauge = telemetry.gauge("gauge", "doc") assert gauge._name.startswith( f"{s.PROMETHEUS_NAMESPACE}_{s.PROMETHEUS_SUBSYSTEM}")