Documentation ¶
Index ¶
- Constants
- Variables
- func FloatEquals(a, b float64) bool
- func Max(n int, max, v float64) float64
- func Min(n int, min, v float64) float64
- func QPS1(keys ...string)
- func Stop()
- type CurRecorder
- type FailRateRecorder
- type HitRateRecorder
- type Key
- type Line
- type LogType
- type Option
- type OptionFn
- type QPSRecorder
- type RTRecorder
- type Recorder
- type Runner
- func (r *Runner) AsyncPut(keys Key, logType LogType, v1, v2 float64, vx ...float64)
- func (r *Runner) Cur(keys ...string) CurRecorder
- func (r *Runner) FailRate(keys ...string) FailRateRecorder
- func (r *Runner) HitRate(keys ...string) HitRateRecorder
- func (r *Runner) MakeRecorder(logType LogType, keys []string) Recorder
- func (r *Runner) QPS(keys ...string) QPSRecorder
- func (r *Runner) QPS1(keys ...string)
- func (r *Runner) RT(keys ...string) RTRecorder
- func (r *Runner) Start()
- func (r *Runner) Stop()
- func (r *Runner) SuccessRate(keys ...string) SuccessRateRecorder
- type SuccessRateRecorder
Constants ¶
const ( // KeyRT RT 日志类型. KeyRT LogType = "RT" // KeyQPS QPS 日志类型. KeyQPS = "QPS" // KeySuccessRate SuccessRate 日志类型. KeySuccessRate = "SUCCESS_RATE" // KeyFailRate FailRate 日志类型. KeyFailRate = "FAIL_RATE" // KeyHitRate HitRate 日志类型. KeyHitRate = "HIT_RATE" // KeyCUR CUR 日志类型. KeyCUR = "CUR" // HB 特殊处理,每?s记录一次. HB = "HB" )
const TimeLayout = "20060102150405000"
Variables ¶
var DefaultRunner = NewRunner(EnvOption())
DefaultRunner is the default runner for metric recording.
var EPSILON = math.Nextafter(1, 2) - 1
EPSILON。 math.Nextafter(1, 2) 返回的结果是比 1 稍微大一点的浮点数, 它是浮点数 1 在计算机中表示的下一个可表示的值。将这个值减去 1,得到的是 浮点数 1 和它的下一个可表示值之间的差距,这通常被称为“机器精度”或 EPSILON。
Functions ¶
func FloatEquals ¶
Types ¶
type FailRateRecorder ¶
type FailRateRecorder struct{ Recorder }
FailRateRecorder record success rate.
func (FailRateRecorder) IncrFail ¶
func (c FailRateRecorder) IncrFail()
IncrFail increment success count.
func (FailRateRecorder) IncrTotal ¶
func (c FailRateRecorder) IncrTotal()
IncrTotal increment total.
func (FailRateRecorder) Ks ¶
func (c FailRateRecorder) Ks(k *ks.Ks) FailRateRecorder
Ks add extra keys.
type HitRateRecorder ¶
type HitRateRecorder struct{ Recorder }
HitRateRecorder record hit rate.
func (HitRateRecorder) IncrHit ¶
func (c HitRateRecorder) IncrHit()
IncrHit increment success count.
func (HitRateRecorder) Ks ¶
func (c HitRateRecorder) Ks(k *ks.Ks) HitRateRecorder
Ks add extra keys.
type Line ¶
type Line struct { Ks *ks.Ks `json:"-"` K1 string `json:"k1,omitempty"` K2 string `json:"k2,omitempty"` K3 string `json:"k3,omitempty"` K4 string `json:"k4,omitempty"` K5 string `json:"k5,omitempty"` K6 string `json:"k6,omitempty"` K7 string `json:"k7,omitempty"` K8 string `json:"k8,omitempty"` K9 string `json:"k9,omitempty"` K10 string `json:"k10,omitempty"` K11 string `json:"k11,omitempty"` K12 string `json:"k12,omitempty"` K13 string `json:"k13,omitempty"` K14 string `json:"k14,omitempty"` K15 string `json:"k15,omitempty"` K16 string `json:"k16,omitempty"` K17 string `json:"k17,omitempty"` K18 string `json:"k18,omitempty"` K19 string `json:"k19,omitempty"` K20 string `json:"k20,omitempty"` Key string `json:"key"` // {{k1}}#{{k2}}#{{k3}} LogType LogType `json:"logtype"` Time string `json:"time"` // yyyyMMddHHmmssSSS Hostname string `json:"hostname"` Keys []string `json:"-"` Min float64 `json:"min"` // 每次采集区间(METRICS_INTERVAL)中 v1 最小/大值 Max float64 `json:"max"` // 只对 RT 生效 V1 float64 `json:"v1"` // 小数 V2 float64 `json:"v2"` // 只有比率类型的时候,才用到v2 V3 float64 `json:"v3"` // RT 当 [300-400) ms 时 v3 = 1 V4 float64 `json:"v4"` // RT 当 [400-500) ms 时 v4 = 1 V5 float64 `json:"v5"` // RT 当 [500-600) ms 时 v5 = 1 V6 float64 `json:"v6"` // RT 当 [600-700) ms 时 v6 = 1 V7 float64 `json:"v7"` // RT 当 [700-800) ms 时 v7 = 1 V8 float64 `json:"v8"` // RT 当 [800-900) ms 时 v8 = 1 V9 float64 `json:"v9"` // RT 当 [900-∞) ms 时 v9 = 1 N int `json:"n"` // 上次记录完日志后,累积的写次数 }
Line represents a metric rotate line structure in rotate file.
func (*Line) ToLineProtocol ¶
ToLineProtocol print l to a influxdb v1 line protocol format.
type Option ¶
type Option struct { AppName string `env:"APP_NAME"` // 应用名称,默认使用当前进程的PID LogPath string `default:"/tmp/log/metrics" env:"LOG_PATH"` // 日志路径 MetricsInterval time.Duration `default:"1s" env:"METRICS_INTERVAL"` // 每隔多少时间记录一次日志 HBInterval time.Duration `default:"20s" env:"HB_INTERVAL"` // 每隔多少时间记录一次心跳日志 ChanCap int `default:"1000" env:"CHAN_CAP"` // 指标通道容量,当指标大量发送容量堆满时,自动扔弃 MaxBackups int `default:"7" env:"MAX_BACKUPS"` // 最大保留天数 AutoDrop bool `env:"AUTO_DROP"` // 在指标来不及处理时,是否自动扔弃 Debug bool `env:"DEBUG"` // 开启测试模式 }
Option defines the option for runner.
type OptionFn ¶
type OptionFn func(o *Option)
OptionFn defines the function for options setting.
func MaxBackups ¶
MaxBackups sets max backups of metrics logMetrics files.
func MetricsInterval ¶
MetricsInterval sets the interval to write logMetrics line.
type RTRecorder ¶
RTRecorder is a Round-Time recorder 平均响应时间.
func (RTRecorder) RecordSince ¶
func (r RTRecorder) RecordSince(start time.Time)
RecordSince records a round-time since start.
type Runner ¶
type Runner struct { MetricsLogfile io.Writer HBLogfile io.Writer C chan *Line AppName string MetricsInterval time.Duration HBInterval time.Duration // contains filtered or unexported fields }
Runner is a runner for metric rotate writing.
func (*Runner) FailRate ¶
func (r *Runner) FailRate(keys ...string) FailRateRecorder
FailRate creates a FailRateRecorder.
func (*Runner) HitRate ¶
func (r *Runner) HitRate(keys ...string) HitRateRecorder
HitRate makes a HitRateRecorder.
func (*Runner) MakeRecorder ¶
MakeRecorder creates a Recorder.
func (*Runner) SuccessRate ¶
func (r *Runner) SuccessRate(keys ...string) SuccessRateRecorder
SuccessRate makes a SuccessRateRecorder.
type SuccessRateRecorder ¶
type SuccessRateRecorder struct{ Recorder }
SuccessRateRecorder record success rate.
func SuccessRate ¶
func SuccessRate(keys ...string) SuccessRateRecorder
SuccessRate makes a SuccessRateRecorder.
func (SuccessRateRecorder) IncrSuccess ¶
func (c SuccessRateRecorder) IncrSuccess()
IncrSuccess increment success count.
func (SuccessRateRecorder) IncrTotal ¶
func (c SuccessRateRecorder) IncrTotal()
IncrTotal increment total.
func (SuccessRateRecorder) Ks ¶
func (c SuccessRateRecorder) Ks(k *ks.Ks) SuccessRateRecorder
Ks add extra keys.