Skip to content

Commit

Permalink
fix save metrics values on mysql inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicola Strappazzon C committed Jul 5, 2020
1 parent dd127e9 commit fc18345
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
23 changes: 14 additions & 9 deletions plugins/inputs/mysql/slave/slave.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func (l *MySQLSlave) Collect() {
m.Connect(config.File.Inputs.MySQL[host].DSN)

var r = m.Query(query)
if len(r) == 0 {
continue
}

var v = []metrics.Value{}

for column := range r[0] {
if value, ok := mysql.ParseValue(r[0][column]); ok {
Expand All @@ -43,17 +48,17 @@ func (l *MySQLSlave) Collect() {
column: value,
})

a.Add(metrics.Metric{
Key: "mysql_slave",
Tags: []metrics.Tag{
{"hostname", config.File.Inputs.MySQL[host].Hostname},
},
Values: []metrics.Value{
{column, value},
},
})
v = append(v, metrics.Value{column, value})
}
}

a.Add(metrics.Metric{
Key: "mysql_slave",
Tags: []metrics.Tag{
{"hostname", config.File.Inputs.MySQL[host].Hostname},
},
Values: v,
})
}
}

Expand Down
23 changes: 14 additions & 9 deletions plugins/inputs/mysql/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func (l *MySQLStatus) Collect() {
m.Connect(config.File.Inputs.MySQL[host].DSN)

var r = m.Query(query)
if len(r) == 0 {
continue
}

var v = []metrics.Value{}

for _, i := range r {
if value, ok := mysql.ParseValue(i["Value"]); ok {
Expand All @@ -43,17 +48,17 @@ func (l *MySQLStatus) Collect() {
i["Variable_name"]: value,
})

a.Add(metrics.Metric{
Key: "mysql_status",
Tags: []metrics.Tag{
{"hostname", config.File.Inputs.MySQL[host].Hostname},
},
Values: []metrics.Value{
{i["Variable_name"], value},
},
})
v = append(v, metrics.Value{i["Variable_name"], value})
}
}

a.Add(metrics.Metric{
Key: "mysql_status",
Tags: []metrics.Tag{
{"hostname", config.File.Inputs.MySQL[host].Hostname},
},
Values: v,
})
}
}

Expand Down
23 changes: 14 additions & 9 deletions plugins/inputs/mysql/variables/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func (l *MySQLVariables) Collect() {
m.Connect(config.File.Inputs.MySQL[host].DSN)

var r = m.Query(query)
if len(r) == 0 {
continue
}

var v = []metrics.Value{}

for _, i := range r {
if value, ok := mysql.ParseValue(i["Value"]); ok {
Expand All @@ -43,17 +48,17 @@ func (l *MySQLVariables) Collect() {
i["Variable_name"]: value,
})

a.Add(metrics.Metric{
Key: "mysql_variables",
Tags: []metrics.Tag{
{"hostname", config.File.Inputs.MySQL[host].Hostname},
},
Values: []metrics.Value{
{i["Variable_name"], value},
},
})
v = append(v, metrics.Value{i["Variable_name"], value})
}
}

a.Add(metrics.Metric{
Key: "mysql_variables",
Tags: []metrics.Tag{
{"hostname", config.File.Inputs.MySQL[host].Hostname},
},
Values: v,
})
}
}

Expand Down

0 comments on commit fc18345

Please sign in to comment.