Script now takes a csv, finds relevant memory usage values, calcuates % memory
available, and adds it to a Python OrderedDict to be rewritten to csv. new file: .gitignore new file: sadfadd
This commit is contained in:
commit
50379a4646
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.*.sw*
|
35
sadfadd
Executable file
35
sadfadd
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
#!/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 = 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})
|
||||||
|
print(row['# hostname'],row['timestamp'],row['%kbavail'])
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main(sys.argv[1:])
|
Loading…
Reference in New Issue
Block a user