diff --git a/README.md b/README.md index 9f92c27..95ad4c6 100644 --- a/README.md +++ b/README.md @@ -1 +1,13 @@ # check_mk-mysql_open_files + +This check will monitor mysql open_files value raported to +setted open_files_limit value. The plugin must be copied +into /usr/lib/check_mk_agent/plugins folder and the +executable bit must be set for this file. + +The check will return current open_files_limit and open_files +values. The check gets critical at 90 percent of +open_files_limit and warning at 80. + +Both limits are definable in Wato under "Parameters for +Inventorized Checks", "Applications, Processes & Services". diff --git a/agents/plugins/mysql_open_files b/agents/plugins/mysql_open_files new file mode 100644 index 0000000..36aa239 --- /dev/null +++ b/agents/plugins/mysql_open_files @@ -0,0 +1,16 @@ +#!/bin/bash +# SpearHead Systems george.mocanu@sphs.ro 2015 +# Check_MK plugin for monitoring mysql open_files + +# Get mysqld pid number +mysqlPid=`pidof mysqld` + +# Count files currently opened by mysql +mysqlOpenFiles=`ls -las /proc/$mysqlPid/fd/ | wc -l` + +# Get current open_files_limit value +mysqlOpenFilesLimit=`cat /proc/$mysqlPid/limits | grep 'Max\ open\ files' | awk '{print $4}'` + +# Check output +echo '<<>>' +echo 'open_files ' $mysqlOpenFilesLimit ' ' $mysqlOpenFiles diff --git a/checkman/mysql_open_files b/checkman/mysql_open_files new file mode 100644 index 0000000..a82c650 --- /dev/null +++ b/checkman/mysql_open_files @@ -0,0 +1,21 @@ +title: Check for monitor mysql open_files +agents: linux +catalog: os/linux +license: GPL +distribution: +description: + This check will monitor mysql open_files raported to + setted open_files_limit value. The plugin must be copied + into /usr/lib/check_mk_agent/plugins folder and the + executable bit mus be set for this file. + Will return current open_files_limit and open_files + values. The check gets critical at 90 percent of + open_files_limit and warning at 80. + Both limits are definable in Wato under "Parameters for + Inventorized Checks", "Applications, Processes & Services". + +inventory: + One service will be created for each host running the plugin. + +perfdata: + Percent usage of open_files_limit value. diff --git a/checks/mysql_open_files b/checks/mysql_open_files new file mode 100644 index 0000000..073ad44 --- /dev/null +++ b/checks/mysql_open_files @@ -0,0 +1,47 @@ +#!/usr/bin/python +# SpearHead Systems george.mocanu@sphs.ro 2015 + +# EXAMPLE DATA FROM: +# fomat: "open_files" current_setted_value_of_open_files_limit current_value_of_open_files +# +#<<>> +#open_files 3000 2305 + +factory_settings["mysql_open_files_default_values"] = { + "levels": (80, 90), +} + +def inventory_mysql_open_files(info): + inventory = [] + for line in info: + checkName = line[0] + inventory.append( (checkName, {} ) ) + return inventory + + +def check_mysql_open_files(item, params, info): + if type(params) != dict: + params = { "levels": params } + warn, crit = params["levels"] + for line in info: + if line[0] == item: + open_files_limit = int(line[1]) + open_files = int(line[2]) + openPerc = int(((open_files*100)/open_files_limit)) + perfdata = [ ( "open_files", openPerc, warn, crit ) ] + if openPerc > crit: + return (2, "Open files use level: %d percents. %d files opened out of maximum %d cconfigured." %(openPerc, open_files, open_files_limit), perfdata) + elif openPerc > warn: + return (1, "Open files use level: %d percents. %d files opened out of maximum %d cconfigured." %(openPerc, open_files, open_files_limit), perfdata) + else: + return (0, "Open files use level: %d percents. %d files opened out of maximum %d cconfigured." %(openPerc, open_files, open_files_limit), perfdata) + return(3, "Plugin not running on host") + +check_info["mysql_open_files"] = { + "check_function" :check_mysql_open_files, + "inventory_function" :inventory_mysql_open_files, + "service_description" :"%s", + "default_levels_variable" :"mysql_open_files_default_values", + "has_perfdata" :True, + "group" :"mysql_open_files", +} diff --git a/info b/info new file mode 100644 index 0000000..263ea79 --- /dev/null +++ b/info @@ -0,0 +1,17 @@ +{'author': 'george.mocanu@sphs.ro', + 'description': 'Monitor mysql open_files', + 'download_url': 'https://github.com/spearheadsys/check_mk-mysql_open_files', + 'files': {'agents': ['plugins/mysql_open_files'], + 'checkman': ['mysql_open_files'], + 'checks': ['mysql_open_files'], + 'doc': [], + 'inventory': [], + 'notifications': [], + 'pnp-templates': [], + 'web': ['plugins/wato/mysql_open_files.py']}, + 'name': 'mysql_open_files', + 'num_files': 4, + 'title': 'Check for mysql open_files', + 'version': '1.0', + 'version.min_required': '1.2.6b5', + 'version.packaged': '1.2.6b5'} \ No newline at end of file diff --git a/mysql_open_files-1.0.mkp b/mysql_open_files-1.0.mkp new file mode 100644 index 0000000..857ece5 Binary files /dev/null and b/mysql_open_files-1.0.mkp differ diff --git a/web/plugins/wato/mysql_open_files.py b/web/plugins/wato/mysql_open_files.py new file mode 100644 index 0000000..0ca9ae1 --- /dev/null +++ b/web/plugins/wato/mysql_open_files.py @@ -0,0 +1,32 @@ +#!/usr/bin/python +# SpearHead Syste george.mocanu@sphs.ro 2015 + +register_check_parameters( + subgroup_applications, + "mysql_open_files", + _("Mysql Open Files Usage Status"), + Dictionary( + elements = [ + ("levels", # Name of your parameters + Tuple( + title = "Levels for Mysql Open Files Usage check", # Specify a title for this parameters + elements = [ + Integer( + title = _("Warning if above"), + unit = _("Percent"), + default_value = 80 + ), + Integer( + title = _("Critical if above"), + unit = _("Percent"), + default_value = 90 + ), + ] + ) + ), + ], + optional_keys = None, # Always show this subgroup + ), + TextAscii( title = "Service name"), + "dict" +)