Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConstMetric ¶ added in v0.6.0
type CounterStoreFactory ¶ added in v0.19.0
type CounterStoreFactory func(logger *slog.Logger, ttl time.Duration) DeltaCounterStore
CounterStoreFactory creates a DeltaCounterStore for a given TTL.
type DeltaCounterStore ¶ added in v0.13.0
type DeltaCounterStore interface {
Increment(metricDescriptor *monitoring.MetricDescriptor, currentValue *ConstMetric)
ListMetrics(metricDescriptorName string) []*ConstMetric
}
type DeltaHistogramStore ¶ added in v0.15.0
type DeltaHistogramStore interface {
Increment(metricDescriptor *monitoring.MetricDescriptor, currentValue *HistogramMetric)
ListMetrics(metricDescriptorName string) []*HistogramMetric
}
type DescriptorCache ¶ added in v0.14.0
type DescriptorCache interface {
// Lookup searches the cache for an entry. If the cache has no entry or the entry has expired nil is returned.
Lookup(prefix string) []*monitoring.MetricDescriptor
// Store stores an entry in the cache
Store(prefix string, data []*monitoring.MetricDescriptor)
}
type HistogramMetric ¶ added in v0.6.0
type HistogramMetric struct {
FqName string
LabelKeys []string
Sum float64
Count uint64
Buckets map[float64]uint64
LabelValues []string
ReportTime time.Time
CollectionTime time.Time
KeysHash uint64
}
func (*HistogramMetric) MergeHistogram ¶ added in v0.15.1
func (h *HistogramMetric) MergeHistogram(other *HistogramMetric)
type HistogramStoreFactory ¶ added in v0.19.0
type HistogramStoreFactory func(logger *slog.Logger, ttl time.Duration) DeltaHistogramStore
HistogramStoreFactory creates a DeltaHistogramStore for a given TTL.
type MetricFilter ¶ added in v0.12.0
func ParseMetricExtraFilters ¶ added in v0.19.0
func ParseMetricExtraFilters(raw []string) []MetricFilter
type MonitoringCollector ¶
type MonitoringCollector struct {
// contains filtered or unexported fields
}
func NewMonitoringCollector ¶
func NewMonitoringCollector(projectID string, monitoringService *monitoring.Service, opts MonitoringCollectorOptions, logger *slog.Logger, counterStore DeltaCounterStore, histogramStore DeltaHistogramStore) (*MonitoringCollector, error)
func (*MonitoringCollector) Collect ¶
func (c *MonitoringCollector) Collect(ch chan<- prometheus.Metric)
func (*MonitoringCollector) Describe ¶
func (c *MonitoringCollector) Describe(ch chan<- *prometheus.Desc)
type MonitoringCollectorOptions ¶ added in v0.13.0
type MonitoringCollectorOptions struct {
// MetricTypePrefixes are the Google Monitoring (ex-Stackdriver) metric type prefixes that the collector
// will be querying.
MetricTypePrefixes []string
// ExtraFilters is a list of criteria to apply to each corresponding metric prefix query. If one or more are
// applicable to a given metric type prefix, they will be 'AND' concatenated.
ExtraFilters []MetricFilter
// RequestInterval is the time interval used in each request to get metrics. If there are many data points returned
// during this interval, only the latest will be reported.
RequestInterval time.Duration
// RequestOffset is used to offset the requested interval into the past.
RequestOffset time.Duration
// IngestDelay decides if the ingestion delay specified in the metrics metadata is used when calculating the
// request time interval.
IngestDelay bool
// FillMissingLabels decides if metric labels should be added with empty string to prevent failures due to label inconsistency on metrics.
FillMissingLabels bool
// DropDelegatedProjects decides if only metrics matching the collector's projectID should be retrieved.
DropDelegatedProjects bool
// AggregateDeltas decides if DELTA metrics should be treated as a counter using the provided counterStore/distributionStore or a gauge
AggregateDeltas bool
// DescriptorCacheTTL is the TTL on the items in the descriptorCache which caches the MetricDescriptors for a MetricTypePrefix
DescriptorCacheTTL time.Duration
// DescriptorCacheOnlyGoogle decides whether only google specific descriptors should be cached or all
DescriptorCacheOnlyGoogle bool
}
type Runtime ¶ added in v0.19.0
type Runtime struct {
// contains filtered or unexported fields
}
Runtime holds the resolved state produced by NewRuntime.
func NewRuntime ¶ added in v0.19.0
func NewRuntime(ctx context.Context, logger *slog.Logger, cfg *config.Config, counterFactory CounterStoreFactory, histogramFactory HistogramStoreFactory) (*Runtime, error)
NewRuntime resolves project IDs and creates the monitoring service. The caller must have run cfg.Validate first.
counterFactory and histogramFactory are invoked each time a new collector is built. The returned Runtime does not cache collectors; call WithCache to derive a sibling that does.
func (*Runtime) Collectors ¶ added in v0.19.0
func (r *Runtime) Collectors() ([]*MonitoringCollector, error)
Collectors builds one MonitoringCollector per resolved project scoped to all configured prefixes.
func (*Runtime) CollectorsForPrefixes ¶ added in v0.19.0
func (r *Runtime) CollectorsForPrefixes(prefixFilter []string) ([]*MonitoringCollector, error)
CollectorsForPrefixes builds one MonitoringCollector per resolved project restricted to the given metric type prefixes. A nil or empty prefixFilter is equivalent to Collectors.
func (*Runtime) WithCache ¶ added in v0.19.0
WithCache returns a Runtime configured to cache its collectors per (project, prefix-filter). Subsequent calls to Collectors or CollectorsForPrefixes reuse cached entries until they expire, which lets delta-counter state survive repeated rebuilds. The TTL is derived from AggregateDeltasTTL and DescriptorCacheTTL.
HTTP scrape paths that rebuild collectors per request (?collect= filtering) want this; embedded callers that hold a long-lived registry do not.
Each call allocates a fresh cache (and its cleanup goroutine); call it once per consumer and discard the receiver.