Ejemplo n.º 1
0
    def report_runtime_metrics(self, batch: metrics.Client) -> None:
        if not isinstance(self.connection_pool, redis.BlockingConnectionPool):
            return

        size = self.connection_pool.max_connections
        in_use = len(self.connection_pool._connections)  # type: ignore

        batch.gauge("pool.size").replace(size)
        batch.gauge("pool.in_use").replace(in_use)
Ejemplo n.º 2
0
    def report_runtime_metrics(self, batch: metrics.Client) -> None:
        if not isinstance(self.connection_pool,
                          rediscluster.ClusterBlockingConnectionPool):
            return

        size = self.connection_pool.max_connections
        open_connections = len(self.connection_pool._connections)

        batch.gauge("pool.size").replace(size)
        batch.gauge("pool.open_connections").replace(open_connections)
Ejemplo n.º 3
0
def _report_runtime_metrics_periodically(
        metrics_client: metrics.Client,
        reporters: List[_Reporter]) -> NoReturn:
    hostname = socket.gethostname()
    pid = os.getpid()

    while True:
        now = time.time()
        time_since_last_report = now % REPORT_INTERVAL_SECONDS
        time_until_next_report = REPORT_INTERVAL_SECONDS - time_since_last_report
        time.sleep(time_until_next_report)

        try:
            with metrics_client.batch() as batch:
                batch.namespace += f".runtime.{hostname}.PID{pid}".encode()
                for reporter in reporters:
                    try:
                        reporter.report(batch)
                    except Exception as exc:
                        logger.debug(
                            "Error generating server metrics: %s: %s",
                            reporter.__class__.__name__,
                            exc,
                        )
        except Exception as exc:
            logger.debug("Error while sending server metrics: %s", exc)
Ejemplo n.º 4
0
    def report_runtime_metrics(self, batch: metrics.Client) -> None:
        pool = self.engine.pool
        if not isinstance(pool, QueuePool):
            return

        batch.gauge("pool.size").replace(pool.size())
        batch.gauge("pool.open_and_available").replace(pool.checkedin())
        batch.gauge("pool.in_use").replace(pool.checkedout())
        batch.gauge("pool.overflow").replace(max(pool.overflow(), 0))
Ejemplo n.º 5
0
    def report_runtime_metrics(self, batch: metrics.Client) -> None:
        if not isinstance(self.connection_pool, redis.BlockingConnectionPool):
            return

        size = self.connection_pool.max_connections
        open_connections = len(
            self.connection_pool._connections)  # type: ignore
        available = self.connection_pool.pool.qsize()
        in_use = size - available

        batch.gauge("pool.size").replace(size)
        batch.gauge("pool.in_use").replace(in_use)
        batch.gauge("pool.open_and_available").replace(open_connections -
                                                       in_use)
Ejemplo n.º 6
0
 def report_runtime_metrics(self, batch: metrics.Client) -> None:
     batch.gauge("pool.size").replace(self.pool.size)
     batch.gauge("pool.in_use").replace(self.pool.checkedout)
Ejemplo n.º 7
0
 def report_memcache_runtime_metrics(self, batch: metrics.Client) -> None:
     pool = self.pooled_client.client_pool
     batch.gauge("pool.in_use").replace(len(pool.used))
     batch.gauge("pool.open_and_available").replace(len(pool.free))
     batch.gauge("pool.size").replace(pool.max_size)