func HostInfo() (*HostInfoStat, error) { ret := &HostInfoStat{ OS: runtime.GOOS, } hostname, err := os.Hostname() if err == nil { ret.Hostname = hostname } platform, family, version, err := GetPlatformInformation() if err == nil { ret.Platform = platform ret.PlatformFamily = family ret.PlatformVersion = version } else { return ret, err } boot, err := BootTime() if err == nil { ret.BootTime = boot ret.Uptime = uptime(boot) } procs, err := process.Pids() if err != nil { return ret, err } ret.Procs = uint64(len(procs)) return ret, nil }
//AdjustOOMPriorityByName Adjust the OOM adj value for the process' with the given name regexp func (procs *Procs) AdjustOOMPriorityByName(processName string, value int, ignoreIfNonZero bool) error { found := false pids, err := process.Pids() if err != nil { return err } for _, pid := range pids { // Find the process with the given name if currProcess, err := process.NewProcess(pid); err != nil { continue } else if name, err := currProcess.Name(); err != nil || name != processName { continue } else if err := procs.AdjustOOMPriority(int(pid), value, ignoreIfNonZero); err == nil { found = true } else { // Not an error but logging these for debugging. log.Printf("Error adjusting OOM for process %s (pid %d): %s", processName, pid, err) } } if found { return nil } return fmt.Errorf("No process matches: %s\n", processName) }