本文整理汇总了Golang中github.com/GeoNet/mtr/ts.Plot.GetSeries方法的典型用法代码示例。如果您正苦于以下问题:Golang Plot.GetSeries方法的具体用法?Golang Plot.GetSeries怎么用?Golang Plot.GetSeries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/GeoNet/mtr/ts.Plot
的用法示例。
在下文中一共展示了Plot.GetSeries方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: appMetricCsv
func appMetricCsv(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
a := appMetric{}
v := r.URL.Query()
applicationID := v.Get("applicationID")
resolution := v.Get("resolution")
if resolution == "" {
resolution = "minute"
}
var timeRange []time.Time
var err error
if timeRange, err = parseTimeRange(v); err != nil {
return weft.InternalServerError(err)
}
// the Plot type holds all the data used to plot svgs, we'll create a CSV from the labels and point values
var p ts.Plot
switch v.Get("group") {
case "counters":
if res := a.loadCounters(applicationID, resolution, timeRange, &p); !res.Ok {
return res
}
case "timers":
// "full" resolution for timers is 90th percentile max per minute over fourty days
sourceID := v.Get("sourceID")
if sourceID != "" {
if res := a.loadTimersWithSourceID(applicationID, sourceID, resolution, timeRange, &p); !res.Ok {
return res
}
} else {
if res := a.loadTimers(applicationID, resolution, timeRange, &p); !res.Ok {
return res
}
}
case "memory":
if res := a.loadMemory(applicationID, resolution, timeRange, &p); !res.Ok {
return res
}
case "objects":
if res := a.loadAppMetrics(applicationID, resolution, internal.MemHeapObjects, timeRange, &p); !res.Ok {
return res
}
case "routines":
if res := a.loadAppMetrics(applicationID, resolution, internal.Routines, timeRange, &p); !res.Ok {
return res
}
default:
return weft.BadRequest("invalid value for group")
}
// CSV headers, the first label is always time
labels := p.GetLabels()
var headers []string
for _, label := range labels {
headers = append(headers, label.Label)
}
// Labels can be in random order so keep a sorted list but with time always at 0
sort.Strings(headers)
headers = append([]string{"time"}, headers...)
values := make(map[time.Time]map[string]float64)
ts := times{} // maintaining an ordered and unique list of times in the map
// add all points to a map to collect duplicate times with different column names
allData := p.GetSeries()
for i, d := range allData {
points := d.Series.Points
for _, point := range points {
if _, ok := values[point.DateTime]; ok == false {
values[point.DateTime] = map[string]float64{labels[i].Label: point.Value}
ts = append(ts, point.DateTime)
} else {
v := values[point.DateTime]
v[labels[i].Label] = point.Value
}
}
}
if len(values) == 0 {
return &weft.StatusOK
}
w := csv.NewWriter(b)
sort.Sort(ts)
for i, t := range ts {
// CSV headers
if i == 0 {
if err = w.Write(headers); err != nil {
return weft.InternalServerError(err)
}
}
fields := []string{t.Format(DYGRAPH_TIME_FORMAT)}
// CSV data
//.........这里部分代码省略.........