Documentation ¶
Overview ¶
The mon2prom package supports reading TimeSeries metric values from GCP (Google Cloud Platform) and exporting them as Prometheus metrics.
Index ¶
- Variables
- func MetricFetcher(monClient mon.Client) (chan<- UpdateRequest, func())
- type ForHumans
- type PromVector
- func (pv *PromVector) Clear()
- func (pv *PromVector) Collect(ch chan<- prom.Metric)
- func (pv *PromVector) Describe(ch chan<- *prom.Desc)
- func (pv *PromVector) ForHumans() (unit string, scale string, count int, bucketType string, buckets interface{})
- func (pv *PromVector) Populate(ts *sd.TimeSeries, pt *sd.Point) bool
- func (pv *PromVector) Publish()
- func (pv *PromVector) ReadOnlyMap() map[label.RuneList]value.Metric
- func (pv *PromVector) Schedule(ch chan<- UpdateRequest, end string, seq int)
- func (pv *PromVector) Update(monClient mon.Client, ch chan<- UpdateRequest)
- type UpdateRequest
Constants ¶
This section is empty.
Variables ¶
var WasScraped = false
Functions ¶
func MetricFetcher ¶
func MetricFetcher(monClient mon.Client) (chan<- UpdateRequest, func())
Returns a runner that updates PromVector values and a channel that each PromVector uses to request an update. Invoke the runner function once all of the PromVectors have been initialized:
ch, runner := mon2prom.MetricFetcher(monClient) for md := range monClient.StreamMetricDescs(nil, projectID, prefix) { mon2prom.NewVec(projectID, monClient, md, ch) } go runner()
Types ¶
type ForHumans ¶
type ForHumans struct { Unit string Scale string MonCount int BucketType string MonBuckets interface{} }
Descriptive data for a GCP metric that we may want to report at start-up. This structure can be freed after start-up is finished.
type PromVector ¶
type PromVector struct { ProjectID string // GCP Project Name (ID) MonDesc *sd.MetricDescriptor PromName string // Metric name in Prometheus PromDesc *prom.Desc MetricKind mon.MetricKind // 'D'elta, 'G'auge, or 'C'ounter ValueType mon.ValueType // Histogram, Int, Float, or Bool BucketOpts *sd.BucketOptions BucketBounds []float64 // Boundaries between hist buckets SubBuckets []int // Count of SD buckets in each Prom one. label.Set // To build hash keys from label values. PrevEnd string // Timestamp of prior sample period end. PrevWhen time.Time // When fetched prior period (debug). NextWhen time.Time // When we will fetch next period. UpdateStart time.Time // Used for debugging timing quirks. MetricMap *map[label.RuneList]value.Metric ReadOnly atomic.Value // Read-only metric map to export. // contains filtered or unexported fields }
A vector of Prometheus metrics exported from a GCP metric. Each metric in a vector has a different set of label values.
func NewVec ¶
func NewVec( projectID string, monClient mon.Client, md *sd.MetricDescriptor, ch chan<- UpdateRequest, ) *PromVector
Creates a new PromVector, initializes it from recent TimeSeries data, and schedules it to be updated as time goes on. Returns `nil` if the configuration does not specify how this metric should be exported.
func (*PromVector) Clear ¶
func (pv *PromVector) Clear()
Replaces pv.MetricMap with an empty map (not disturbing the map that pv.MetricMap used to point to, which is now the read-only map). If pv refers to a Delta metric kind, then the read-only metrics from the read-only map get (deep) copied into the new map, so that these Counter metrics don't lose their accumulated value.
func (*PromVector) Collect ¶
func (pv *PromVector) Collect(ch chan<- prom.Metric)
Writes out (in protobuf format) each metric in the vector.
func (*PromVector) Describe ¶
func (pv *PromVector) Describe(ch chan<- *prom.Desc)
Just returns the prometheus *Desc for the metric.
func (*PromVector) ForHumans ¶
func (pv *PromVector) ForHumans() ( unit string, scale string, count int, bucketType string, buckets interface{}, )
Returns information that humans might want to know about the metric being exported and then frees up that information to save space. Calling it a second time just gives you zero values for all of the items.
func (*PromVector) Populate ¶
func (pv *PromVector) Populate(ts *sd.TimeSeries, pt *sd.Point) bool
Inserts or updates a single metric value in the metric map based on the latest sample period of the GCP metric.
func (*PromVector) Publish ¶
func (pv *PromVector) Publish()
Converts all of the metrics in pv.MetricMap to be read-only metrics and then atomically replaces the pointer to the old read-only map with the pointer in pv.MetricMap.
func (*PromVector) ReadOnlyMap ¶
func (pv *PromVector) ReadOnlyMap() map[label.RuneList]value.Metric
Atomically fetches the pointer to the read-only map of read-only metrics, usually so that they can be exported by Collect() while updates might be simultaneously applied to the not-read-only map.
func (*PromVector) Schedule ¶
func (pv *PromVector) Schedule( ch chan<- UpdateRequest, end string, seq int, )
Schedules when to request that the values for this metric next be updated. We compute when the next sample period should be available (plus a few random seconds to reduce "thundering herd") and schedule pv to be sent to the metric runner's channel at that time.
func (*PromVector) Update ¶
func (pv *PromVector) Update(monClient mon.Client, ch chan<- UpdateRequest)
Iterates over all of the TimeSeries values for a single GCP metric and Populates() them into the metric map.
type UpdateRequest ¶
type UpdateRequest struct {
// contains filtered or unexported fields
}
What gets sent to request a metric be updated.
Directories ¶
Path | Synopsis |
---|---|
This package deals with sets of metric labels and lists of label values.
|
This package deals with sets of metric labels and lists of label values. |
The `value` package contains the types for holding individual metric values (either just a float64 or the numeric state for a histogram).
|
The `value` package contains the types for holding individual metric values (either just a float64 or the numeric state for a histogram). |