forked from open-falcon/mymon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
37 lines (31 loc) · 789 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"github.com/ziutek/mymysql/mysql"
_ "github.com/ziutek/mymysql/native"
)
func GlobalStatus(m *MysqlIns, db mysql.Conn) ([]*MetaData, error) {
return mysqlState(m, db, "SHOW /*!50001 GLOBAL */ STATUS")
}
func GlobalVariables(m *MysqlIns, db mysql.Conn) ([]*MetaData, error) {
return mysqlState(m, db, "SHOW /*!50001 GLOBAL */ VARIABLES")
}
func mysqlState(m *MysqlIns, db mysql.Conn, sql string) ([]*MetaData, error) {
rows, _, err := db.Query(sql)
if err != nil {
return nil, err
}
data := make([]*MetaData, len(rows))
i := 0
for _, row := range rows {
key_ := row.Str(0)
v, err := row.Int64Err(1)
// Ignore non digital value
if err != nil {
continue
}
data[i] = NewMetric(key_)
data[i].SetValue(v)
i++
}
return data[:i], nil
}