当前位置: 首页>>代码示例>>Golang>>正文


Golang Plot.GetLabels方法代码示例

本文整理汇总了Golang中github.com/GeoNet/mtr/ts.Plot.GetLabels方法的典型用法代码示例。如果您正苦于以下问题:Golang Plot.GetLabels方法的具体用法?Golang Plot.GetLabels怎么用?Golang Plot.GetLabels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/GeoNet/mtr/ts.Plot的用法示例。


在下文中一共展示了Plot.GetLabels方法的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
//.........这里部分代码省略.........
开发者ID:GeoNet,项目名称:mtr,代码行数:101,代码来源:app_metric.go


注:本文中的github.com/GeoNet/mtr/ts.Plot.GetLabels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。