示例#1
0
func cpu(output string) (used float64, numOfCore int) {
	o := strings.Split(output, "\n")
	o0 := strings.TrimSuffix(o[0], " CPU)")
	ol0 := strings.Split(o0, "(")
	numOfCore = kmgStrconv.AtoIDefault0(ol0[len(ol0)-1])
	o1 := strings.Split(o[3], " ")
	_used := kmgStrconv.ParseFloat64Default0(o1[len(o1)-1])
	used = (float64(100) - _used) / float64(100)
	used = kmgMath.Float64RoundToRelativePrec(used, 4)
	return
}
示例#2
0
func disk(output string) (used float64, total int) {
	o := strings.Split(output, "\n")
	o0 := strings.Split(o[1], " ")
	after := 0
	for i, s := range o0 {
		if i == 0 {
			continue
		}
		if s == "" {
			continue
		}
		if total == 0 {
			total = kmgStrconv.AtoIDefault0(s)
			continue
		}
		after++
		if after == 3 {
			p := kmgStrconv.ParseFloat64Default0(strings.TrimSuffix(s, "%"))
			used = kmgMath.Float64RoundToRelativePrec(p/float64(100), 4)
			break
		}
	}
	return
}