Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

收集表+索引的数据大小 #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions dataSize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"github.com/ziutek/mymysql/mysql"
_ "github.com/ziutek/mymysql/native"
"strconv"
)

func getDataSize(m *MysqlIns, db mysql.Conn) (*MetaData, error) {
sql := "SELECT (SUM(DATA_LENGTH)+SUM(INDEX_LENGTH)) AS data_size FROM INFORMATION_SCHEMA.TABLES"

row, _, err := db.QueryFirst(sql)
if err != nil {
return nil, err
}
sizeStr := row.Str(0)
size, _ := strconv.Atoi(sizeStr)

dataSize := NewMetric("Data_size")
dataSize.SetValue(size)

return dataSize, nil
}
1 change: 1 addition & 0 deletions metrics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,4 @@ Uptime
Uptime_since_flush_status
wait_timeout
warning_count
Data_size
8 changes: 7 additions & 1 deletion mpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Cfg struct {
LogFile string
LogLevel int
FalconClient string
Endpoint string
Endpoint string

User string
Pass string
Expand Down Expand Up @@ -160,6 +160,12 @@ func FetchData(m *MysqlIns) (err error) {
}
data = append(data, slaveState...)

dataSize, err := getDataSize(m, db)
if err != nil {
return
}
data = append(data, dataSize)

msg, err := sendData(data)
if err != nil {
return
Expand Down