Script currently takes a csv, finds relevant memory usage values, calculates % memory available, and adds it to a Python OrderedDict to be rewritten to csv.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB

#!/usr/bin/env python3
import csv, sys, getopt
## Main Function, operating on cmdln args
def main(argv):
inptcsv = ''
outptfile = ''
tempfile = '/tmp/sadfaddtemp.tmp'
try:
opts, args = getopt.getopt(argv,"f:t:",["infile=","type="])
## opts used wrong?
except getopt.GetoptError:
print("Usage Message")
sys.exit(2)
## opts used correctly
for opt, arg in opts:
if opt == '-f':
inptcsv = arg
## opt unrecognized
else:
print("Unrecognized opt")
## Parse input csv
open(tempfile,'w').writelines([ line for line in open(inptcsv) if 'LINUX-' not in line])
with open(tempfile, newline='') as csvfile:
csvreader = csv.DictReader(csvfile, delimiter=';')
for row in csvreader:
rowkeys = iter(row.keys())
kbtotal = int(row.get('kbmemused')) + int(row.get('kbmemfree'))
kbavail = int(row.get('kbavail'))
percavail = (kbavail/kbtotal)
fmtpavail = str('{:.1%}'.format(percavail))
row.update({'%kbavail':fmtpavail})
for key,val in zip(row.keys(),row.values()):
print(str(key))
print(str(val))
if __name__ == "__main__":
main(sys.argv[1:])