PHP 8.2.30
Preview: gc_collector.py Size: 1.48 KB
/opt/hc_python/lib64/python3.12/site-packages/prometheus_client/gc_collector.py

import gc
import platform
from typing import Iterable

from .metrics_core import CounterMetricFamily, Metric
from .registry import Collector, CollectorRegistry, REGISTRY


class GCCollector(Collector):
    """Collector for Garbage collection statistics."""

    def __init__(self, registry: CollectorRegistry = REGISTRY):
        if not hasattr(gc, 'get_stats') or platform.python_implementation() != 'CPython':
            return
        registry.register(self)

    def collect(self) -> Iterable[Metric]:
        collected = CounterMetricFamily(
            'python_gc_objects_collected',
            'Objects collected during gc',
            labels=['generation'],
        )
        uncollectable = CounterMetricFamily(
            'python_gc_objects_uncollectable',
            'Uncollectable objects found during GC',
            labels=['generation'],
        )

        collections = CounterMetricFamily(
            'python_gc_collections',
            'Number of times this generation was collected',
            labels=['generation'],
        )

        for gen, stat in enumerate(gc.get_stats()):
            generation = str(gen)
            collected.add_metric([generation], value=stat['collected'])
            uncollectable.add_metric([generation], value=stat['uncollectable'])
            collections.add_metric([generation], value=stat['collections'])

        return [collected, uncollectable, collections]


GC_COLLECTOR = GCCollector()
"""Default GCCollector in default Registry REGISTRY."""

Directory Contents

Dirs: 4 × Files: 19

Name Size Perms Modified Actions
bridge DIR
- drwxr-xr-x 2025-04-04 08:01:58
Edit Download
- drwxr-xr-x 2025-04-04 08:01:58
Edit Download
twisted DIR
- drwxr-xr-x 2025-04-04 08:01:58
Edit Download
- drwxr-xr-x 2025-04-04 08:01:58
Edit Download
1.57 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
2.29 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
860 B lrw-r--r-- 2025-04-04 08:01:58
Edit Download
15.43 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
25.56 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
1.48 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
27.45 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
15.18 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
5.27 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
7.36 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
7.26 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
1.83 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
3.77 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
0 B lrw-r--r-- 2025-04-04 08:01:58
Edit Download
6.05 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
1.65 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
594 B lrw-r--r-- 2025-04-04 08:01:58
Edit Download
4.88 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download
1.77 KB lrw-r--r-- 2025-04-04 08:01:58
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).