本文整理汇总了Golang中github.com/dgryski/carbonzipper/carbonzipperpb.MultiFetchResponse.GetMetrics方法的典型用法代码示例。如果您正苦于以下问题:Golang MultiFetchResponse.GetMetrics方法的具体用法?Golang MultiFetchResponse.GetMetrics怎么用?Golang MultiFetchResponse.GetMetrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/dgryski/carbonzipper/carbonzipperpb.MultiFetchResponse
的用法示例。
在下文中一共展示了MultiFetchResponse.GetMetrics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createRenderResponse
func createRenderResponse(metrics pb.MultiFetchResponse, missing interface{}) []map[string]interface{} {
var response []map[string]interface{}
for _, metric := range metrics.GetMetrics() {
var pvalues []interface{}
for i, v := range metric.Values {
if metric.IsAbsent[i] {
pvalues = append(pvalues, missing)
} else {
pvalues = append(pvalues, v)
}
}
// create the response
presponse := map[string]interface{}{
"start": metric.StartTime,
"step": metric.StepTime,
"end": metric.StopTime,
"name": metric.Name,
"values": pvalues,
}
response = append(response, presponse)
}
return response
}
示例2: fetchHandler
//.........这里部分代码省略.........
continue
}
points, err := w.Fetch(fromTime, untilTime)
w.Close()
if err != nil {
Metrics.RenderErrors.Add(1)
logger.Logf("failed to fetch points from %s: %s", path, err)
continue
}
if points == nil {
Metrics.NotFound.Add(1)
logger.Debugf("Metric time range not found: metric=%s from=%d to=%d ", metric, fromTime, untilTime)
continue
}
values := points.Values()
fromTime := int32(points.FromTime())
untilTime := int32(points.UntilTime())
step := int32(points.Step())
response := pb.FetchResponse{
Name: proto.String(metric),
StartTime: &fromTime,
StopTime: &untilTime,
StepTime: &step,
Values: make([]float64, len(values)),
IsAbsent: make([]bool, len(values)),
}
for i, p := range values {
if math.IsNaN(p) {
response.Values[i] = 0
response.IsAbsent[i] = true
} else {
response.Values[i] = p
response.IsAbsent[i] = false
}
}
multi.Metrics = append(multi.Metrics, &response)
}
var b []byte
switch format {
case "json":
wr.Header().Set("Content-Type", "application/json")
b, err = json.Marshal(multi)
case "protobuf":
wr.Header().Set("Content-Type", "application/protobuf")
b, err = proto.Marshal(&multi)
case "pickle":
// transform protobuf data into what pickle expects
//[{'start': 1396271100, 'step': 60, 'name': 'metric',
//'values': [9.0, 19.0, None], 'end': 1396273140}
var response []map[string]interface{}
for _, metric := range multi.GetMetrics() {
var m map[string]interface{}
m = make(map[string]interface{})
m["start"] = metric.StartTime
m["step"] = metric.StepTime
m["end"] = metric.StopTime
m["name"] = metric.Name
mv := make([]interface{}, len(metric.Values))
for i, p := range metric.Values {
if metric.IsAbsent[i] {
mv[i] = nil
} else {
mv[i] = p
}
}
m["values"] = mv
response = append(response, m)
}
wr.Header().Set("Content-Type", "application/pickle")
var buf bytes.Buffer
pEnc := pickle.NewEncoder(&buf)
err = pEnc.Encode(response)
b = buf.Bytes()
}
if err != nil {
Metrics.RenderErrors.Add(1)
logger.Logf("failed to create %s data for %s: %s", format, "<metric>", err)
return
}
wr.Write(b)
logger.Debugf("fetch: served %q from %d to %d in %v", metric, fromTime, untilTime, time.Since(t0))
}