Skip to content

Commit

Permalink
add debug and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sylzd committed Oct 17, 2018
1 parent 53fb6bf commit 7336b7e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
13 changes: 11 additions & 2 deletions README.md
Expand Up @@ -49,7 +49,16 @@ port=3306 # 数据库端口

采集的metric信息,请参考./metrics.txt。该文件仅供参考,实际采集信息会根据MySQL版本、配置的不同而变化。

## Contributors
### 同步延迟

关于同步延迟检测的metric有两个: `Seconds_Behind_Master``Heartbeats_Behind_Master`

`Seconds_Behind_Master`是MySQL`SHOW SLAVE STATUS`输出的状态变量。由于低版本的MySQL还不支持HEARTBEAT_EVENT,在低版本的MySQL中该状态可能会由于IO线程假死导致测量不准确,因此mymon增加了`Heartbeats_Behind_Master`。它依赖于`pt-heartbeat`,统计基于`pt-heartbeat`生成的mysql.heartbeat表中的ts字段值与从库当前时间差。如果未配置`pt-heartbeat`,则该项上报-1值。

关于pt-heartbeat的配置使用,链接如下:
https://www.percona.com/doc/percona-toolkit/LATEST/pt-heartbeat.html



* libin 微信:libin_cc 邮件:libin_dba@xiaomi.com [OLD]
* liuzidong [![Chat on gitter](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/sylzd) 邮件:liuzidong@xiaomi.com [CURRENT]
* liuzidong [![Chat on gitter](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/sylzd) 邮件:liuzidong@xiaomi.com [CURRENT]
1 change: 1 addition & 0 deletions metric.go
Expand Up @@ -341,6 +341,7 @@ func MySQLAlive(conf *common.Config, ok bool) {
func GetIsReadOnly(db mysql.Conn) (int, error) {
row, _, err := db.QueryFirst("select @@read_only")
if err != nil {
Log.Debug("get read_only error: %+v", err)
return -1, err
}
return row.Int(0), nil
Expand Down
5 changes: 5 additions & 0 deletions senddata.go
Expand Up @@ -33,6 +33,7 @@ func SendData(conf *common.Config, data []*MetaData) ([]byte, error) {
data = filterIgnoreData(conf, data)
js, err := json.Marshal(data)
if err != nil {
Log.Debug("parse json data error: %+v", err)
return nil, err
}
Log.Info("Send to %s, size: %d", conf.Base.FalconClient, len(data))
Expand All @@ -42,6 +43,7 @@ func SendData(conf *common.Config, data []*MetaData) ([]byte, error) {

res, err := http.Post(conf.Base.FalconClient, "Content-Type: application/json", bytes.NewBuffer(js))
if err != nil {
Log.Debug("send data to falcon-agent error: %+v", err)
return nil, err
}

Expand Down Expand Up @@ -77,6 +79,7 @@ func filterIgnoreData(conf *common.Config, data []*MetaData) []*MetaData {
f, err := os.OpenFile(ignoreFile, os.O_RDONLY, 0644)
// ignorefile does not exists
if err != nil {
Log.Debug("ignorefile %s does not exist", ignoreFile)
return data
}
inputReader := bufio.NewReader(f)
Expand Down Expand Up @@ -137,11 +140,13 @@ func Snapshot(conf *common.Config, note string, fileNameDay string, fileNameOldD
}
f, err := os.OpenFile(fileNameDay, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
Log.Debug("open snapshot file %s error: %+v", fileNameDay, err)
return err
}
defer f.Close()
_, err = f.WriteString(note)
if err != nil {
Log.Debug("write info to snapshot file error: %+v", err)
return err
}
e := os.Remove(fileNameOldDay)
Expand Down
14 changes: 13 additions & 1 deletion show.go
Expand Up @@ -42,6 +42,7 @@ func ShowProcesslist(conf *common.Config, db mysql.Conn) error {
var note string
rows, _, err := db.Query("SHOW FULL PROCESSLIST")
if err != nil {
Log.Debug("get processlist error: %+v", err)
return err
}
for _, row := range rows {
Expand All @@ -59,12 +60,14 @@ func ShowProcesslist(conf *common.Config, db mysql.Conn) error {
func ShowInnodbStatus(conf *common.Config, db mysql.Conn) ([]*MetaData, error) {
status, _, err := db.QueryFirst("SHOW /*!50000 ENGINE*/ INNODB STATUS")
if err != nil {
Log.Debug("show innodb status error: %+v", err)
return nil, err
}
allStatus := status.Str(2)
fileNameDay, fileNameOldDay := common.GetFileNameDayAndOldDay(conf, "innodb")
err = Snapshot(conf, allStatus, fileNameDay, fileNameOldDay)
if err != nil {
Log.Debug("write snapshot error: %+v", err)
return nil, err
}

Expand All @@ -80,6 +83,7 @@ func ShowBinaryLogs(conf *common.Config, db mysql.Conn) ([]*MetaData, error) {

rows, res, err := db.Query("SHOW BINARY LOGS")
if err != nil {
Log.Debug("show binary logs error: %+v", err)
return []*MetaData{binlogFileCounts, binlogFileSize}, err
}

Expand Down Expand Up @@ -115,14 +119,17 @@ func ShowSlaveStatus(conf *common.Config, db mysql.Conn) ([]*MetaData, error) {
// Master_is_readonly VS master_is_read_only for version compatible, ugly
masterReadOnly, err := ShowOtherMetric(conf, db, "Master_is_readonly")
if err != nil {
Log.Debug("get Master_is_readonly metric error: %+v", err)
return nil, err
}
masterReadOnly2, err := ShowOtherMetric(conf, db, "master_is_read_only")
if err != nil {
Log.Debug("get master_is_readonly metric error: %+v", err)
return nil, err
}
innodbStatsOnMetadata, err := ShowOtherMetric(conf, db, "innodb_stats_on_metadata")
if err != nil {
Log.Debug("get innodb_stats_on_metadata metric error: %+v", err)
return nil, err
}
return []*MetaData{isSlaveMetric, masterReadOnly, masterReadOnly2, innodbStatsOnMetadata}, nil
Expand All @@ -131,10 +138,12 @@ func ShowSlaveStatus(conf *common.Config, db mysql.Conn) ([]*MetaData, error) {
// be slave
ioDelay, err := ShowOtherMetric(conf, db, "io_thread_delay")
if err != nil {
Log.Debug("get io_thread_delay metric error: %+v", err)
return nil, err
}
slaveReadOnly, err := ShowOtherMetric(conf, db, "slave_is_read_only")
if err != nil {
Log.Debug("get slave_is_read_only metric error: %+v", err)
return nil, err
}
heartbeat, err := ShowOtherMetric(conf, db, "Heartbeats_Behind_Master")
Expand Down Expand Up @@ -178,7 +187,7 @@ func ShowOtherMetric(conf *common.Config, db mysql.Conn, metric string) (*MetaDa
case "master_is_read_only", "slave_is_read_only", "Master_is_readonly":
newMetaData.SetValue(IsReadOnly)
case "innodb_stats_on_metadata":
row, _, err = db.QueryFirst("SELECT /*!50504 @@GLOBAL.innodb_stats_on_metadata */;")
row, _, err = db.QueryFirst("SELECT /*!50504 @@GLOBAL.innodb_stats_on_metadata,*/ -1;")
newMetaData.SetValue(row.Int(0))
case "io_thread_delay":
var res mysql.Result
Expand Down Expand Up @@ -215,6 +224,7 @@ func ShowOtherMetric(conf *common.Config, db mysql.Conn, metric string) (*MetaDa
func parseMySQLStatus(conf *common.Config, db mysql.Conn, sql string) ([]*MetaData, error) {
rows, _, err := db.Query(sql)
if err != nil {
Log.Debug("sql query: %s error: %+v", sql, err)
return nil, err
}

Expand Down Expand Up @@ -247,6 +257,7 @@ func parseInnodbSection(
row, "ACTIVE ")[1],
" sec")[0])
if err != nil {
Log.Debug("parse TRANSACTIONS of innodb info error:%+v", err)
return err
}
if tmpLongTransactionTime > *longTranTime {
Expand Down Expand Up @@ -325,6 +336,7 @@ func parseInnodbStatus(conf *common.Config, rows []string) ([]*MetaData, error)
}
err = parseInnodbSection(conf, row, section, &data, &longTranTime)
if err != nil {
Log.Debug("parse innodb section error: %+v", err)
return nil, err
}
}
Expand Down

0 comments on commit 7336b7e

Please sign in to comment.