-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_file_growing.py
executable file
·54 lines (41 loc) · 1.07 KB
/
is_file_growing.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
import os
import sys
import time
SIZE_TIMEOUT = 10
def get_size(f):
for x in range(SIZE_TIMEOUT):
try:
size = os.stat(f).st_size
return size
except OSError:
time.sleep(1)
return os.stat(f).st_size
def is_growing(f):
size = get_size(f)
time.sleep(1)
for x in range(SIZE_TIMEOUT):
time.sleep(1)
newsize = get_size(f)
if newsize != size:
return True
return False
def is_growing_with_retries(f):
"""Check to see if a file is growing, with retries
this should handle the case when a file gets rotated mid check
"""
for x in range(3):
if is_growing(f):
return True
return False
if __name__ == "__main__":
if len(sys.argv) != 2:
print ("Usage %s filename" % sys.argv[0])
sys.exit(1)
f = sys.argv[1]
res = is_growing_with_retries(f)
if not res:
print ("CRITICAL - ERROR %s is not growing",f)
sys.exit(2)
print ("OK. file %s is growing",f)
sys.exit(0)