Documentation ¶
Overview ¶
Usage:
import "github.com/baidu/go-lib/web-monitor/metrics" // define counter struct type type ServerState { ReqServed *Counter // field type must be *Counter or *Gauge or *State ConServed *Counter ConActive *Gauge } // create metrics var m Metrics var s ServerState m.Init(&s, "PROXY", 20) // counter operations s.ConActive.Inc(2) s.ConServed.Inc(1) s.ReqServed.Inc(1) s.ConActive.Dec(1) m.Counter("CounterName").Inc(1) m.Gauge("GaugeName").Inc(1) m.State("StateName").Set("StateValue") // get absoulute data for all metrics stateData := m.GetAll() // get diff data for all counters(gauge don't have diff data) stateDiff := m.GetDiff()
Index ¶
Constants ¶
View Source
const ( KindTotal = "total" KindDelta = "delta" )
View Source
const ( TypeGauge = "Gauge" TypeCounter = "Counter" TypeState = "State" )
View Source
const (
DefaultInterval = 20 // in seconds
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Counter ¶
type Counter uint64
Counter is a cumulative metric that represents a single monotonically increasing counter whose value can only increase or be reset to zero on restart
type Gauge ¶
type Gauge int64
Gauge is a Metric that represents a single numerical value that can arbitrarily go up and down.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
func NewEmptyMetrics ¶
NewEmptyMetrics initializes empty Metrics
func (*Metrics) GetAll ¶
func (m *Metrics) GetAll() *MetricsData
GetAll gets absoulute values for all counters
func (*Metrics) GetDiff ¶
func (m *Metrics) GetDiff() *MetricsData
GetDiff gets diff values for all counters
type MetricsData ¶
type MetricsData struct { Prefix string Kind string GaugeData map[string]int64 CounterData map[string]int64 StateData map[string]string }
func NewMetricsData ¶
func NewMetricsData(prefix string, kind string) *MetricsData
func (*MetricsData) Diff ¶
func (d *MetricsData) Diff(last *MetricsData) *MetricsData
func (*MetricsData) Format ¶
func (d *MetricsData) Format(params map[string][]string) ([]byte, error)
func (*MetricsData) KeyValueFormat ¶
func (d *MetricsData) KeyValueFormat() []byte
func (*MetricsData) PrometheusFormat ¶
func (d *MetricsData) PrometheusFormat() []byte
func (*MetricsData) Sum ¶
func (d *MetricsData) Sum(d2 *MetricsData) *MetricsData
Click to show internal directories.
Click to hide internal directories.