def get_proc_pid_stat(pid: int, c=None) -> dict:
    assert isinstance(pid, int)
    assert pid > 0

    stdout, stderr, exitcode = jk_sysinfo.run(
        c, "cat /proc/" + str(pid) + "/stat")
    stdout = stdout.strip()

    # split into parts and extract fileName

    parts = stdout.split(" ")
    items = [parts[0]]
    assert parts[1][0] == "("
    fileName = None
    for i in range(1, len(parts)):
        if parts[i][-1] == ")":
            # end of file name found
            fileName = " ".join(parts[1:i + 1])
            fileName = fileName[1:-1]
            items.extend(parts[i + 1:])
            break
    assert fileName is not None
    assert len(items) == 51

    ret = {}
    for _i, _key, _keyResult, _parser, _iFactor in _VALUE_SPECS_STAT:
        _vpart = items[_i]
        if (_parser is not None) and (_parser is not str):
            ret[_keyResult] = (int(_vpart) *
                               _iFactor) if (_parser
                                             == int) else _parser(_vpart)
        else:
            ret[_keyResult] = _vpart

    return ret
def get_proc_pid_status(pid: int, c=None) -> dict:
    assert isinstance(pid, int)
    assert pid > 0

    stdout, stderr, exitcode = jk_sysinfo.run(
        c, "cat /proc/" + str(pid) + "/status")

    stdoutLines = stdout.split("\n")

    ret = _LINE_PARSER.parseLinesReturnDict(
        stdoutLines, valueParserMap=_VALUE_PARSERS_STATUS)
    return ret
예제 #3
0
def cmd_diskfree(cfg: dict, log):
    print()

    mounter = jk_mounting.Mounter()
    mi = mounter.getMountInfoByFilePath(cfg["wwwWikiRootDir"])
    stdout, stderr, exitcode = jk_sysinfo.run(None, "/bin/df -BK")
    ret = jk_sysinfo.parse_df(stdout, stderr, exitcode)[mi.mountPoint]

    print("Mount point:", mi.mountPoint)

    fBlock = (ret["spaceTotal"] - ret["spaceFree"]) / ret["spaceTotal"]
    barLength = min(jk_console.Console.width(), 140) - 20
    iBlock = int(round(fBlock * barLength))
    text = "{0} {1:.1f}% filled".format(
        "#" * iBlock + ":" * (barLength - iBlock), fBlock * 100)
    print(text)

    print(_formatGBytes((ret["spaceTotal"] - ret["spaceFree"]) / 1073741824),
          "of", _formatGBytes(ret["spaceTotal"] / 1073741824), "used.")
예제 #4
0
import jk_sysinfo
#import jk_json
#import jk_flexdata
import jk_utils

from fabric import Connection
import jk_pwdinput

REMOTE_HOST = "127.0.0.1"
REMOTE_PORT = 22
REMOTE_LOGIN = "******"
REMOTE_PASSWORD = jk_pwdinput.readpwd("Password for " + REMOTE_LOGIN + "@" +
                                      REMOTE_HOST + ": ")
c = Connection(host=REMOTE_HOST,
               user=REMOTE_LOGIN,
               port=REMOTE_PORT,
               connect_kwargs={"password": REMOTE_PASSWORD})

SYSTEM_ID = "nbxxxxxxxx"

EXECUTABLE_PATH = "/home/" + REMOTE_LOGIN + "/DevOS/PythonModules/jk_sysinfo/examples/sysmonctrl.py"

stdout, stderr, exitcode = jk_sysinfo.run(c, EXECUTABLE_PATH + " sysinfo")
if exitcode != 0:
    print("FAILED!")
else:
    with open("sysmonctrl.json", "w") as f:
        f.write(stdout)
    print(stderr)