// [3027925413 10.1.8.203 0 shijiazhuang vehicle_post // SELECT tag,puid, title, thumb_img, city, license_date, road_haul, price, major_category FROM `shijiazhuang`.`vehicle_post` force index (user_id_index) WHERE `city`=1100 AND (user_id = 356435537 AND post_at >= 1424973620 AND minor_category = 1212 AND deal_type = 0 AND listing_status = 5 AND puid <> 1418989540) LIMIT 0, 300; // 616.00 1646.00 0.00 0.13 true // [{"id":"1","select_type":"SIMPLE","table":"vehicle_post","explain_type":"ref","possible_keys":"user_id_index","key":"user_id_index","key_len":"4","ref":"const","rows":"615","extra":"Using where"}]] func (is *InfluxStore) send(s *SlowSql) { fillSerial(s, is.serial) if err := is.influxdb.WriteSeries([]influxdbc.Series{*is.serial}); err != nil { //just ignore error , continue and to be statsd log.Println("write serial error: ", err) } if s.Table != "" { tmpss := influxdbc.NewSeries( fmt.Sprintf("%s.%s", is.product, s.Table), "id", //id is a unique for same slow sql "host", // host is sql's source executed host // "time", // time is sql's executed timestamp "schema", // schema is database name of current sql "table", // table is sql's table, only first one all sql (include join or subquery sql) "sql", // original sql "rowsread", // rows read by this sql "bytessent", // bytes sent by this sql "rowsaffected", // rows affected by this sql "rowsexamined", // rows examined by this sql "slowtime", // slow time by this sql "useindex", // if this sql use index or scan whole table "explains") // simple sql explain , it's a json array fillSerial(s, tmpss) if err := is.influxdb.WriteSeries([]influxdbc.Series{*tmpss}); err != nil { //just ignore error , continue and to be statsd log.Println("write serial error: ", err) } } }
// type SlowSql struct { // ID uint32 // ProductName string // FromHostname string // Timestamp int64 // Schema string // Table string // PayLoad string // Fields []*message.Field // RowsRead float64 // BytesSent float64 // RowsAffected float64 // RowsExamined float64 // QueryTime float64 // Explains []*SqlExplain // UseIndex bool // } func (is *InfluxStore) InitHelper(g *GlobalConfig) { is.addr = g.InfluxDBConfig.Addrs is.user = g.InfluxDBConfig.Iuser is.pwd = g.InfluxDBConfig.Ipwd is.dbname = g.InfluxDBConfig.Idbname is.product = g.Base.Product is.quit = make(chan bool, 1) is.sqls = make(chan *SlowSql, 100) log.Println("influx config: ", is.addr, is.user, is.pwd, is.dbname) if ok := is.checkValid(); !ok { log.Fatalln("influxStore check valid failed!!!", is) } is.influxdb = influxdbc.NewInfluxDB(is.addr, is.dbname, is.user, is.pwd) // replace influxdb time with sql's executed timestamp is.serial = influxdbc.NewSeries( is.product, "id", //id is a unique for same slow sql "host", // host is sql's source executed host // "time", // time is sql's executed timestamp "schema", // schema is database name of current sql "table", // table is sql's table, only first one all sql (include join or subquery sql) "sql", // original sql "rowsread", // rows read by this sql "bytessent", // bytes sent by this sql "rowsaffected", // rows affected by this sql "rowsexamined", // rows examined by this sql "slowtime", // slow time by this sql "useindex", // if this sql use index or scan whole table "explains") // simple sql explain , it's a json array if g.Base.Product == "" { log.Fatalln("product name must be set and not empty") } is.serial.Name = g.Base.Product is.wg.Wrap(is.LoopProcess) }