luci: go.chromium.org/luci/common/tsmon Index | Files | Directories

package tsmon

import "go.chromium.org/luci/common/tsmon"

Package tsmon contains global state and utility functions for configuring and interacting with tsmon. This has a similar API to the infra-python ts_mon module.

If your application accepts command line flags, then call InitializeFromFlags from your main function.

If you use tsmon on AppEngine, then see appengine/tsmon package doc.

Index

Package Files

callback.go config.go context.go doc.go flags.go flush.go flushType.go iface.go

Constants

const (
    // FlushManual requires the user to flush manually.
    FlushManual = FlushType("manual")
    // FlushAuto automatically flushes at a periodic flush interval.
    FlushAuto = FlushType("auto")
)

func Flush Uses

func Flush(c context.Context) error

Flush sends all the metrics that are registered in the application.

func Initialize Uses

func Initialize(c context.Context, m monitor.Monitor, s store.Store)

Initialize configures the tsmon library with the given monitor and store.

func InitializeFromFlags Uses

func InitializeFromFlags(c context.Context, fl *Flags) error

InitializeFromFlags configures the tsmon library from flag values.

This will set a Target (information about what's reporting metrics) and a Monitor (where to send the metrics to).

func Monitor Uses

func Monitor(c context.Context) monitor.Monitor

Monitor returns the global monitor that sends metrics to monitoring endpoints. Defaults to a nil monitor, but changed by InitializeFromFlags.

func RegisterCallback Uses

func RegisterCallback(f Callback)

RegisterCallback registers a callback function that will be run at metric collection time to set the values of one or more metrics. RegisterCallback should be called from an init() function in your module.

func RegisterCallbackIn Uses

func RegisterCallbackIn(c context.Context, f Callback)

RegisterCallbackIn is like RegisterCallback but registers in a given context.

func RegisterGlobalCallback Uses

func RegisterGlobalCallback(f Callback, metrics ...types.Metric)

RegisterGlobalCallback registers a callback function that will be run once per minute on *one* instance of your application. It is supported primarily on GAE.

You must specify the list of metrics that your callback affects - these metrics will be reset after flushing to ensure they are not sent by multiple instances.

RegisterGlobalCallback should be called from an init() function in your module.

func RegisterGlobalCallbackIn Uses

func RegisterGlobalCallbackIn(c context.Context, f Callback, metrics ...types.Metric)

RegisterGlobalCallbackIn is like RegisterGlobalCallback but registers in a given context.

func ResetCumulativeMetrics Uses

func ResetCumulativeMetrics(c context.Context)

ResetCumulativeMetrics resets only cumulative metrics.

func SetStore Uses

func SetStore(c context.Context, s store.Store)

SetStore changes the global metric store. All metrics that were registered with the old store will be re-registered on the new store.

func Shutdown Uses

func Shutdown(c context.Context)

Shutdown gracefully terminates the tsmon by doing the final flush and disabling auto flush (if it was enabled).

It resets Monitor and Store.

Logs error to standard logger. Does nothing if tsmon wasn't initialized.

func Store Uses

func Store(c context.Context) store.Store

Store returns the global metric store that contains all the metric values for this process. Applications shouldn't need to access this directly - instead use the metric objects which provide type-safe accessors.

func WithDummyInMemory Uses

func WithDummyInMemory(c context.Context) (context.Context, *monitor.Fake)

WithDummyInMemory returns a new context holding a new State with a new in- memory store and a fake monitor.

func WithFakes Uses

func WithFakes(c context.Context) (context.Context, *store.Fake, *monitor.Fake)

WithFakes returns a new context holding a new State with a fake store and a fake monitor.

func WithState Uses

func WithState(c context.Context, s *State) context.Context

WithState returns a new context holding the given State instance.

type Callback Uses

type Callback func(ctx context.Context)

Callback is a function that is run at metric collection time to set the values of one or more metrics. A callback can be registered with RegisterCallback.

type Flags Uses

type Flags struct {
    ConfigFile    string
    Endpoint      string
    Credentials   string
    ActAs         string
    Flush         FlushType
    FlushInterval time.Duration

    Target target.Flags
}

Flags defines command line flags related to tsmon. Use NewFlags() to get a Flags struct with sensible default values.

func NewFlags Uses

func NewFlags() Flags

NewFlags returns a Flags struct with sensible default values.

func (*Flags) Register Uses

func (fl *Flags) Register(f *flag.FlagSet)

Register adds tsmon related flags to a FlagSet.

type FlushType Uses

type FlushType string

FlushType is a flush type enumeration.

func (*FlushType) Set Uses

func (ft *FlushType) Set(v string) error

Set implements flag.Value.

func (*FlushType) String Uses

func (ft *FlushType) String() string

type GlobalCallback Uses

type GlobalCallback struct {
    Callback
    Metrics []types.Metric
}

A GlobalCallback is a Callback with the list of metrics it affects, so those metrics can be reset after they are flushed.

type State Uses

type State struct {
    S       store.Store
    M       monitor.Monitor
    Flusher *autoFlusher

    CallbacksMutex               sync.RWMutex
    Callbacks                    []Callback
    GlobalCallbacks              []GlobalCallback
    InvokeGlobalCallbacksOnFlush bool
}

State holds the configuration of the tsmon library. There is one global instance of State, but it can be overridden in a Context by tests.

func GetState Uses

func GetState(c context.Context) *State

GetState returns the State instance held in the context (if set) or else returns the global state.

func NewState Uses

func NewState() *State

NewState returns a new default State, configured with a nil Store and Monitor.

func (*State) Flush Uses

func (state *State) Flush(c context.Context, mon monitor.Monitor) error

Flush sends all the metrics that are registered in the application.

Uses given monitor if not nil, or the state.M otherwise.

func (*State) ResetCumulativeMetrics Uses

func (state *State) ResetCumulativeMetrics(c context.Context)

ResetCumulativeMetrics resets only cumulative metrics.

func (*State) RunGlobalCallbacks Uses

func (state *State) RunGlobalCallbacks(c context.Context)

RunGlobalCallbacks runs all registered global callbacks that produce global metrics.

See RegisterGlobalCallback for more info.

func (*State) SetStore Uses

func (state *State) SetStore(s store.Store)

SetStore changes the metric store. All metrics that were registered with the old store will be re-registered on the new store.

Directories

PathSynopsis
distributionPackage distribution contains distribution metrics, fixed width and geometric bucketers.
fieldPackage field contains constructors for metric field definitions.
metricPackage metric is the API for defining metrics and updating their values.
monitorPackage monitor contains the code for sending metric data to monitoring endpoints.
registryPackage registry holds a map of all metrics registered by the process.
runtimestatsPackage runtimestats exposes metrics related to the Go runtime.
storePackage store contains code for storing and retreiving metrics.
store/storetestPackage storetest is imported exclusively by tests for Store implementations.
targetPackage target contains information about the thing that is sending metrics - either a NetworkDevice (a machine) or a Task (a service).
ts_mon_protoPackage ts_mon_proto contains ts_mon protobuf source and generated protobuf data.
typesPackage types contains miscellaneous structs and interfaces used throughout tsmon.
versionsPackage versions allows processes to report string-valued metrics with versions of various libraries they link with.

Package tsmon imports 22 packages (graph) and is imported by 9 packages. Updated 2018-10-19. Refresh now. Tools for package owners.