added connections measurement with user tag

This commit is contained in:
Tyler Nisonoff 2015-10-17 23:56:59 -07:00
parent 73f1ed4f25
commit a716d220b5
2 changed files with 29 additions and 9 deletions

View File

@ -129,6 +129,15 @@ func (m *Mysql) gatherServer(serv string, acc plugins.Accumulator) error {
return err
}
// Parse out user/password from server address tag if given
var servtag string
if strings.Contains(serv, "@") {
servtag = strings.Split(serv, "@")[1]
} else if serv == "" {
servtag = "localhost"
} else {
servtag = serv
}
for rows.Next() {
var name string
var val interface{}
@ -140,15 +149,6 @@ func (m *Mysql) gatherServer(serv string, acc plugins.Accumulator) error {
var found bool
// Parse out user/password from server address tag if given
var servtag string
if strings.Contains(serv, "@") {
servtag = strings.Split(serv, "@")[1]
} else if serv == "" {
servtag = "localhost"
} else {
servtag = serv
}
tags := map[string]string{"server": servtag}
for _, mapped := range mappings {
@ -181,6 +181,25 @@ func (m *Mysql) gatherServer(serv string, acc plugins.Accumulator) error {
}
}
conn_rows, err := db.Query("SELECT user, sum(1) FROM INFORMATION_SCHEMA.PROCESSLIST GROUP BY user")
for conn_rows.Next() {
var user string
var connections int64
err = conn_rows.Scan(&user, &connections)
if err != nil {
return err
}
tags := map[string]string{"server": servtag, "user": user}
if err != nil {
return err
}
acc.Add("connections", connections, tags)
}
return nil
}

View File

@ -45,6 +45,7 @@ func TestMysqlGeneratesMetrics(t *testing.T) {
intMetrics := []string{
"queries",
"slow_queries",
"connections",
}
for _, prefix := range prefixes {