Example #1
0
func (s *PerCgroupStatMetrics) Collect() {
	file, err := os.Open(s.path + "/" + "cpu.stat")
	if err != nil {
		return
	}

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		f := regexp.MustCompile("\\s+").Split(scanner.Text(), 2)

		if f[0] == "nr_periods" {
			s.Nr_periods.Set(misc.ParseUint(f[1]))
		}

		if f[0] == "nr_throttled" {
			s.Nr_throttled.Set(misc.ParseUint(f[1]))
		}

		if f[0] == "throttled_time" {
			s.Throttled_time.Set(misc.ParseUint(f[1]))
		}
	}

	s.Cfs_period_us.Set(
		float64(misc.ReadUintFromFile(
			s.path + "/" + "cpu.cfs_period_us")))

	s.Cfs_quota_us.Set(
		float64(misc.ReadUintFromFile(
			s.path + "/" + "cpu.cfs_quota_us")))
}
Example #2
0
// Unexported functions
func parseCPUline(s *CPUStatPerCPU, f []string) {
	s.User.Set(misc.ParseUint(f[1]))
	s.UserLowPrio.Set(misc.ParseUint(f[2]))
	s.System.Set(misc.ParseUint(f[3]))
	s.Idle.Set(misc.ParseUint(f[4]))
	s.Iowait.Set(misc.ParseUint(f[5]))
	s.Irq.Set(misc.ParseUint(f[6]))
	s.Softirq.Set(misc.ParseUint(f[7]))
	s.Steal.Set(misc.ParseUint(f[8]))
	s.Guest.Set(misc.ParseUint(f[9]))
	s.Total.Set(s.User.Get() + s.UserLowPrio.Get() + s.System.Get() + s.Idle.Get())
}
Example #3
0
func (s *PerProcessStatMetrics) Collect() {
	file, err := os.Open("/proc/" + s.Pid + "/stat")
	defer file.Close()

	if err != nil {
		return
	}

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		f := strings.Split(scanner.Text(), " ")
		s.Utime.Set(misc.ParseUint(f[13]))
		s.Stime.Set(misc.ParseUint(f[14]))
		s.Rss.Set(float64(misc.ParseUint(f[23])))
	}
}
Example #4
0
// Collect() collects per process CPU/Memory/IO metrics
func (s *PerProcessStatMetrics) Collect() {

	file, err := os.Open("/proc/" + s.Pid + "/stat")
	defer file.Close()

	if err != nil {
		return
	}

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		f := strings.Split(scanner.Text(), " ")
		s.Utime.Set(misc.ParseUint(f[13]))
		s.Stime.Set(misc.ParseUint(f[14]))
		s.Rss.Set(float64(misc.ParseUint(f[23])))
	}

	// collect IO metrics
	// only works if we are superuser on Linux
	file, err = os.Open("/proc/" + s.Pid + "/io")
	defer file.Close()

	if err != nil {
		return
	}

	scanner = bufio.NewScanner(file)
	for scanner.Scan() {
		f := strings.Split(scanner.Text(), " ")
		switch f[0] {
		case "read_bytes:":
			s.IOReadBytes.Set(misc.ParseUint(f[1]))
		case "write_bytes:":
			s.IOWriteBytes.Set(misc.ParseUint(f[1]))
		}
	}
}
// Unexported functions
func parseCgroupMemLine(g *metrics.Gauge, f []string) {
	length := len(f)
	val := math.NaN()

	if length < 2 {
		goto fail
	}

	val = float64(misc.ParseUint(f[1]))
	g.Set(val)
	return

fail:
	g.Set(math.NaN())
	return
}
Example #6
0
// Unexported functions
func parseMemLine(g *metrics.Gauge, f []string) {
	length := len(f)
	val := math.NaN()

	if length < 2 {
		goto fail
	}

	val = float64(misc.ParseUint(f[1]))
	if length > 2 && f[2] == "kB" {
		val *= 1024
	}

	g.Set(val)
	return

fail:
	g.Set(math.NaN())
	return
}