Beispiel #1
0
func readInput(prompt string) string {
	reader := bufio.NewReader(os.Stdin)
	fmt.Printf("%s: ", prompt)
	text, err := reader.ReadString('\n')
	if err != nil {
		panic(err)
	}

	return u.Trim(text)
}
Beispiel #2
0
func readAsInt(path string) (int, error) {
	file, err := ioutil.ReadFile(path)
	if err != nil {
		return 0, err
	}
	value, err := strconv.ParseFloat(u.Trim(string(file)), 64)
	if err != nil {
		return 0, err
	}
	return int(0.5 + value/1000.0), nil
}
Beispiel #3
0
func CpuTemp() float64 {
	file, err := ioutil.ReadFile("/sys/class/thermal/thermal_zone0/temp")
	if err != nil {
		panic(err)
	}
	temp, err := strconv.Atoi(u.Trim(string(file)))
	if err != nil {
		log.Fatal(err)
	}

	return float64(temp) / 1000.0
}
Beispiel #4
0
func CpuInfo() []KV {
	file, err := ioutil.ReadFile("/proc/cpuinfo")
	if err != nil {
		panic(err)
	}
	cpus := strings.Split(u.Trim(string(file)), "\n\n")

	var maps = make([]KV, len(cpus))
	for id, cpu := range cpus {

		cpuinfo := append(strings.Split(cpu, "\n"), fmt.Sprintf("timestamp:%d", u.Timestamp()))

		var cpuMap = make(KV, len(cpuinfo))
		for _, str := range cpuinfo {
			chunks := strings.Split(str, ":")
			if len(chunks) == 2 {
				cpuMap[u.Trim(strings.ToLower(chunks[0]))] = u.Trim(chunks[1])
			}
		}
		maps[id] = cpuMap
	}

	return maps
}