-
Notifications
You must be signed in to change notification settings - Fork 41
/
scheduler.go
53 lines (49 loc) · 1.16 KB
/
scheduler.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
package main
import (
"github.com/rach/pome/Godeps/_workspace/src/github.com/jmoiron/sqlx"
"github.com/robfig/cron"
"strings"
)
func scheduleMetric(c *cron.Cron, schedule string, fct func()) {
c.AddFunc(schedule, fct)
if strings.HasPrefix(schedule, "@every") {
fct()
}
}
func initScheduler(
db *sqlx.DB,
metrics *MetricList,
scheduleTableBloat string,
scheduleDbSize string,
scheduleIndexBloat string,
scheduleNumConn string,
scheduleTPS string) {
c := cron.New()
scheduleMetric(c, scheduleIndexBloat,
func() {
indexBloatUpdate(db, metrics, GetIndexBloatResult, 120)
},
)
scheduleMetric(c, scheduleTableBloat,
func() {
tableBloatUpdate(db, metrics, GetTableBloatResult, 120)
},
)
scheduleMetric(c, scheduleDbSize,
func() {
databaseSizeUpdate(db, metrics, GetDatabeSizeResult, 120)
},
)
scheduleMetric(c, scheduleNumConn,
func() {
numberOfConnectionUpdate(db, metrics, GetNumberOfConnectionResult, 120)
},
)
scheduleMetric(c, scheduleTPS,
func() {
// GetTransactionNumberResult only return the current number of transaction currently
transactionPerSecUpdate(db, metrics, GetTransactionNumberResult, 120)
},
)
c.Start()
}