GatherMetricBytes gathers the registered metric info and encode it to [][]byte.
()
| 106 | |
| 107 | // GatherMetricBytes gathers the registered metric info and encode it to [][]byte. |
| 108 | func (cc *CollectClient) GatherMetricBytes() (mfb [][]byte, err error) { |
| 109 | mfs, err := cc.Registry.Gather() |
| 110 | if err != nil { |
| 111 | log.Errorf("gather metrics failed: %s", err) |
| 112 | return |
| 113 | } |
| 114 | mfb = make([][]byte, 0, len(mfs)) |
| 115 | for _, mf := range mfs[:] { |
| 116 | //log.Debugf("mf: %s", mf.String()) |
| 117 | buf := new(bytes.Buffer) |
| 118 | //enc := expfmt.NewEncoder(buf, expfmt.FmtProtoCompact) |
| 119 | //err = enc.Encode(mf) |
| 120 | _, err := expfmt.MetricFamilyToText(buf, mf) |
| 121 | if err != nil { |
| 122 | log.Warnf("encode MetricFamily failed: %s", err) |
| 123 | continue |
| 124 | } |
| 125 | mfb = append(mfb, buf.Bytes()) |
| 126 | } |
| 127 | if len(mfb) == 0 { |
| 128 | err = errors.New("no valid metric gathered") |
| 129 | } |
| 130 | |
| 131 | return |
| 132 | } |
| 133 | |
| 134 | // UploadMetrics calls RPC UploadMetrics to upload its metric info. |
| 135 | func (cc *CollectClient) UploadMetrics(BPNodeID proto.NodeID) (err error) { |