Esempio n. 1
0
func ReadContainerFromProc(pid int, fullpath string) (string, error) {
	b, err := ue.ExecShCommand(`cat ` + procPath + `/` + strconv.Itoa(pid) + `/root` + fullpath)
	if err != nil {
		return "", err
	}
	bstr := strings.TrimRight(string(b), "\n")
	if strings.Contains(bstr, "Cannot run exec command") ||
		strings.Contains(bstr, "No such exec") ||
		strings.Contains(bstr, "Failed") ||
		strings.Contains(bstr, "invalid argument") ||
		bstr == "" {
		return "", errors.New("Invalid path")
	}
	return bstr, nil
}
Esempio n. 2
0
func listLocalNetInt(pid string) ([]string, error) {
	log.Debug("")
	stdout, err := ue.ExecShCommand(`ls /proc/` + pid + `/root` + netStatsBasePath)
	if err != nil {
		return nil, err
	}
	stdoutstr := string(stdout)
	var interfaces []string
	if len(stdoutstr) != 0 {
		if strings.Contains(stdoutstr, "executable file not found") {
			log.Debug("stdout %s", stdout)
			return nil, errors.New("Doesn't support network statistics")
		}
		for _, inter := range strings.Split(stdoutstr, "\n") {
			if len(inter) != 0 {
				interfaces = append(interfaces, inter)
			}
		}
	}
	return interfaces, nil
}