lib/ec2macossystemmonitor/cpuutilization.go (13 lines of code) (raw):
package ec2macossystemmonitor
import (
"fmt"
"strconv"
"github.com/shirou/gopsutil/cpu"
)
// RunningCpuUsage gathers the value expected for CloudWatch but allows long running measurement. This is intended for
// usage where repeated calls will take place.
func RunningCpuUsage() (s string, err error) {
percent, err := cpu.Percent(0, false)
if err != nil {
return "", fmt.Errorf("ec2macossystemmonitor: error while getting cpu stats: %s", err)
}
return strconv.FormatFloat(percent[0], 'f', -1, 64), nil
}