# Poco::Prometheus

# class Collector

Library: Prometheus
Package: Core
Header: Poco/Prometheus/Collector.h

## Description

This is the base class for all metrics, such as Counter, Gauge and Histogram.

Collector objects automatically register themselves with the default Registry (unless a nullptr is passed to the constructor's pRegistry parameter), but do not automatically unregister. This brings the danger of dangling pointers if Collector instances are destroyed without being explicitly unregistered first. In most practical cases this is not an issue as Collector instances will be alive for the entire run time of the process. However, it can be an issue if Collector instances are created and destroyed dynamically during the run time of the process.

## Inheritance

Known Derived Classes: CallbackMetric, IntCounter, IntGauge, LabeledMetric, LabeledMetricImpl, Metric, ProcessCollector, ThreadPoolCollector

## Member Summary

Member Functions: exportTo, name, validateName

## Constructors

### Collector

Collector(
const std::string & name
);

Creates a Collector with the given name and registers it with the default Registry.

The name must be a valid metric name and match the regular expression [a-zA-Z_:][a-zA-Z0-9_:]*.

### Collector

Collector(
const std::string & name,
Registry * pRegistry
);

Creates a Collector with the given name and registers it with the given Registry (if not nullptr).

The name must be a valid metric name and match the regular expression [a-zA-Z_:][a-zA-Z0-9_:]*.

## Destructor

### ~Collector

virtual ~Collector() = default;

Destroys the Collector.

## Member Functions

### exportTo

virtual void exportTo(
Exporter & exporter
) const = 0;

Writes the given Metric to the Exporter.

### name

const std::string & name() const;

Returns the metric's name.

### validateName

static const std::string & validateName(
const std::string & name
);