Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Hardik Juneja
slapos
Commits
94476995
Commit
94476995
authored
Oct 05, 2017
by
Hardik Juneja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stack/monitor: use check-free-disk promise from toolbox instead
parent
0e0c5b9a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6 additions
and
89 deletions
+6
-89
stack/monitor/buildout.cfg
stack/monitor/buildout.cfg
+1
-6
stack/monitor/buildout.hash.cfg
stack/monitor/buildout.hash.cfg
+1
-1
stack/monitor/instance-monitor.cfg.jinja2.in
stack/monitor/instance-monitor.cfg.jinja2.in
+4
-9
stack/monitor/templates/check_free_disk.in
stack/monitor/templates/check_free_disk.in
+0
-73
No files found.
stack/monitor/buildout.cfg
View file @
94476995
...
@@ -83,11 +83,6 @@ md5sum = 1bdb4e05c6be04f4e5766c64467fbcec
...
@@ -83,11 +83,6 @@ md5sum = 1bdb4e05c6be04f4e5766c64467fbcec
<= monitor-template-base
<= monitor-template-base
filename = httpd-cors.cfg.in
filename = httpd-cors.cfg.in
md5sum = 683ea85fc054094248baf5752dd089bf
md5sum = 683ea85fc054094248baf5752dd089bf
[monitor-check-free-disk-space]
<= monitor-template-base
filename = check_free_disk.in
md5sum = bab457ac4d139ed31d0b343a7d14d996
# End templates files
# End templates files
# XXX keep compatibility (with software/ipython_notebook/software.cfg )
# XXX keep compatibility (with software/ipython_notebook/software.cfg )
...
@@ -122,8 +117,8 @@ context =
...
@@ -122,8 +117,8 @@ context =
raw python_executable ${buildout:executable}
raw python_executable ${buildout:executable}
raw python_with_eggs ${buildout:directory}/bin/${extra-eggs:interpreter}
raw python_with_eggs ${buildout:directory}/bin/${extra-eggs:interpreter}
raw template_wrapper ${monitor-template-wrapper:location}/${monitor-template-wrapper:filename}
raw template_wrapper ${monitor-template-wrapper:location}/${monitor-template-wrapper:filename}
raw template_check_disk_space ${monitor-check-free-disk-space:location}/${monitor-check-free-disk-space:filename}
raw bin_directory ${buildout:directory}/bin
raw bin_directory ${buildout:directory}/bin
raw check_free_disk_bin ${buildout:directory}/bin/check-free-disk
depends =
depends =
${monitor-eggs:eggs}
${monitor-eggs:eggs}
...
...
stack/monitor/buildout.hash.cfg
View file @
94476995
...
@@ -15,4 +15,4 @@
...
@@ -15,4 +15,4 @@
# not need these here).
# not need these here).
[monitor2-template]
[monitor2-template]
filename = instance-monitor.cfg.jinja2.in
filename = instance-monitor.cfg.jinja2.in
md5sum =
5027f0b1abcc28ce3817cd70fb667a3
b
md5sum =
63ba28173a72e5121603edeaff49ceb
b
stack/monitor/instance-monitor.cfg.jinja2.in
View file @
94476995
...
@@ -377,16 +377,11 @@ output = ${monitor-directory:promises}/buildout-${slap-connection:partition-id}-
...
@@ -377,16 +377,11 @@ output = ${monitor-directory:promises}/buildout-${slap-connection:partition-id}-
mode = 700
mode = 700
[promise-check-free-disk-space]
[promise-check-free-disk-space]
recipe = slapos.recipe.template:jinja2
recipe = slapos.cookbook:wrapper
template = {{ template_check_disk_space }}
wrapper-path = ${monitor-directory:promises}/check-free-disk-space
rendered = ${monitor-directory:promises}/check-free-disk-space
command-line = {{ python_executable }} {{ check_free_disk_bin }} --collectordb ${monitor-instance-parameter:collector-db} --home_path ${buildout:directory} --config ${:config-file}
mode = 0700
context =
key config_file :config-file
raw home_path ${buildout:directory}
raw python_bin {{ python_with_eggs }}
config-file = ${directory:etc}/min-free-disk-size
config-file = ${directory:etc}/min-free-disk-size
mode = 0700
[monitor-base]
[monitor-base]
# create dependencies between required monitor parts
# create dependencies between required monitor parts
...
...
stack/monitor/templates/check_free_disk.in
deleted
100644 → 0
View file @
0e0c5b9a
#!{{ python_bin }}
import os
import sys
def free_space(path, fn):
while True:
try:
disk = os.statvfs(path)
return fn(disk)
except OSError:
pass
if os.sep not in path:
break
path = os.path.split(path)[0]
def user_free_space(path):
return free_space(path, lambda d: d.f_bsize * d.f_bavail)
def check_inode_usage(path):
max_inode_usage = 97.99 # < 98% usage
st = os.statvfs(path)
usage_output = ""
total_inode = st.f_files
free_inode = st.f_ffree
usage = round((float(total_inode - free_inode) / total_inode), 4) * 100
if usage > max_inode_usage:
return "Disk Inodes are widely used: %s%%" % usage
elif os.path.exists('/tmp'):
# check if /tmp is mounted on another disk than path
tmp_st = os.statvfs('/tmp')
if tmp_st.f_blocks != st.f_blocks:
tmp_usage = round((float(tmp_st.f_files - tmp_st.f_ffree) / tmp_st.f_files), 4) * 100
if tmp_usage > max_inode_usage:
return "Disk Inodes are widely used: %s%%" % tmp_usage
return ""
if __name__ == '__main__':
home_path = '{{ home_path }}'
config_file = '{{ config_file }}'
min_free_size = 1024*1024*1024*2 # 2G by default
if os.path.exists(config_file):
with open(config_file) as f:
min_size_str = f.read().strip()
if min_size_str == '0':
# disable check
print "Free disk space check is disabled\n set a number up to 0 to enable!"
exit(0)
if min_size_str.isdigit():
value = int(min_size_str)
if value >= 200:
# Minimum value is 200Mb, it's already low
min_free_size = int(min_size_str)*1024*1024
else:
with open(config_file, 'w') as f:
f.write(str(min_free_size/(1024*1024)))
real_free_space = user_free_space(home_path)
if real_free_space > min_free_size:
inode_usage = check_inode_usage(home_path)
if inode_usage:
print inode_usage
exit(2)
print "Disk usage: OK"
exit(0)
real_space_g = round(real_free_space/(1024.0*1024*1024), 2)
min_space_g = round(min_free_size/(1024.0*1024*1024), 2)
print 'Free disk space low: remaning %s G (threshold: %s G)' % (
real_space_g, min_space_g)
print 'You can modify minimum value on your monitor interface.'
exit(1)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment