code refactor

This commit is contained in:
Ulric Qin 2022-04-27 11:48:57 +08:00
parent 8fc15dc671
commit a3b7470349
4 changed files with 11 additions and 9 deletions

View File

@ -11,7 +11,8 @@ password = "1234"
extra_status_metrics = true
extra_innodb_metrics = false
gather_process_list = true
gather_processlist_processes_by_state = false
gather_processlist_processes_by_user = true
# # timeout
# timeout_seconds = 3

View File

@ -29,9 +29,10 @@ type Instance struct {
Labels map[string]string `toml:"labels"`
IntervalTimes int64 `toml:"interval_times"`
ExtraStatusMetrics bool `toml:"extra_status_metrics"`
ExtraInnodbMetrics bool `toml:"extra_innodb_metrics"`
GatherProcessList bool `toml:"gather_process_list"`
ExtraStatusMetrics bool `toml:"extra_status_metrics"`
ExtraInnodbMetrics bool `toml:"extra_innodb_metrics"`
GatherProcessListProcessByState bool `toml:"gather_processlist_processes_by_state"`
GatherProcessListProcessByUser bool `toml:"gather_processlist_processes_by_user"`
validMetrics map[string]struct{}
dsn string
@ -234,6 +235,6 @@ func (m *MySQL) gatherOnce(slist *list.SafeList, ins *Instance) {
m.gatherEngineInnodbStatus(slist, ins, db, tags, cache)
m.gatherEngineInnodbStatusCompute(slist, ins, db, tags, cache)
m.gatherBinlog(slist, ins, db, tags, cache)
m.gatherProcesslist(slist, ins, db, tags, cache)
m.gatherProcesslistByState(slist, ins, db, tags, cache)
m.gatherProcesslistByUser(slist, ins, db, tags, cache)
}

View File

@ -90,8 +90,8 @@ var (
}
)
func (m *MySQL) gatherProcesslist(slist *list.SafeList, ins *Instance, db *sql.DB, globalTags map[string]string, cache map[string]float64) {
if !ins.GatherProcessList {
func (m *MySQL) gatherProcesslistByState(slist *list.SafeList, ins *Instance, db *sql.DB, globalTags map[string]string, cache map[string]float64) {
if !ins.GatherProcessListProcessByState {
return
}
@ -131,7 +131,7 @@ func (m *MySQL) gatherProcesslist(slist *list.SafeList, ins *Instance, db *sql.D
}
for s, c := range stateCounts {
slist.PushFront(inputs.NewSample("process_list_threads", c, labels, map[string]string{"state": s}))
slist.PushFront(inputs.NewSample("processlist_processes_by_state", c, labels, map[string]string{"state": s}))
}
}

View File

@ -10,7 +10,7 @@ import (
)
func (m *MySQL) gatherProcesslistByUser(slist *list.SafeList, ins *Instance, db *sql.DB, globalTags map[string]string, cache map[string]float64) {
if !ins.GatherProcessList {
if !ins.GatherProcessListProcessByUser {
return
}