from prometheus_client import CollectorRegistry registry = CollectorRegistry()
from prometheus_client import Counter registry = CollectorRegistry() my_counter = Counter('mycounter', 'Description of my counter', registry=registry)
from prometheus_client import REGISTRY collectors = list(REGISTRY.collect())This code retrieves all of the collectors from the global Registry instance that is automatically created when the prometheus_client package is imported. The collectors are returned as a list. In summary, the CollectorRegistry class in the python prometheus_client package library is used to create a registry for collectors that gather metrics for an application. The examples provided demonstrate how to create a new registry instance, add a collector to a registry, and retrieve all collectors from a registry.