monitor

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WORK_STATUS_ING  = 1
	WORK_STATUS_STOP = 2
)

hotkey任务状态值 * 通过原子操作进行状态的更新。

View Source
const INIT_INDEX = -1
View Source
const Namespace = "redisproxy"

Variables

View Source
var BasicLabels = []string{"host"}
View Source
var BasicLabelsMap = map[string]string{}

Functions

func CurrentNetworkStatInputByte

func CurrentNetworkStatInputByte() float64

func CurrentNetworkStatOutputByte

func CurrentNetworkStatOutputByte() float64

func GetNetstat

func GetNetstat() (tcp map[string]int, err error)

func NewDesc

func NewDesc(metricName string, docString string, labels []string) *prometheus.Desc

func ReadNumberFromFile

func ReadNumberFromFile(name string) (n float64, err error)

func RunPrometheusExporter

func RunPrometheusExporter(mon *Monitor, c *ExporterConf) error

Types

type BigKeyConfS

type BigKeyConfS struct {
	Enable           bool
	KeyMaxBytes      int
	ValueMaxBytes    int
	LruSize          int
	EnableCache      bool
	MaxCacheLifeTime int
	sync.RWMutex
}

type BigKeyDataS

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

type BigKeyExporter

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

func NewBigKeyExporter

func NewBigKeyExporter(mon *Monitor, c *ExporterConf) *BigKeyExporter

func (*BigKeyExporter) Collect

func (b *BigKeyExporter) Collect(ch chan<- prometheus.Metric)

func (*BigKeyExporter) Describe

func (b *BigKeyExporter) Describe(ch chan<- *prometheus.Desc)

type BigKeyExporterConf

type BigKeyExporterConf struct {
	RecordLimit int      `mapstructure:"record_limit"`
	Include     []string `mapstructure:"include_metrics"`
}

type BigKeyMonitorDataS

type BigKeyMonitorDataS struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

type BigKeyPair

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

type BigKeyStatistics

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

func (*BigKeyStatistics) Filter

func (b *BigKeyStatistics) Filter()

func (*BigKeyStatistics) GetBigKeyCount

func (b *BigKeyStatistics) GetBigKeyCount() int

func (*BigKeyStatistics) GetBigKeyPairArray

func (b *BigKeyStatistics) GetBigKeyPairArray() []BigKeyPair

func (*BigKeyStatistics) GetBigKeyValueSizeSum

func (b *BigKeyStatistics) GetBigKeyValueSizeSum() int

func (*BigKeyStatistics) Init

func (b *BigKeyStatistics) Init(data []BigKeyDataS, threshold int)

func (*BigKeyStatistics) Len

func (b *BigKeyStatistics) Len() int

func (*BigKeyStatistics) Less

func (b *BigKeyStatistics) Less(i, j int) bool

func (*BigKeyStatistics) Swap

func (b *BigKeyStatistics) Swap(i, j int)

type ExporterConf

type ExporterConf struct {
	Enable              bool                  `mapstructure:"enable"`
	Host                string                `mapstructure:"host"`
	Address             string                `mapstructure:"address"`
	HotKeyExporterConf  HotKeyExporterConf    `mapstructure:"hotkey_exporter"`
	BigKeyExporterConf  BigKeyExporterConf    `mapstructure:"bigkey_exporter"`
	SlowQueryConf       SlowQueryExporterConf `mapstructure:"slowquery_exporter"`
	RunTimeExporterConf RunTimeExporterConf   `mapstructure:"runtime_exporter"`
}

func (*ExporterConf) SetDefaultHostname

func (e *ExporterConf) SetDefaultHostname()

type Fields

type Fields struct {
	NumCPU       int64 `json:"cpu.count"`
	NumGoroutine int64 `json:"cpu.goroutines"`

	Alloc      int64 `json:"mem.alloc"`
	TotalAlloc int64 `json:"mem.total"`
	Sys        int64 `json:"mem.sys"`
	Lookups    int64 `json:"mem.lookups"`
	Mallocs    int64 `json:"mem.malloc"`
	Frees      int64 `json:"mem.frees"`

	HeapAlloc    int64 `json:"mem.heap.alloc"`
	HeapSys      int64 `json:"mem.heap.sys"`
	HeapIdle     int64 `json:"mem.heap.idle"`
	HeapInuse    int64 `json:"mem.heap.inuse"`
	HeapReleased int64 `json:"mem.heap.released"`
	HeapObjects  int64 `json:"mem.heap.objects"`

	StackInuse  int64 `json:"mem.stack.inuse"`
	StackSys    int64 `json:"mem.stack.sys"`
	MSpanInuse  int64 `json:"mem.stack.mspan_inuse"`
	MSpanSys    int64 `json:"mem.stack.mspan_sys"`
	MCacheInuse int64 `json:"mem.stack.mcache_inuse"`
	MCacheSys   int64 `json:"mem.stack.mcache_sys"`

	OtherSys int64 `json:"mem.othersys"`

	GCSys         int64   `json:"mem.gc.sys"`
	NextGC        int64   `json:"mem.gc.next"`
	LastGC        int64   `json:"mem.gc.last"`
	PauseTotalNs  int64   `json:"mem.gc.pause_total"`
	PauseNs       int64   `json:"mem.gc.pause"`
	NumGC         int64   `json:"mem.gc.count"`
	GCCPUFraction float64 `json:"mem.gc.cpu_fraction"`
}

func (*Fields) Values

func (f *Fields) Values() map[string]interface{}

type FieldsFunc

type FieldsFunc func(Fields)

type HotKeyConfS

type HotKeyConfS struct {
	Enable                  bool
	MonitorJobInterval      int
	MonitorJobLifeTime      int
	SecondHotThreshold      int
	SecondIncreaseThreshold int
	LruSize                 int

	EnableCache      bool
	MaxCacheLifeTime int
	sync.RWMutex
}

type HotKeyCountDataS

type HotKeyCountDataS map[string]uint64

type HotKeyDataS

type HotKeyDataS struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

type HotKeyExporter

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

func NewHotKeyExporter

func NewHotKeyExporter(mon *Monitor, c *ExporterConf) *HotKeyExporter

func (*HotKeyExporter) Collect

func (n *HotKeyExporter) Collect(ch chan<- prometheus.Metric)

func (*HotKeyExporter) Describe

func (n *HotKeyExporter) Describe(ch chan<- *prometheus.Desc)

type HotKeyExporterConf

type HotKeyExporterConf struct {
	RecordLimit int      `mapstructure:"record_limit"`
	Include     []string `mapstructure:"include_metrics"`
}

type HotKeyMonitorDataS

type HotKeyMonitorDataS struct {
	HotKeyData HotKeyCountDataS
	TimeRange  *TimePair

	sync.RWMutex
}

func (*HotKeyMonitorDataS) ReSetData

func (hkmd *HotKeyMonitorDataS) ReSetData()

type HotKeyPair

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

type HotKeyStatistics

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

func (*HotKeyStatistics) Filter

func (h *HotKeyStatistics) Filter()

func (*HotKeyStatistics) GetHotKeyPairArray

func (h *HotKeyStatistics) GetHotKeyPairArray() []HotKeyPair

func (*HotKeyStatistics) GetHotKeyTotal

func (h *HotKeyStatistics) GetHotKeyTotal() int

func (*HotKeyStatistics) Init

func (h *HotKeyStatistics) Init(data *HotKeyMonitorDataS, threshold int)

func (*HotKeyStatistics) Len

func (h *HotKeyStatistics) Len() int

func (*HotKeyStatistics) Less

func (h *HotKeyStatistics) Less(i, j int) bool

func (*HotKeyStatistics) Swap

func (h *HotKeyStatistics) Swap(i, j int)

type KeyMonitor

type KeyMonitor struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

type Monitor

type Monitor struct {
	Cache                *cache.Cache
	KeyMonitor           *KeyMonitor
	HotKeyConf           *HotKeyConfS
	HotKeyMonitorData    *HotKeyMonitorDataS
	BigKeyConf           *BigKeyConfS
	BigKeyMonitorData    *BigKeyMonitorDataS
	SlowQueryConf        *SlowQueryConfS
	SlowQueryMonitorData *SlowQueryMonitorDataS
	ConnectionGauge      prometheus.Gauge
	sync.RWMutex
}

func GetNewMonitor

func GetNewMonitor(hotKeyConf *HotKeyConfS, bigKeyConf *BigKeyConfS, slowQueryConf *SlowQueryConfS) (m *Monitor, err error)

func (*Monitor) AddBigKeyCacheItem

func (m *Monitor) AddBigKeyCacheItem(cache *cache.Cache, key, value []byte, expireMilliSeconds int) bool

func (*Monitor) AddHotKeyCacheItem

func (m *Monitor) AddHotKeyCacheItem(cache *cache.Cache, key string, value []byte, expireMilliSeconds int) bool

*AddHotKeyCacheItem(cache缓存对象,cache的key,cache的数据体,超时时间-毫秒) *这个函数主要支撑hotkey数据的缓存写入工作,当检测出hotkey时,判断是否开启了cache功能,如果开启了则进行cache的写入工作。

func (*Monitor) BeginMonitorHotKey

func (m *Monitor) BeginMonitorHotKey()

*BeginMonitorHotKey() *这个函数主要启动HotKey的监控工作,监控工作主要包括以下几部分: * 1.原子切换hotkey任务执行状态,WORK_STATUS_STOP状态代表任务监控停止,WORK_STATUS_ING状态代表正在进行hotkey监控 * 2.hotkey任务监控等待:等待的目的主要是为了让requesthandle可以在这段时间内统计hotkey lRU数据 * 3.对于监控获得的数据进行hotkey LRU数据进行汇总工作,并把hotkey存储到hotkeys汇总数据内存中。 * 4.把hotkeys中的数据并发安全的存储到HotKeyMonitorData数据中,这个数据可以供外部调用并发安全的访问。

func (*Monitor) GetBigKeyData

func (m *Monitor) GetBigKeyData() []BigKeyDataS

func (*Monitor) GetSlowQueryData

func (m *Monitor) GetSlowQueryData() (data []*SlowQueryDataS, count int)

func (*Monitor) IsShouldPutHotKey

func (m *Monitor) IsShouldPutHotKey() bool

*IsShouldPutHotKey() *这个函数主要用来判断当前时机是不是应该可以进行hotkey的统计操作 *通过这个函数的前置判断,避免不必要的函数参数传递而造成的性能损耗

func (*Monitor) IsSlowQuery

func (m *Monitor) IsSlowQuery(args []interface{}, startTime time.Time, endTime time.Time)

func (*Monitor) PutBigKey

func (m *Monitor) PutBigKey(key string, valueSize int) bool

func (*Monitor) PutHotKey

func (m *Monitor) PutHotKey(key string, value []byte)

*PutHotKey(hotkey的key数据,hotkey的value数据) *在调用IsShouldPutHotKey函数发现处于hotkey统计周期内时,进行hotkey的写入工作 *这个函数主要完成LRU内存的写入,LRU内存中长久存活的对象就是热点对象,不够热的对象都将被LRU算法置换出。

type NetStatCallback

type NetStatCallback func(stat *NetworkStat, err error)

type NetworkExporter

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

func NewNetExporter

func NewNetExporter(c *ExporterConf) *NetworkExporter

func (*NetworkExporter) Collect

func (s *NetworkExporter) Collect(ch chan<- prometheus.Metric)

func (*NetworkExporter) Describe

func (s *NetworkExporter) Describe(ch chan<- *prometheus.Desc)

type NetworkStat

type NetworkStat struct {
	RxBytes uint64
	TxBytes uint64
}

type RunTimeExporterConf

type RunTimeExporterConf struct {
	Enable    bool `mapstructure:"enable"`
	EnableCPU bool `mapstructure:"enable_cpu"`
	EnableMem bool `mapstructure:"enable_mem"`
	EnableGC  bool `mapstructure:"enable_gc"`
}

type RuntimeExporter

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

func NewRuntimeExport

func NewRuntimeExport(c *ExporterConf) *RuntimeExporter

func (*RuntimeExporter) Collect

func (r *RuntimeExporter) Collect(ch chan<- prometheus.Metric)

func (*RuntimeExporter) Describe

func (r *RuntimeExporter) Describe(ch chan<- *prometheus.Desc)

type SlowQueryConfS

type SlowQueryConfS struct {
	Enable                 bool
	SlowQueryTimeThreshold int
	MaxListSize            int
	sync.RWMutex
}

type SlowQueryDataS

type SlowQueryDataS struct {
	Resp      []interface{}
	StartTime time.Time
	EndTime   time.Time
}

type SlowQueryExporter

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

func NewSlowQueryExporter

func NewSlowQueryExporter(mon *Monitor, c *ExporterConf) *SlowQueryExporter

func (*SlowQueryExporter) Collect

func (s *SlowQueryExporter) Collect(ch chan<- prometheus.Metric)

func (*SlowQueryExporter) Describe

func (s *SlowQueryExporter) Describe(ch chan<- *prometheus.Desc)

type SlowQueryExporterConf

type SlowQueryExporterConf struct {
	RecordLimit int `mapstructure:"record_limit"`
}

type SlowQueryMonitorDataS

type SlowQueryMonitorDataS struct {
	SlowQueryDataList []*SlowQueryDataS
	Index             int32
	sync.RWMutex
}

type SlowQueryPair

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

type SlowQueryStatistics

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

func (*SlowQueryStatistics) Filter

func (s *SlowQueryStatistics) Filter()

func (*SlowQueryStatistics) GetQueryPairArray

func (s *SlowQueryStatistics) GetQueryPairArray() []SlowQueryPair

func (*SlowQueryStatistics) Init

func (s *SlowQueryStatistics) Init(data []*SlowQueryDataS, threshold int)

func (*SlowQueryStatistics) Len

func (s *SlowQueryStatistics) Len() int

func (*SlowQueryStatistics) Less

func (s *SlowQueryStatistics) Less(i, j int) bool

func (*SlowQueryStatistics) Swap

func (s *SlowQueryStatistics) Swap(i, j int)

type TimePair

type TimePair struct {
	Start time.Time
	End   time.Time
}

Jump to

Keyboard shortcuts

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