Fix "nil map" panic in statistics collection.

pull/7193/head
rw 2016-08-23 11:45:12 -07:00
parent a2fcafd5c0
commit 8d7d89d8ed
2 changed files with 10 additions and 7 deletions

View File

@ -5,3 +5,11 @@ type Statistic struct {
Tags map[string]string `json:"tags"`
Values map[string]interface{} `json:"values"`
}
func NewStatistic(name string) Statistic {
return Statistic{
Name: name,
Tags: make(map[string]string),
Values: make(map[string]interface{}),
}
}

View File

@ -210,9 +210,7 @@ func (m *Monitor) Statistics(tags map[string]string) ([]*Statistic, error) {
}
statistic := &Statistic{
Statistic: models.Statistic{
Values: make(map[string]interface{}),
},
Statistic: models.NewStatistic(""),
}
// Add any supplied tags.
@ -277,10 +275,7 @@ func (m *Monitor) Statistics(tags map[string]string) ([]*Statistic, error) {
// Add Go memstats.
statistic := &Statistic{
Statistic: models.Statistic{
Name: "runtime",
Values: make(map[string]interface{}),
},
Statistic: models.NewStatistic("runtime"),
}
// Add any supplied tags to Go memstats