2015-05-18 18:54:11 +00:00
|
|
|
package mysql
|
|
|
|
|
|
|
|
import (
|
2015-07-07 01:18:31 +00:00
|
|
|
"fmt"
|
2015-05-18 18:54:11 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2015-05-22 23:45:14 +00:00
|
|
|
"github.com/influxdb/telegraf/testutil"
|
2015-05-18 18:54:11 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMysqlGeneratesMetrics(t *testing.T) {
|
2015-08-04 20:52:44 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
}
|
|
|
|
|
2015-05-18 18:54:11 +00:00
|
|
|
m := &Mysql{
|
2015-07-07 01:18:31 +00:00
|
|
|
Servers: []string{fmt.Sprintf("root@tcp(%s:3306)/", testutil.GetLocalHost())},
|
2015-05-18 18:54:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
|
|
err := m.Gather(&acc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
prefixes := []struct {
|
|
|
|
prefix string
|
|
|
|
count int
|
|
|
|
}{
|
2015-05-18 19:15:15 +00:00
|
|
|
{"commands", 141},
|
|
|
|
{"handler", 18},
|
|
|
|
{"bytes", 2},
|
|
|
|
{"innodb", 51},
|
|
|
|
{"threads", 4},
|
2015-09-02 16:03:05 +00:00
|
|
|
{"aborted", 2},
|
|
|
|
{"created", 3},
|
|
|
|
{"key", 7},
|
|
|
|
{"open", 7},
|
|
|
|
{"opened", 3},
|
|
|
|
{"qcache", 8},
|
|
|
|
{"table", 5},
|
2015-05-18 18:54:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
intMetrics := []string{
|
2015-05-18 19:15:15 +00:00
|
|
|
"queries",
|
|
|
|
"slow_queries",
|
2015-05-18 18:54:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, prefix := range prefixes {
|
|
|
|
var count int
|
|
|
|
|
|
|
|
for _, p := range acc.Points {
|
2015-07-03 12:17:53 +00:00
|
|
|
if strings.HasPrefix(p.Measurement, prefix.prefix) {
|
2015-05-18 18:54:11 +00:00
|
|
|
count++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, prefix.count, count)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, metric := range intMetrics {
|
|
|
|
assert.True(t, acc.HasIntValue(metric))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMysqlDefaultsToLocal(t *testing.T) {
|
2015-08-04 20:52:44 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
}
|
|
|
|
|
2015-07-06 04:46:43 +00:00
|
|
|
m := &Mysql{
|
2015-07-07 01:18:31 +00:00
|
|
|
Servers: []string{fmt.Sprintf("root@tcp(%s:3306)/", testutil.GetLocalHost())},
|
2015-07-06 04:46:43 +00:00
|
|
|
}
|
2015-05-18 18:54:11 +00:00
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
|
|
err := m.Gather(&acc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assert.True(t, len(acc.Points) > 0)
|
|
|
|
}
|