diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..7a80f7d --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,21 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "windowsSdkVersion": "10.0.19041.0", + "compilerPath": "C:/MinGW/bin/gcc.exe", + "cStandard": "gnu17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9deab0a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "stdlib.h": "c" + } +} \ No newline at end of file diff --git a/README.md b/README.md index 867abbd..6e4e331 100644 --- a/README.md +++ b/README.md @@ -1 +1,16 @@ # ProxMon + +Basic idea: + Use the following PS command to gather basic data on processes: + ps ax -o pid,ppid,uid,lxc,cuu,rss,times,etimes,stat,command --cols 1000 + + Use resident size as an approximation of real memory usage. + + Use CPU utilization may need to be divided by CPU count + +Structure of each entry: + _id: unique ID of data point + time: time sample was taken + node: Node of process + host: Host name + hostType: Type of host ('node', 'lxc', 'vm') diff --git a/py/ps_parse.py b/py/ps_parse.py new file mode 100644 index 0000000..5f1359b --- /dev/null +++ b/py/ps_parse.py @@ -0,0 +1,101 @@ +field_defs = { + 'PID': { + 'desc': 'PID', + 'dtype': str, + }, + 'PPID': { + 'desc': 'Parent PID', + 'dtype': str, + }, + 'UID': { + 'desc': 'User ID', + 'dtype': str, + }, + 'LXC': { + 'desc': 'LXC ID', + 'dtype': str, + }, + '%CUU': { + 'desc': 'CPU Use', + 'dtype': float, + }, + '%MEM': { + 'desc': 'Memory Use', + 'dtype': float, + }, + 'VSZ': { + 'desc': 'Virtual Memory', + 'dtype': int, + 'mult': 1024, + }, + 'RSS': { + 'desc': 'Resident Memory', + 'dtype': int, + 'mult': 1024, + }, + 'PSS': { + 'desc': 'Proportional Shared Memory', + 'dtype': int, + 'mult': 1024, + }, + 'USS': { + 'desc': 'Unique Memory', + 'dtype': int, + 'mult': 1024, + }, + 'SZ': { + 'desc': 'Core Size', + 'dtype': int, + 'mult': 4096, + }, + 'SIZE': { + 'desc': 'Approximate Memory', + 'dtype': int, + 'mult': 1024, + }, + 'THCNT': { + 'desc': 'Thread Count', + 'dtype': int, + }, + 'TIME': { + 'desc': 'Execution Time', + 'dtype': int, + }, + 'ELAPSED': { + 'desc': 'Elapsed Time', + 'dtype': int, + }, + 'STAT': { + 'desc': 'Status', + 'dtype': str, + }, + 'COMMAND': { + 'desc': 'Command', + 'dtype': str, + } +} + +def parseFile(fname): + f = open(fname, 'r') + data = f.read() + f.close() + + data = data.split('\n') + data = list(filter(bool, [line.split() for line in data])) + header = data[0] + procs = [] + + for line in data[1:]: + proc = {} + for i in range(len(header)): + field = field_defs[header[i]] + value = line[i] + if i == len(header): + value = ' '.join(line[i:]) + value = field['dtype'](value) + if 'mult' in field: + value *= field['mult'] + proc[header[i]] = value + procs.append(proc) + return procs + diff --git a/src/exampledir.c b/src/exampledir.c new file mode 100644 index 0000000..1e4091e --- /dev/null +++ b/src/exampledir.c @@ -0,0 +1,33 @@ +#include +#include + +int main(int argc, char *argv[]) { + struct dirent *pDirent; + DIR *pDir; + + // Ensure correct argument count. + + if (argc != 2) { + printf("Usage: testprog \n"); + return 1; + } + + // Ensure we can open directory. + + pDir = opendir(argv[1]); + if (pDir == NULL) { + printf("Cannot open directory '%s'\n", argv[1]); + return 1; + } + + // Process each entry. + + while ((pDirent = readdir(pDir)) != NULL) { + printf("[%s]\n", pDirent->d_name); + } + + // Close directory and exit. + + closedir(pDir); + return 0; +} \ No newline at end of file diff --git a/src/proxmon.c b/src/proxmon.c new file mode 100644 index 0000000..cea025b --- /dev/null +++ b/src/proxmon.c @@ -0,0 +1,12 @@ +#include +#include +#include + +int main(int argc, char *argv[]) { + DIR *procdir = opendir("/proc"); + struct dirent *pDirent; + + while ((pDirent = readdir(procdir)) != NULL) { + printf("[%s]\n", pDirent->d_name); + } +} \ No newline at end of file