compute some innodb metrics

This commit is contained in:
Ulric Qin 2022-04-26 14:02:26 +08:00
parent f5bcc36e9e
commit d10f67c1e3
2 changed files with 37 additions and 16 deletions

View File

@ -0,0 +1,36 @@
package mysql
import (
"database/sql"
"flashcat.cloud/categraf/inputs"
"flashcat.cloud/categraf/pkg/tagx"
"github.com/toolkits/pkg/container/list"
)
func (m *MySQL) gatherEngineInnodbStatusCompute(slist *list.SafeList, ins *Instance, db *sql.DB, globalTags map[string]string, cache map[string]float64) {
if !ins.ExtraInnodbMetrics {
return
}
tags := tagx.Copy(globalTags)
pageUsed := cache["innodb_buffer_pool_pages_total"] - cache["innodb_buffer_pool_pages_free"]
byteUsed := pageUsed * cache["innodb_page_size"]
byteData := cache["innodb_buffer_pool_pages_data"] * cache["innodb_page_size"]
byteDirty := cache["innodb_buffer_pool_pages_dirty"] * cache["innodb_page_size"]
byteFree := cache["innodb_buffer_pool_pages_free"] * cache["innodb_page_size"]
byteTotal := cache["innodb_buffer_pool_pages_total"] * cache["innodb_page_size"]
pageUtil := float64(0)
if cache["innodb_buffer_pool_pages_total"] != 0 {
pageUtil = pageUsed / cache["innodb_buffer_pool_pages_total"]
}
slist.PushFront(inputs.NewSample("global_status_buffer_pool_pages", pageUsed, tags, map[string]string{"state": "used"}))
slist.PushFront(inputs.NewSample("global_status_buffer_pool_pages_bytes", byteUsed, tags, map[string]string{"state": "used"}))
slist.PushFront(inputs.NewSample("global_status_buffer_pool_pages_bytes", byteData, tags, map[string]string{"state": "data"}))
slist.PushFront(inputs.NewSample("global_status_buffer_pool_pages_bytes", byteFree, tags, map[string]string{"state": "free"}))
slist.PushFront(inputs.NewSample("global_status_buffer_pool_pages_bytes", byteTotal, tags, map[string]string{"state": "total"}))
slist.PushFront(inputs.NewSample("global_status_buffer_pool_dirty_pages_bytes", byteDirty, tags))
slist.PushFront(inputs.NewSample("global_status_buffer_pool_pages_utilization", pageUtil, tags))
}

View File

@ -231,20 +231,5 @@ func (m *MySQL) gatherOnce(slist *list.SafeList, ins *Instance) {
m.gatherGlobalStatus(slist, ins, db, tags, cache)
m.gatherGlobalVariables(slist, ins, db, tags, cache)
m.gatherEngineInnodbStatus(slist, ins, db, tags, cache)
innodbKeys := []string{
"innodb_page_size",
"innodb_buffer_pool_pages_data",
"innodb_buffer_pool_pages_dirty",
"innodb_buffer_pool_pages_total",
"innodb_buffer_pool_pages_free",
}
for _, key := range innodbKeys {
if val, has := cache[key]; has {
log.Println("---key:", key, "value:", val)
} else {
log.Println("---key not found:", key)
}
}
m.gatherEngineInnodbStatusCompute(slist, ins, db, tags, cache)
}