metrics

package
v1.3.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const MaxQueueSize = 256 // TODO 可以配置,可以在单个任务里配置

Variables

View Source
var SharedManager = NewManager()

Functions

func CheckSQLiteDB added in v1.3.5

func CheckSQLiteDB(itemId int64) bool

func DecodeSumKey added in v1.3.5

func DecodeSumKey(sumKey string) (serverId int64, timeString string, version int32, err error)

func DecodeSumValue added in v1.3.5

func DecodeSumValue(data []byte) (count uint64, total uint64)

func DecodeValueKey added in v1.3.5

func DecodeValueKey(valueKey string) (serverId int64, timeString string, version int32, value int64, hash string, err error)

func EncodeSumValue added in v1.3.5

func EncodeSumValue(count uint64, total uint64) []byte

func UniqueKey added in v1.3.5

func UniqueKey(serverId int64, keys []string, time string, version int32, itemId int64) string

Types

type BaseTask added in v1.3.5

type BaseTask struct {
	// contains filtered or unexported fields
}

func (*BaseTask) Add added in v1.3.5

func (this *BaseTask) Add(obj MetricInterface)

Add 添加数据

func (*BaseTask) Item added in v1.3.5

func (this *BaseTask) Item() *serverconfigs.MetricItemConfig

func (*BaseTask) SetItem added in v1.3.5

func (this *BaseTask) SetItem(itemConfig *serverconfigs.MetricItemConfig)

type ItemEncoder added in v1.3.5

type ItemEncoder[T interface{ *Stat }] struct {
}

func (*ItemEncoder[T]) Decode added in v1.3.5

func (this *ItemEncoder[T]) Decode(valueBytes []byte) (value T, err error)

func (*ItemEncoder[T]) Encode added in v1.3.5

func (this *ItemEncoder[T]) Encode(value T) ([]byte, error)

func (*ItemEncoder[T]) EncodeField added in v1.3.5

func (this *ItemEncoder[T]) EncodeField(value T, fieldName string) ([]byte, error)

type KVTask added in v1.3.5

type KVTask struct {
	BaseTask
	// contains filtered or unexported fields
}

KVTask KV存储实现的任务管理

func NewKVTask added in v1.3.5

func NewKVTask(itemConfig *serverconfigs.MetricItemConfig) *KVTask

func (*KVTask) CleanExpired added in v1.3.5

func (this *KVTask) CleanExpired() error

func (*KVTask) Delete added in v1.3.5

func (this *KVTask) Delete() error

func (*KVTask) Flush added in v1.3.5

func (this *KVTask) Flush() error

func (*KVTask) Init added in v1.3.5

func (this *KVTask) Init() error

func (*KVTask) InsertStat added in v1.3.5

func (this *KVTask) InsertStat(stat *Stat) error

func (*KVTask) Start added in v1.3.5

func (this *KVTask) Start() error

func (*KVTask) Stop added in v1.3.5

func (this *KVTask) Stop() error

func (*KVTask) TestInspect added in v1.3.5

func (this *KVTask) TestInspect(t *testing.T)

func (*KVTask) Truncate added in v1.3.5

func (this *KVTask) Truncate() error

func (*KVTask) Upload added in v1.3.5

func (this *KVTask) Upload(pauseDuration time.Duration) error

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager() *Manager

func (*Manager) Add

func (this *Manager) Add(obj MetricInterface)

Add 添加数据

func (*Manager) HasHTTPMetrics

func (this *Manager) HasHTTPMetrics() bool

func (*Manager) HasTCPMetrics

func (this *Manager) HasTCPMetrics() bool

func (*Manager) HasUDPMetrics

func (this *Manager) HasUDPMetrics() bool

func (*Manager) Quit added in v0.5.2

func (this *Manager) Quit()

Quit 退出管理器

func (*Manager) TaskMap added in v1.3.5

func (this *Manager) TaskMap() map[int64]Task

func (*Manager) Update

func (this *Manager) Update(items []*serverconfigs.MetricItemConfig)

type MetricInterface

type MetricInterface interface {
	// MetricKey 指标对象
	MetricKey(key string) string

	// MetricValue 指标值
	MetricValue(value string) (result int64, ok bool)

	// MetricServerId 服务ID
	MetricServerId() int64

	// MetricCategory 指标分类
	MetricCategory() string
}

type SQLiteTask added in v1.3.5

type SQLiteTask struct {
	BaseTask
	// contains filtered or unexported fields
}

SQLiteTask 单个指标任务 数据库存储:

data/
   metric.$ID.db
      stats
         id, keys, value, time, serverId, hash
原理:
   添加或者有变更时 isUploaded = false
   上传时检查 isUploaded 状态
   只上传每个服务中排序最前面的 N 个数据

func NewSQLiteTask added in v1.3.5

func NewSQLiteTask(item *serverconfigs.MetricItemConfig) *SQLiteTask

NewSQLiteTask 获取新任务

func (*SQLiteTask) CleanExpired added in v1.3.5

func (this *SQLiteTask) CleanExpired() error

CleanExpired 清理数据

func (*SQLiteTask) Delete added in v1.3.5

func (this *SQLiteTask) Delete() error

func (*SQLiteTask) Init added in v1.3.5

func (this *SQLiteTask) Init() error

Init 初始化

func (*SQLiteTask) InsertStat added in v1.3.5

func (this *SQLiteTask) InsertStat(stat *Stat) error

InsertStat 写入数据

func (*SQLiteTask) Start added in v1.3.5

func (this *SQLiteTask) Start() error

Start 启动任务

func (*SQLiteTask) Stop added in v1.3.5

func (this *SQLiteTask) Stop() error

Stop 停止任务

func (*SQLiteTask) Upload added in v1.3.5

func (this *SQLiteTask) Upload(pauseDuration time.Duration) error

Upload 上传数据

type Stat

type Stat struct {
	ServerId int64    `json:"serverId"`
	Keys     []string `json:"keys"`
	Hash     string   `json:"hash"`
	Value    int64    `json:"value"`
	Time     string   `json:"time"`
}

func (*Stat) EncodeSumKey added in v1.3.5

func (this *Stat) EncodeSumKey(version int32) string

func (*Stat) EncodeValueKey added in v1.3.5

func (this *Stat) EncodeValueKey(version int32) string

func (*Stat) FullKey added in v1.3.5

func (this *Stat) FullKey(version int32, itemId int64) string

func (*Stat) UniqueKey added in v1.3.5

func (this *Stat) UniqueKey(version int32, itemId int64) string

type Task

type Task interface {
	Init() error
	Item() *serverconfigs.MetricItemConfig
	SetItem(item *serverconfigs.MetricItemConfig)
	Add(obj MetricInterface)
	InsertStat(stat *Stat) error
	Upload(pauseDuration time.Duration) error
	Start() error
	Stop() error
	Delete() error
	CleanExpired() error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL