Andrew's git
/
logparse.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
fix bug in writing disk usage
author
Andrew Lorimer
<andrew@charles.cortex>
Sun, 17 Mar 2019 08:47:43 +0000
(19:47 +1100)
committer
Andrew Lorimer
<andrew@charles.cortex>
Sun, 17 Mar 2019 08:47:43 +0000
(19:47 +1100)
logparse.py
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
769d14c
)
diff --git
a/logparse.py
b/logparse.py
index 638d02a0a50d7f2dd209e3717e888c6a90fc7e37..19dba198cf926ace2dbdcc9048e33c4ffc531bf7 100755
(executable)
--- a/
logparse.py
+++ b/
logparse.py
@@
-51,7
+51,10
@@
config = {
'httpd': {
'resolve-domains': '',
},
'httpd': {
'resolve-domains': '',
},
- 'du-paths': ['/', '/etc', '/home'],
+ 'du': {
+ 'paths': ['/', '/etc', '/home'],
+ 'force-write': 'n',
+ },
'hostname-path': '/etc/hostname',
'logs': {
'auth': '/var/log/auth.log',
'hostname-path': '/etc/hostname',
'logs': {
'auth': '/var/log/auth.log',
@@
-219,8
+222,8
@@
def hostname(): # get the hostname of current server
return hn
def getlocaldomain(): # get the parent fqdn of current server
return hn
def getlocaldomain(): # get the parent fqdn of current server
- domain = socket.getfqdn().split('.', 1)
- if len(domain)
=
= 2:
+ domain = socket.getfqdn().split('.', 1)
# Note: if socket.fetfqdn() returns localhost, make sure the first entry in /etc/hosts contains the fqdn
+ if len(domain)
!
= 2:
logger.warning('Could not get domain of this server, only hostname. Please consider updating /etc/hosts')
return ''
else:
logger.warning('Could not get domain of this server, only hostname. Please consider updating /etc/hosts')
return ''
else:
@@
-298,6
+301,7
@@
def writelog(path = None, content = "", mode = 'w'): # read file, substituting
file = open(path, mode)
file.write(content)
file.close()
file = open(path, mode)
file.write(content)
file.close()
+ logger.debug("written to file " + path)
def getusage(path): # Get disk usage statistics
disk = os.statvfs(path)
def getusage(path): # Get disk usage statistics
disk = os.statvfs(path)
@@
-793,20
+797,20
@@
def du():
out = []
content = readlog('alloc')
contentnew = ""
out = []
content = readlog('alloc')
contentnew = ""
- for p
in config['du-
paths']:
- alloc_f = getusage(p).alloc
+ for p
ath in config['du']['
paths']:
+ alloc_f = getusage(p
ath
).alloc
delta = None
try:
delta = None
try:
- alloc_i = re.search(p + '\t(.*)\n', content).group(1)
+ alloc_i = re.search(p
ath
+ '\t(.*)\n', content).group(1)
delta = alloc_f - float(alloc_i)
except:
pass
if (delta == None):
delta = alloc_f - float(alloc_i)
except:
pass
if (delta == None):
- out.append([p, "used " + parsesize(alloc_f)])
+ out.append([p
ath
, "used " + parsesize(alloc_f)])
else:
else:
- out.append([p, "used " + parsesize(alloc_f), "delta " + parsesize(delta)])
- contentnew += (p + '\t' + str(alloc_f) + '\n')
- if config['rotate'] == 'y':
+ out.append([p
ath
, "used " + parsesize(alloc_f), "delta " + parsesize(delta)])
+ contentnew += (p
ath
+ '\t' + str(alloc_f) + '\n')
+ if config['rotate'] == 'y'
or config['du']['force-write'] == 'y'
:
writelog('alloc', contentnew)
writetitle("du")
writelog('alloc', contentnew)
writetitle("du")