Esempio n. 1
0
func (s concreteService) Get() (vitals Vitals, err error) {
	var (
		loadStats boshstats.CPULoad
		cpuStats  boshstats.CPUStats
		memStats  boshstats.Usage
		swapStats boshstats.Usage
		diskStats DiskVitals
	)

	loadStats, err = s.statsCollector.GetCPULoad()
	if err != nil {
		err = bosherr.WrapError(err, "Getting CPU Load")
		return
	}

	cpuStats, err = s.statsCollector.GetCPUStats()
	if err != nil {
		err = bosherr.WrapError(err, "Getting CPU Stats")
		return
	}

	memStats, err = s.statsCollector.GetMemStats()
	if err != nil {
		err = bosherr.WrapError(err, "Getting Memory Stats")
		return
	}

	swapStats, err = s.statsCollector.GetSwapStats()
	if err != nil {
		err = bosherr.WrapError(err, "Getting Swap Stats")
		return
	}

	diskStats, err = s.getDiskStats()
	if err != nil {
		err = bosherr.WrapError(err, "Getting Disk Stats")
		return
	}

	vitals = Vitals{
		Load: []string{
			fmt.Sprintf("%.2f", loadStats.One),
			fmt.Sprintf("%.2f", loadStats.Five),
			fmt.Sprintf("%.2f", loadStats.Fifteen),
		},
		CPU: CPUVitals{
			User: cpuStats.UserPercent().FormatFractionOf100(1),
			Sys:  cpuStats.SysPercent().FormatFractionOf100(1),
			Wait: cpuStats.WaitPercent().FormatFractionOf100(1),
		},
		Mem:  createMemVitals(memStats),
		Swap: createMemVitals(swapStats),
		Disk: diskStats,
	}
	return
}
Esempio n. 2
0
func (s concreteService) Get() (vitals Vitals, err error) {
	var (
		loadStats boshstats.CPULoad
		cpuStats  boshstats.CPUStats
		memStats  boshstats.Usage
		swapStats boshstats.Usage
		diskStats DiskVitals
	)

	loadStats, err = s.statsCollector.GetCPULoad()
	if err != nil && err != sigar.ErrNotImplemented {
		err = bosherr.WrapError(err, "Getting CPU Load")
		return
	}

	cpuStats, err = s.statsCollector.GetCPUStats()
	if err != nil {
		err = bosherr.WrapError(err, "Getting CPU Stats")
		return
	}

	memStats, err = s.statsCollector.GetMemStats()
	if err != nil {
		err = bosherr.WrapError(err, "Getting Memory Stats")
		return
	}

	swapStats, err = s.statsCollector.GetSwapStats()
	if err != nil {
		err = bosherr.WrapError(err, "Getting Swap Stats")
		return
	}

	diskStats, err = s.getDiskStats()
	if err != nil {
		err = bosherr.WrapError(err, "Getting Disk Stats")
		return
	}

	vitals = Vitals{
		Load: createLoadVitals(loadStats),
		CPU: CPUVitals{
			User: cpuStats.UserPercent().FormatFractionOf100(1),
			Sys:  cpuStats.SysPercent().FormatFractionOf100(1),
			Wait: cpuStats.WaitPercent().FormatFractionOf100(1),
		},
		Mem:  createMemVitals(memStats),
		Swap: createMemVitals(swapStats),
		Disk: diskStats,
	}
	return
}