Testing code

This commit is contained in:
Dan Snyder 2025-01-09 12:37:51 -05:00
parent 6df69b47eb
commit fed3c7ee6f
6 changed files with 187 additions and 0 deletions

21
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -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
}

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"stdlib.h": "c"
}
}

View File

@ -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')

101
py/ps_parse.py Normal file
View File

@ -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

33
src/exampledir.c Normal file
View File

@ -0,0 +1,33 @@
#include <stdio.h>
#include <dirent.h>
int main(int argc, char *argv[]) {
struct dirent *pDirent;
DIR *pDir;
// Ensure correct argument count.
if (argc != 2) {
printf("Usage: testprog <dirname>\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;
}

12
src/proxmon.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
int main(int argc, char *argv[]) {
DIR *procdir = opendir("/proc");
struct dirent *pDirent;
while ((pDirent = readdir(procdir)) != NULL) {
printf("[%s]\n", pDirent->d_name);
}
}