yubo 2021-02-25 15:37:35 +08:00 committed by GitHub
parent 9c1c894e29
commit 005dc47868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 2 deletions

1
.gitignore vendored
View File

@ -59,3 +59,4 @@ tmp/
main
Makefile
src/modules/monapi/plugins/snmp/
src/modules/monapi/plugins/oracle/

View File

@ -0,0 +1,20 @@
package mysql
import (
"os"
"testing"
"github.com/didi/nightingale/src/modules/monapi/plugins"
)
func TestCollect(t *testing.T) {
dsn := os.Getenv("MYSQL_DSN")
if dsn == "" {
t.Error("unable to get DATA_SOURCE_NAME from environment")
}
plugins.PluginTest(t, &MysqlRule{
Servers: []string{dsn},
GatherSlaveStatus: true,
})
}

View File

@ -5,9 +5,11 @@ import (
"hash/fnv"
"sort"
"strconv"
"strings"
"time"
"github.com/influxdata/telegraf"
"github.com/toolkits/pkg/logger"
)
type metric struct {
@ -53,9 +55,10 @@ func NewMetric(
if len(fields) > 0 {
m.fields = make([]*telegraf.Field, 0, len(fields))
for k, v := range fields {
v := convertField(v)
for k, value := range fields {
v := convertField(value)
if v == nil {
logger.Debugf("unable to convert field to float64 %s_%s %v value: %v", name, k, tags, value)
continue
}
m.AddField(k, v)
@ -383,6 +386,13 @@ func convertField(v interface{}) interface{} {
}
func atof(s string) interface{} {
switch strings.ToLower(s) {
case "yes", "true", "on":
return float64(1)
case "no", "false", "off", "none":
return float64(0)
}
if f, err := strconv.ParseFloat(s, 64); err != nil {
return nil
} else {