// RequestStats returns a middleware that tracks request metrics.
437473
func RequestStats() macaron.Handler {
	stats := requestStats{
		responseCounts:    make(map[string]map[int]*stats.Counter32),
		latencyHistograms: make(map[string]*stats.LatencyHistogram15s32),
		sizeMeters:        make(map[string]*stats.Meter32),
	}

	return func(ctx *macaron.Context) {
		start := time.Now()
		rw := ctx.Resp.(macaron.ResponseWriter)
		// call next handler. This will return after all handlers
		// have completed and the request has been sent.
		ctx.Next()
		status := rw.Status()
		path := pathSlug(ctx.Req.URL.Path)
		// graphite cluster requests use local=1
		// this way we can differentiate "full" render requests from client to MT (encompassing data processing, proxing to graphite, etc)
		// from "subrequests" where metrictank is called by graphite and graphite does the processing and returns to the client
		if ctx.Req.Request.Form.Get("local") == "1" {
			path += "-local"
		}
		stats.PathStatusCount(path, status)
		stats.PathLatency(path, time.Since(start))
		// only record the request size if the request succeeded.
		if status < 300 {
			stats.PathSize(path, rw.Size())
		}
	}
}
161949
func (c *RPCClient) Stats() (map[string]map[string]string, error) {
	header := requestHeader{
		Command: statsCommand,
		Seq:     c.getSeq(),
	}
	var resp map[string]map[string]string

	err := c.genericRPC(&header, nil, &resp)
	return resp, err
}
158318
func (s *Server) reportStats() {
	_ = metrics.ReportOne(s.opts.traceClient,
		ssf.Gauge("proxy.active_goroutines", float32(atomic.LoadInt64(s.activeProxyHandlers)), globalProtocolTags))
}
788101
func (h *Handler) WriteStats(w io.Writer) {
	b := make([]byte, 1024)

	var lastMetricName string
	metrics := h.metrics.collect(make([]metric, 0, 10000))
	sort.Sort(byNameAndLabels(metrics))

	for i, m := range metrics {
		b = b[:0]
		name := m.rootName()

		if name == lastMetricName {
			// Silence the repeated output of type for values belonging to the
			// same metric.
			m.mtype, m.help = untyped, ""
		} else if i != 0 {
			// After every metric we want to output an empty line to make the
			// output easier to read.
			b = append(b, '\n')
		}

		w.Write(appendMetric(b, m))
		lastMetricName = name
	}
}
945460
func (s *Stat) NetIOStats() []*NetIOStats {
	s.Lock()
	defer s.Unlock()

	var res []*NetIOStats

	do(func() {
		var nSize C.size_t
		var cArray *C.sg_network_io_stats = C.sg_get_network_io_stats_diff(&nSize)
		length := int(nSize)
		slice := (*[1 << 16]C.sg_network_io_stats)(unsafe.Pointer(cArray))[:length:length]

		for _, v := range slice {
			n := &NetIOStats{
				IntName:    C.GoString(v.interface_name),
				TX:         int(v.tx),
				RX:         int(v.rx),
				IPackets:   int(v.ipackets),
				OPackets:   int(v.opackets),
				IErrors:    int(v.ierrors),
				OErrors:    int(v.oerrors),
				Collisions: int(v.collisions),
				Period:     time.Duration(int(v.systime)) * time.Second,
				TimeTaken:  time.Now(),
			}

			res = append(res, n)
		}
	})
	return res
}
524337
func NewRequestsStatsHandler(sub Subsystem, vec *prometheus.GaugeVec) *RequestsStatsHandler {
	return &RequestsStatsHandler{
		baseStatsHandler: baseStatsHandler{
			subsystem: sub,
			collector: vec,
		},
		vec: vec,
	}
}
739621
func (c *Client) IndexStats(indices ...string) *IndicesStatsService {
	return NewIndicesStatsService(c).Index(indices...)
}
1329024
func ReportStatistics(stats *statsd.Client, interval time.Duration, tags []string) ClientParam {
	return func(cl *Client) error {
		ticker := time.NewTicker(interval)
		cl.report = func(ctx context.Context) {
			defer ticker.Stop()
			for {
				select {
				case <-ticker.C:
					SendClientStatistics(cl, stats, tags)
				case <-ctx.Done():
					return
				}
			}
		}
		return nil
	}
}
1072013
func (s *VolumeServer) Stats(
	ctx context.Context,
	req *api.SdkVolumeStatsRequest,
) (*api.SdkVolumeStatsResponse, error) {
	if s.cluster() == nil || s.driver(ctx) == nil {
		return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
	}

	if len(req.GetVolumeId()) == 0 {
		return nil, status.Error(codes.InvalidArgument, "Must supply volume id")
	}

	// Get access rights
	if err := s.checkAccessForVolumeId(ctx, req.GetVolumeId(), api.Ownership_Read); err != nil {
		return nil, err
	}

	stats, err := s.driver(ctx).Stats(req.GetVolumeId(), !req.GetNotCumulative())
	if err != nil {
		return nil, status.Errorf(
			codes.Internal,
			"Failed to obtain stats for volume %s: %v",
			req.GetVolumeId(),
			err.Error())
	}

	return &api.SdkVolumeStatsResponse{
		Stats: stats,
	}, nil
}
582084
func (c *Client) GetStats(i *GetStatsInput) (*StatsResponse, error) {

	p := "/stats"

	if i.Service != "" {
		p = fmt.Sprintf("%s/service/%s", p, i.Service)
	}

	if i.Field != "" {
		p = fmt.Sprintf("%s/field/%s", p, i.Field)
	}

	r, err := c.Get(p, &RequestOptions{
		Params: map[string]string{
			"from":   i.From,
			"to":     i.To,
			"by":     i.By,
			"region": i.Region,
		},
	})
	if err != nil {
		return nil, err
	}

	var sr *StatsResponse
	if err := decodeJSON(&sr, r.Body); err != nil {
		return nil, err
	}

	return sr, nil
}
515082
func (p *podEvaluator) UsageStats(options quota.UsageStatsOptions) (quota.UsageStats, error) {
	return generic.CalculateUsageStats(options, p.listFuncByNamespace, podMatchesScopeFunc, p.Usage)
}
1221929
func (mg *MailgunImpl) GetStats(ctx context.Context, events []string, opts *GetStatOptions) ([]Stats, error) {
	r := newHTTPRequest(generateApiUrl(mg, statsTotalEndpoint))

	if opts != nil {
		if !opts.Start.IsZero() {
			r.addParameter("start", opts.Start.Format(iso8601date))
		}
		if !opts.End.IsZero() {
			r.addParameter("end", opts.End.Format(iso8601date))
		}
		if opts.Resolution != "" {
			r.addParameter("resolution", string(opts.Resolution))
		}
		if opts.Duration != "" {
			r.addParameter("duration", opts.Duration)
		}
	}

	for _, e := range events {
		r.addParameter("event", e)
	}

	r.setClient(mg.Client())
	r.setBasicAuth(basicAuthUser, mg.APIKey())

	var res statsTotalResponse
	err := getResponseFromJSON(ctx, r, &res)
	if err != nil {
		return nil, err
	} else {
		return res.Stats, nil
	}
}
1003328
func (mr *MockStatsClientMockRecorder) SendStats() *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendStats", reflect.TypeOf((*MockStatsClient)(nil).SendStats))
}
615557
func ConnectStats(stats adapter.StatsAPI) (*StatsConnection, error) {
	c := newStatsConnection(stats)

	if err := c.connectClient(); err != nil {
		return nil, err
	}

	return c, nil
}
1373948
func (parser *StandardResultParser) ParseStats(response *SolrResponse, sr *SolrResult) {
	if stats, ok := response.Response["stats"].(map[string]interface{}); ok {
		sr.Stats = stats
	}
}
146414
func (c *Client) Statuses(url *url.URL) (statuses *StatusesService) {
	statuses = &StatusesService{client: c, URL: url}
	return
}
860506
func (b *Bucket) GatherStats(which string) map[string]GatheredStats {
	vsm := b.VBServerMap()
	if vsm.ServerList == nil {
		return nil
	}

	// Go grab all the things at once.
	ch := make(chan GatheredStats, len(vsm.ServerList))
	for i, sn := range vsm.ServerList {
		go getStatsParallel(sn, b, i, which, ch)
	}

	// Gather the results
	rv := map[string]GatheredStats{}
	for range vsm.ServerList {
		gs := <-ch
		rv[gs.Server] = gs
	}
	return rv
}