forked from flashcatcloud/categraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine_innodb.go
61 lines (52 loc) · 1.78 KB
/
engine_innodb.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package mysql
import (
"database/sql"
"log"
"regexp"
"strconv"
"strings"
"flashcat.cloud/categraf/inputs"
"flashcat.cloud/categraf/pkg/tagx"
"github.com/toolkits/pkg/container/list"
)
func (m *MySQL) gatherEngineInnodbStatus(slist *list.SafeList, ins *Instance, db *sql.DB, globalTags map[string]string, cache map[string]float64) {
rows, err := db.Query(SQL_ENGINE_INNODB_STATUS)
if err != nil {
log.Println("E! failed to query engine innodb status:", err)
return
}
defer rows.Close()
var typeCol, nameCol, statusCol string
// First row should contain the necessary info. If many rows returned then it's unknown case.
if rows.Next() {
if err := rows.Scan(&typeCol, &nameCol, &statusCol); err != nil {
log.Println("E! failed to scan result, sql:", SQL_ENGINE_INNODB_STATUS, "error:", err)
return
}
}
tags := tagx.Copy(globalTags)
// 0 queries inside InnoDB, 0 queries in queue
// 0 read views open inside InnoDB
rQueries, _ := regexp.Compile(`(\d+) queries inside InnoDB, (\d+) queries in queue`)
rViews, _ := regexp.Compile(`(\d+) read views open inside InnoDB`)
for _, line := range strings.Split(statusCol, "\n") {
if data := rQueries.FindStringSubmatch(line); data != nil {
value, err := strconv.ParseFloat(data[1], 64)
if err != nil {
continue
}
slist.PushFront(inputs.NewSample("engine_innodb_queries_inside_innodb", value, tags))
value, err = strconv.ParseFloat(data[2], 64)
if err != nil {
continue
}
slist.PushFront(inputs.NewSample("engine_innodb_queries_in_queue", value, tags))
} else if data := rViews.FindStringSubmatch(line); data != nil {
value, err := strconv.ParseFloat(data[1], 64)
if err != nil {
continue
}
slist.PushFront(inputs.NewSample("engine_innodb_read_views_open_inside_innodb", value, tags))
}
}
}