// NewStatsClient initializes a new stats client
1283
func NewStatsClient(cr statscollector.Collector) (StatsClient, error) {

	sc := &statsClient{
		collector:     cr,
		rpchdl:        rpcwrapper.NewRPCWrapper(),
		secret:        os.Getenv(constants.EnvStatsSecret),
		statsChannel:  os.Getenv(constants.EnvStatsChannel),
		statsInterval: defaultStatsIntervalMiliseconds * time.Millisecond,
		userRetention: defaultUserRetention * time.Minute,
		stop:          make(chan bool),
	}

	if sc.statsChannel == "" {
		return nil, errors.New("no path to stats socket provided")
	}

	if sc.secret == "" {
		return nil, errors.New("no secret provided for stats channel")
	}

	return sc, nil
}
843115
func newServiceAccounts(c *CoreClient, namespace string) *serviceAccounts {
	return &serviceAccounts{
		client: c,
		ns:     namespace,
	}
}
1131722
func newClient(statsNodeClient winNodeStatsClient) (Client, error) {
	statsClient := new(StatsClient)
	statsClient.client = statsNodeClient

	err := statsClient.client.startMonitoring()
	if err != nil {
		return nil, err
	}

	return statsClient, nil
}
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
	}
}
669803
func NewStatsFormat(source, osType string) formatter.Format {
	if source == formatter.TableFormatKey {
		if osType == winOSType {
			return formatter.Format(winDefaultStatsTableFormat)
		}
		return formatter.Format(defaultStatsTableFormat)
	}
	return formatter.Format(source)
}
324372
func (b *bundle) NewShimClient(ctx context.Context, namespace string, getClientOpts ShimOpt, runcOpts *runctypes.RuncOptions) (*client.Client, error) {
	cfg, opt := getClientOpts(b, namespace, runcOpts)
	return client.New(ctx, cfg, opt)
}
1237414
func NewStatsdClient(addr string, prefix string) *StatsdClient {
	// allow %HOST% in the prefix string
	prefix = strings.Replace(prefix, "%HOST%", Hostname, 1)
	return &StatsdClient{
		addr:   addr,
		prefix: prefix,
		Logger: log.New(os.Stdout, "[StatsdClient] ", log.Ldate|log.Ltime),
	}
}
1155902
func NewServerClient(idStore *IDStore, options CodeStoreOptions) (Client, error) {
	codeStore, err := newCodeStore(idStore, options)
	if err != nil {
		return nil, err
	}
	return newServerClient(idStore, codeStore)
}
406460
func NewServiceClients(searchTarget string) (clients []ServiceClient, errors []error, err error) {
	var maybeRootDevices []MaybeRootDevice
	if maybeRootDevices, err = DiscoverDevices(searchTarget); err != nil {
		return
	}

	clients = make([]ServiceClient, 0, len(maybeRootDevices))

	for _, maybeRootDevice := range maybeRootDevices {
		if maybeRootDevice.Err != nil {
			errors = append(errors, maybeRootDevice.Err)
			continue
		}

		deviceClients, err := NewServiceClientsFromRootDevice(maybeRootDevice.Root, maybeRootDevice.Location, searchTarget)
		if err != nil {
			errors = append(errors, err)
			continue
		}
		clients = append(clients, deviceClients...)
	}

	return
}
14880
func newStats() stats {
	s := stats{}
	s.ChannelStats = make(map[string]eventIDStat)
	return s
}
329063
func (daemon *Daemon) newStatsCollector(interval time.Duration) *stats.Collector {
	// FIXME(vdemeester) move this elsewhere
	if runtime.GOOS == "linux" {
		meminfo, err := system.ReadMemInfo()
		if err == nil && meminfo.MemTotal > 0 {
			daemon.machineMemory = uint64(meminfo.MemTotal)
		}
	}
	s := stats.NewCollector(daemon, interval)
	go s.Run()
	return s
}
1270907
func NewStats() *Stats {
	bps := &Stats{}
	bps.Timings = stats.NewTimings("", "", "")
	bps.Rates = stats.NewRates("", bps.Timings, 15, 60e9)
	bps.History = history.New(3)
	bps.SecondsBehindMaster.Set(math.MaxInt64)
	return bps
}
476611
func NewStaticShardManager(
	serverAddrs []string,
	shardFunc func(key string, numShard int) (shard int),
	options net2.ConnectionOptions) ShardManager {

	manager := &StaticShardManager{}
	manager.Init(
		shardFunc,
		func(err error) { log.Print(err) },
		log.Print,
		options)

	shardStates := make([]ShardState, len(serverAddrs), len(serverAddrs))
	for i, addr := range serverAddrs {
		shardStates[i].Address = addr
		shardStates[i].State = ActiveServer
	}

	manager.UpdateShardStates(shardStates)

	return manager
}
568666
func NewStatus(code Code, msg string) *Status {
	return &Status{
		code:    code,
		message: msg,
	}
}
958145
func NewStreamClient(params ClientParams) StreamClient {
	return newClient(params.ServiceName, params.ClientConfig, params.Options...)
}
1331475
func newStats(c *Context) (stats.Stats, error) {
	u := c.String(FlagStats)
	if u == "" {
		return stats.Null, nil
	}

	uri, err := url.Parse(u)
	if err != nil {
		return nil, err
	}

	switch uri.Scheme {
	case "statsd":
		return newStatsdStats(uri.Host)
	case "dogstatsd":
		return newDogstatsdStats(uri.Host)
	default:
		return stats.Null, nil
	}
}
364397
func NewStatsFetcher(logger log.Logger, pool *pool.ConnPool, region string) *StatsFetcher {
	return &StatsFetcher{
		logger:   logger.Named("stats_fetcher"),
		pool:     pool,
		region:   region,
		inflight: make(map[string]struct{}),
	}
}