Documentation ¶
Index ¶
- Constants
- Variables
- func DisableLogging()
- func DisableMetricsDump()
- func DumpMetricsNow() error
- func EnableLogging()
- func EnableMetricsDump() error
- func GetMetricsAsJSON() ([]byte, error)
- func LoadMetricsFromDump() error
- func LogMetricsNow()
- func SetLoggingDuration(duration time.Duration) error
- func SetMetricsDumpFilePath(path string)
- type Counter
- type Gauge
- type Metric
- type MetricGroup
- type MetricGroupList
- type MetricType
Constants ¶
const ( // MetricGroup name format for each user. UserMetricGroupFormat = "user - %s" UserMetricUploadBytes = "UploadBytes" UserMetricDownloadBytes = "DownloadBytes" )
Variables ¶
var ( // Max number of connections ever reached. MaxConn = RegisterMetric("connections", "MaxConn", GAUGE) // Accumulated active open connections. ActiveOpens = RegisterMetric("connections", "ActiveOpens", COUNTER) // Accumulated passive open connections. PassiveOpens = RegisterMetric("connections", "PassiveOpens", COUNTER) // Current number of established connections. CurrEstablished = RegisterMetric("connections", "CurrEstablished", GAUGE) // Number of bytes from client to server. UploadBytes = RegisterMetric("traffic", "UploadBytes", COUNTER) // Number of bytes from server to client. DownloadBytes = RegisterMetric("traffic", "DownloadBytes", COUNTER) // Number of padding bytes send to proxy connections. OutputPaddingBytes = RegisterMetric("traffic", "OutputPaddingBytes", COUNTER) )
Functions ¶
func DisableMetricsDump ¶
func DisableMetricsDump()
Stop dumping metrics to a file when it is logged.
func DumpMetricsNow ¶
func DumpMetricsNow() error
DumpMetricsNow writes the current metrics to the dump file. This function can be called when metrics dump is disabled.
func EnableLogging ¶
func EnableLogging()
Enable metrics logging with the given time duration. This function should not be called again before disable logging.
func GetMetricsAsJSON ¶
GetMetricsAsJSON returns a JSON representation of all the metrics.
func LoadMetricsFromDump ¶
func LoadMetricsFromDump() error
func LogMetricsNow ¶
func LogMetricsNow()
LogMetricsNow writes the current metrics to log. This function can be called when (periodic) logging is disabled.
func SetLoggingDuration ¶
Set the metrics logging time duration. Need to disable and enable logging to make the change effective.
func SetMetricsDumpFilePath ¶
func SetMetricsDumpFilePath(path string)
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter holds a named int64 value that can't decrease.
If time series is enabled, user can query history updates in a given time range.
func (*Counter) DeltaBetween ¶
DeltaBetween returns the increment between t1 and t2.
func (*Counter) Type ¶
func (c *Counter) Type() MetricType
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge holds a named int64 value.
func (*Gauge) Type ¶
func (g *Gauge) Type() MetricType
type Metric ¶
type Metric interface { // Name returns the name of metric. Name() string // Type returns the metric type. Type() MetricType // Add increase or decrease the metric by the given value. Add(delta int64) int64 // Load returns the current value of the metric. Load() int64 // Store sets the metric to a particular value. // This operation is only supported by a GAUGE metric. Store(val int64) }
Metric defines supported operations of a single metric.
func RegisterMetric ¶
func RegisterMetric(groupName, metricName string, metricType MetricType) Metric
RegisterMetric registers a new metric. The caller should not take the ownership of the returned pointer. If the same metric is registered multiple times, the pointer to the first object is returned.
type MetricGroup ¶
type MetricGroup struct {
// contains filtered or unexported fields
}
MetricGroup holds a list of metric under the same group.
func GetMetricGroupByName ¶
func GetMetricGroupByName(groupName string) *MetricGroup
GetMetricGroupByName returns the MetricGroup by name. It returns nil if the MetricGroup is not found.
func (*MetricGroup) DisableLogging ¶
func (g *MetricGroup) DisableLogging()
DisableLogging disables logging of this MetricGroup.
func (*MetricGroup) EnableLogging ¶
func (g *MetricGroup) EnableLogging()
EnableLogging enables logging of this MetricGroup.
func (*MetricGroup) GetMetric ¶
func (g *MetricGroup) GetMetric(name string) (Metric, bool)
GetMetric returns one metric from the metric group.
func (*MetricGroup) IsLoggingEnabled ¶
func (g *MetricGroup) IsLoggingEnabled() bool
IsLoggingEnabled returns if logging is enabled in this MetricGroup.
func (*MetricGroup) NewLogFields ¶
func (g *MetricGroup) NewLogFields() log.Fields
NewLogFields creates log fields from the MetricGroup.
func (*MetricGroup) NewLogMsg ¶
func (g *MetricGroup) NewLogMsg() string
NewLogMsg creates a base log message without fields from the MetricGroup.
type MetricGroupList ¶
type MetricGroupList []*MetricGroup
MetricGroupList is a list of MetricGroup.
func (MetricGroupList) Append ¶
func (l MetricGroupList) Append(group *MetricGroup) MetricGroupList
Append adds a new MetricGroup to the end of list.
func (MetricGroupList) Less ¶
func (l MetricGroupList) Less(i, j int) bool
Less implements sort.Interface.
func (MetricGroupList) MarshalJSON ¶
func (l MetricGroupList) MarshalJSON() ([]byte, error)
MarshalJSON export the content of MetricGroupList in JSON format.
func (MetricGroupList) Swap ¶
func (l MetricGroupList) Swap(i, j int)
Swap implements sort.Interface.
type MetricType ¶
type MetricType uint8
const ( COUNTER MetricType = iota COUNTER_TIME_SERIES GAUGE )