// DeviceStats returns the statistics for the passed devices. If the device is unknown, an
// UnknownDeviceErr is returned.
970964
func (m *manager) DeviceStats(d *structs.AllocatedDeviceResource) (*device.DeviceGroupStats, error) {
	// Go through each plugin and see if it has the requested devices
	for _, i := range m.instances {
		if !i.HasDevices(d) {
			continue
		}

		// We found a match so reserve
		return i.DeviceStats(d), nil
	}

	return nil, UnknownDeviceErrFromAllocated("failed to collect statistics", d)
}
576063
func (_m *Protocol) GetDevices() ([]common.Device, error) {
	ret := _m.Called()

	var r0 []common.Device
	if rf, ok := ret.Get(0).(func() []common.Device); ok {
		r0 = rf()
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]common.Device)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func() error); ok {
		r1 = rf()
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
844713
func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
	mps, err := mountPointDetails()
	if err != nil {
		return nil, err
	}
	stats := []filesystemStats{}
	for _, labels := range mps {
		if c.ignoredMountPointsPattern.MatchString(labels.mountPoint) {
			log.Debugf("Ignoring mount point: %s", labels.mountPoint)
			continue
		}
		if c.ignoredFSTypesPattern.MatchString(labels.fsType) {
			log.Debugf("Ignoring fs type: %s", labels.fsType)
			continue
		}
		stuckMountsMtx.Lock()
		if _, ok := stuckMounts[labels.mountPoint]; ok {
			stats = append(stats, filesystemStats{
				labels:      labels,
				deviceError: 1,
			})
			log.Debugf("Mount point %q is in an unresponsive state", labels.mountPoint)
			stuckMountsMtx.Unlock()
			continue
		}
		stuckMountsMtx.Unlock()

		// The success channel is used do tell the "watcher" that the stat
		// finished successfully. The channel is closed on success.
		success := make(chan struct{})
		go stuckMountWatcher(labels.mountPoint, success)

		buf := new(syscall.Statfs_t)
		err = syscall.Statfs(rootfsFilePath(labels.mountPoint), buf)

		stuckMountsMtx.Lock()
		close(success)
		// If the mount has been marked as stuck, unmark it and log it's recovery.
		if _, ok := stuckMounts[labels.mountPoint]; ok {
			log.Debugf("Mount point %q has recovered, monitoring will resume", labels.mountPoint)
			delete(stuckMounts, labels.mountPoint)
		}
		stuckMountsMtx.Unlock()

		if err != nil {
			stats = append(stats, filesystemStats{
				labels:      labels,
				deviceError: 1,
			})
			log.Debugf("Error on statfs() system call for %q: %s", rootfsFilePath(labels.mountPoint), err)
			continue
		}

		var ro float64
		for _, option := range strings.Split(labels.options, ",") {
			if option == "ro" {
				ro = 1
				break
			}
		}

		stats = append(stats, filesystemStats{
			labels:    labels,
			size:      float64(buf.Blocks) * float64(buf.Bsize),
			free:      float64(buf.Bfree) * float64(buf.Bsize),
			avail:     float64(buf.Bavail) * float64(buf.Bsize),
			files:     float64(buf.Files),
			filesFree: float64(buf.Ffree),
			ro:        ro,
		})
	}
	return stats, nil
}
1361241
func (f *RemoteRuntime) ContainerStats(ctx context.Context, req *kubeapi.ContainerStatsRequest) (*kubeapi.ContainerStatsResponse, error) {
	stats, err := f.RuntimeService.ContainerStats(req.ContainerId)
	if err != nil {
		return nil, err
	}

	return &kubeapi.ContainerStatsResponse{Stats: stats}, nil
}
116966
func (d *FsDevice) stats(ctx context.Context, stats chan *device.StatsResponse, interval time.Duration) {
	defer close(stats)

	// Create a timer that will fire immediately for the first detection
	ticker := time.NewTimer(0)

	for {
		select {
		case <-ctx.Done():
			return
		case <-ticker.C:
			ticker.Reset(interval)
		}

		deviceStats, err := d.collectStats()
		if err != nil {
			stats <- &device.StatsResponse{
				Error: err,
			}
			return
		}
		if deviceStats == nil {
			continue
		}

		stats <- &device.StatsResponse{
			Groups: []*device.DeviceGroupStats{deviceStats},
		}
	}
}
614008
func getDevices(pool, block, metadatadev string) (map[int]*DeviceBlockStats, error) {
	cmd := exec.Command("thin_dump", "-f", "xml", metadatadev, "-m", block)
	stdout, err := cmd.StdoutPipe()
	cmd.Stderr = os.Stderr
	if err != nil {
		return nil, err
	}
	if err := cmd.Start(); err != nil {
		return nil, err
	}
	devices, err := parseMetadata(stdout)
	if err != nil {
		return nil, err
	}
	if err := cmd.Wait(); err != nil {
		return nil, err
	}
	return devices, nil
}
557723
func (c *HyperClient) GetPodStats(podID string) (*types.PodStats, error) {
	statsResponse, err := c.client.PodStats(
		c.ctx,
		&types.PodStatsRequest{PodID: podID},
	)

	if err != nil {
		return nil, err
	}

	return statsResponse.PodStats, nil
}
67694
func (s *ServerRPC) PodStats(c context.Context, req *types.PodStatsRequest) (*types.PodStatsResponse, error) {
	statsObject, err := s.daemon.GetPodStats(req.PodID)
	if err != nil {
		return nil, err
	}

	stats := statsObject.(*runvtypes.PodStats)

	return &types.PodStatsResponse{
		PodStats: convertRunvStatsToGrpcTypes(stats),
	}, nil
}
515495
func (p *V2) GetDevices() ([]common.Device, error) {
	p.RLock()
	defer p.RUnlock()
	if len(p.devices) == 0 {
		return nil, common.ErrNotFound
	}
	devices := make([]common.Device, len(p.devices))
	i := 0
	for _, device := range p.devices {
		devices[i] = device
		i++
	}

	return devices, nil
}
873005
func (s *Stat) MemStats() *MemStats {
	s.Lock()
	defer s.Unlock()

	memStats := C.sg_get_mem_stats(nil)
	swapStats := C.sg_get_swap_stats(nil)

	m := &MemStats{
		Total:     int(memStats.total),
		Free:      int(memStats.free),
		Used:      int(memStats.used),
		Cache:     int(memStats.cache),
		SwapTotal: int(swapStats.total),
		SwapUsed:  int(swapStats.used),
		SwapFree:  int(swapStats.free),
	}
	return m
}
1244220
func (mc MongoClient) GetAllDeviceReports() ([]contract.DeviceReport, error) {
	return mc.getDeviceReports(bson.M{})
}
655789
func (n *nvmlDriver) DeviceInfoAndStatusByIndex(index uint) (*DeviceInfo, *DeviceStatus, error) {
	return nil, nil, UnavailableLib
}
558380
func (_m *Location) Devices() []common.Device {
	ret := _m.Called()

	var r0 []common.Device
	if rf, ok := ret.Get(0).(func() []common.Device); ok {
		r0 = rf()
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]common.Device)
		}
	}

	return r0
}
661903
func deviceStatsToDatapoints(stats []IODeviceStats, prefix string, baseTags map[string]string, ts string) []producers.Datapoint {
	var datapoints []producers.Datapoint

	for _, stat := range stats {
		dev := devTotal
		if stat.Device.Major > 0 {
			dev = fmt.Sprintf("%d:%d", stat.Device.Major, stat.Device.Minor)
		}
		// Create a new tags map for these datapoints
		tags := map[string]string{blkioDevice: dev}
		for k, v := range baseTags {
			tags[k] = v
		}
		datapoints = append(datapoints, statValuesToDatapoints(stat.Serviced, prefix+"."+serviced, tags, ts)...)
		datapoints = append(datapoints, statValuesToDatapoints(stat.ServiceBytes, prefix+"."+serviceBytes, tags, ts)...)
		datapoints = append(datapoints, statValuesToDatapoints(stat.ServiceTime, prefix+"."+serviceTime, tags, ts)...)
		datapoints = append(datapoints, statValuesToDatapoints(stat.Merged, prefix+"."+merged, tags, ts)...)
		datapoints = append(datapoints, statValuesToDatapoints(stat.Queued, prefix+"."+queued, tags, ts)...)
		datapoints = append(datapoints, statValuesToDatapoints(stat.WaitTime, prefix+"."+waitTime, tags, ts)...)
	}

	return datapoints
}
260892
func (s deviceService) FetchDevices(opts ...DeviceRequestOption) (*DeviceResponse, error) {
	request := &deviceRequestOpts{}
	for _, option := range opts {
		if err := option(request); err != nil {
			return nil, err
		}
	}
	var response DeviceResponse
	req, err := s.client.NewRequest("POST", fetchDevicesPath, request)
	if err != nil {
		return nil, err
	}
	err = s.client.Do(req, &response)
	if err != nil {
		return nil, err
	}
	return &response, nil
}
1104798
func (s *DeviceData) SetDeviceStatus(v string) *DeviceData {
	s.DeviceStatus = &v
	return s
}
782533
func (m *manager) AllStats() []*device.DeviceGroupStats {
	// Go through each plugin and collect stats
	var stats []*device.DeviceGroupStats
	for _, i := range m.instances {
		stats = append(stats, i.AllStats()...)
	}

	return stats
}