Documentation ¶
Index ¶
- type DiskMetricStore
- func (dms *DiskMetricStore) GetMetricFamilies() []*dto.MetricFamily
- func (dms *DiskMetricStore) GetMetricFamiliesMap() GroupingKeyToMetricGroup
- func (dms *DiskMetricStore) Healthy() error
- func (dms *DiskMetricStore) Ready() error
- func (dms *DiskMetricStore) Shutdown() error
- func (dms *DiskMetricStore) SubmitWriteRequest(req WriteRequest)
- type GobbableMetricFamily
- type GroupingKeyToMetricGroup
- type MetricGroup
- type MetricStore
- type NameToTimestampedMetricFamilyMap
- type TimestampedMetricFamily
- type WriteRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiskMetricStore ¶
type DiskMetricStore struct {
// contains filtered or unexported fields
}
DiskMetricStore is an implementation of MetricStore that persists metrics to disk.
func NewDiskMetricStore ¶
func NewDiskMetricStore( persistenceFile string, persistenceInterval time.Duration, gaptherPredefinedHelpFrom prometheus.Gatherer, ) *DiskMetricStore
NewDiskMetricStore returns a DiskMetricStore ready to use. To cleanly shut it down and free resources, the Shutdown() method has to be called.
If persistenceFile is the empty string, no persisting to disk will happen. Otherwise, a file of that name is used for persisting metrics to disk. If the file already exists, metrics are read from it as part of the start-up. Persisting is happening upon shutdown and after every write action, but the latter will only happen persistenceDuration after the previous persisting.
If a non-nil Gatherer is provided, the help strings of metrics gathered by it will be used as standard. Pushed metrics with deviating help strings will be adjusted to avoid inconsistent expositions.
func (*DiskMetricStore) GetMetricFamilies ¶
func (dms *DiskMetricStore) GetMetricFamilies() []*dto.MetricFamily
GetMetricFamilies implements the MetricStore interface.
func (*DiskMetricStore) GetMetricFamiliesMap ¶
func (dms *DiskMetricStore) GetMetricFamiliesMap() GroupingKeyToMetricGroup
GetMetricFamiliesMap implements the MetricStore interface.
func (*DiskMetricStore) Healthy ¶ added in v0.5.0
func (dms *DiskMetricStore) Healthy() error
Healthy implements the MetricStore interface.
func (*DiskMetricStore) Ready ¶ added in v0.5.0
func (dms *DiskMetricStore) Ready() error
Ready implements the MetricStore interface.
func (*DiskMetricStore) Shutdown ¶
func (dms *DiskMetricStore) Shutdown() error
Shutdown implements the MetricStore interface.
func (*DiskMetricStore) SubmitWriteRequest ¶
func (dms *DiskMetricStore) SubmitWriteRequest(req WriteRequest)
SubmitWriteRequest implements the MetricStore interface.
type GobbableMetricFamily ¶ added in v0.5.0
type GobbableMetricFamily dto.MetricFamily
GobbableMetricFamily is a dto.MetricFamily that implements GobDecoder and GobEncoder.
func (*GobbableMetricFamily) GobDecode ¶ added in v0.5.0
func (gmf *GobbableMetricFamily) GobDecode(b []byte) error
GobDecode implements gob.GobDecoder.
func (*GobbableMetricFamily) GobEncode ¶ added in v0.5.0
func (gmf *GobbableMetricFamily) GobEncode() ([]byte, error)
GobEncode implements gob.GobEncoder.
type GroupingKeyToMetricGroup ¶
type GroupingKeyToMetricGroup map[uint64]MetricGroup
GroupingKeyToMetricGroup is the first level of the metric store, keyed by grouping key.
type MetricGroup ¶
type MetricGroup struct { Labels map[string]string Metrics NameToTimestampedMetricFamilyMap }
MetricGroup adds the grouping labels to a NameToTimestampedMetricFamilyMap.
func (MetricGroup) SortedLabels ¶
func (mg MetricGroup) SortedLabels() []string
SortedLabels returns the label names of the grouping labels sorted lexicographically but with the "job" label always first. This method exists for presentation purposes, see template.html.
type MetricStore ¶
type MetricStore interface { // SubmitWriteRequest submits a WriteRequest for processing. There is no // guarantee when a request will be processed, but it is guaranteed that // the requests are processed in the order of submission. SubmitWriteRequest(req WriteRequest) // GetMetricFamilies returns all the currently saved MetricFamilies. The // returned MetricFamilies are guaranteed to not be modified by the // MetricStore anymore. However, they may still be read somewhere else, // so the caller is not allowed to modify the returned MetricFamilies. // If different groups have saved MetricFamilies of the same name, they // are all merged into one MetricFamily by concatenating the contained // Metrics. Inconsistent help strings or types are logged, and one of // the versions will "win". Inconsistent and duplicate label sets will // go undetected. GetMetricFamilies() []*dto.MetricFamily // GetMetricFamiliesMap returns a map grouping-key -> MetricGroup. The // MetricFamily pointed to by the Metrics map in each MetricGroup is // guaranteed to not be modified by the MetricStore anymore. However, // they may still be read somewhere else, so the caller is not allowed // to modify it. Otherwise, the returned nested map is a deep copy of // the internal state of the MetricStore and completely owned by the // caller. GetMetricFamiliesMap() GroupingKeyToMetricGroup // Shutdown must only be called after the caller has made sure that // SubmitWriteRequests is not called anymore. (If it is called later, // the request might get submitted, but not processed anymore.) The // Shutdown method waits for the write request queue to empty, then it // persists the content of the MetricStore (if supported by the // implementation). Also, all internal goroutines are stopped. This // method blocks until all of that is complete. If an error is // encountered, it is returned (whereupon the MetricStorage is in an // undefinded state). If nil is returned, the MetricStore cannot be // "restarted" again, but it can still be used for read operations. Shutdown() error // Healthy returns nil if the MetricStore is currently working as // expected or false, Error if it is not. Healthy() error // Ready returns nil if the MetricStore is ready to be used (all files // are opened and checkpoints have been restored) or false, Error if it // is not. Ready() error }
MetricStore is the interface to the storage layer for metrics. All its methods must be safe to be called concurrently.
type NameToTimestampedMetricFamilyMap ¶
type NameToTimestampedMetricFamilyMap map[string]TimestampedMetricFamily
NameToTimestampedMetricFamilyMap is the second level of the metric store, keyed by metric name.
type TimestampedMetricFamily ¶
type TimestampedMetricFamily struct { Timestamp time.Time GobbableMetricFamily *GobbableMetricFamily }
TimestampedMetricFamily adds the push timestamp to a gobbable version of the MetricFamily-DTO.
func (TimestampedMetricFamily) GetMetricFamily ¶ added in v0.5.0
func (tmf TimestampedMetricFamily) GetMetricFamily() *dto.MetricFamily
GetMetricFamily returns the normal GetMetricFamily DTO (without the gob additions).
type WriteRequest ¶
type WriteRequest struct { Labels map[string]string Timestamp time.Time MetricFamilies map[string]*dto.MetricFamily }
WriteRequest is a request to change the MetricStore, i.e. to process it, a write lock has to be acquired. If MetricFamilies is nil, this is a request to delete metrics that share the given Labels as a grouping key. Otherwise, this is a request to update the MetricStore with the MetricFamilies. The key in MetricFamilies is the name of the mapped metric family. All metrics in MetricFamilies MUST have already set job and other labels that are consistent with the Labels fields. The Timestamp field marks the time the request was received from the network. It is not related to the timestamp_ms field in the Metric proto message.