forked from kdavyd/dtrace
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse_zfsio.py
32 lines (28 loc) · 933 Bytes
/
parse_zfsio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
import sys
import pprint
from datetime import datetime,date,time
def main():
with open(sys.argv[1]) as f:
dt=""
while True:
line = f.readline()
if dt != False:
prev_dt = dt
print dt
dt = is_timestamp(line)
if dt == False:
if not (line.split()[0].startswith("------") or line.split()[0].startswith("Dataset")):
dp_convert_and_write(line,prev_dt)
def is_timestamp(t):
try:
return datetime.strptime(" ".join(t.split()[0:4]),"%Y %b %d %H:%M:%S")
except ValueError:
return False
def dp_convert_and_write(t,t_date):
t = t.split()
f = open (t[0].replace("/","_")+".zfsio.csv", "a")
f.write(datetime.strftime(t_date,'%Y-%m-%d-%T')+','+t[1]+','+t[2]+','+t[3]+','+t[4]+','+t[5]+','+t[6]+'\n')
f.close()
if __name__ == "__main__":
main()