Merge "Add Python collectd plugin to check memcached availability"

This commit is contained in:
Jenkins
2016-08-26 13:21:26 +00:00
committed by Gerrit Code Review
4 changed files with 100 additions and 3 deletions

View File

@@ -657,12 +657,15 @@ to get statistics from RabbitMQ.
#### Class: `lma_collector::collectd::memcached`
Declare this class to configure collectd to collect Memcached statistics.
collectd's native `memcached` plugin is used.
collectd's native `memcached` plugin is used to collect statistics and a
custom Python plugin is used to check the availability of Memcached server.
##### Parameters
* `host`: *Required*. The Memcached host. Valid options: a string. See
https://github.com/voxpupuli/puppet-collectd#class-collectdpluginmemcached.
* `Port`: *Optional. The Memcached port. Valid option: an integer.
Default: `11211`.
#### Class: `lma_collector::collectd::openstack_checks`

View File

@@ -0,0 +1,76 @@
#!/usr/bin/python
# Copyright 2016 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import collectd
import collectd_base as base
from pymemcache.client import base as memcache
NAME = 'memcached'
class MemcachedCheckPlugin(base.Base):
def __init__(self, *args, **kwargs):
super(MemcachedCheckPlugin, self).__init__(*args, **kwargs)
self.plugin = NAME
self.host = None
self.port = 11211
def config_callback(self, conf):
super(MemcachedCheckPlugin, self).config_callback(conf)
for node in conf.children:
if node.key == 'Host':
self.host = node.values[0]
if node.key == 'Port':
# Must coerce to integer to avoid getting a float value.
self.port = int(node.values[0])
if self.host is None:
self.logger.error('Missing Host parameter')
def read_callback(self):
try:
mc = memcache.Client((self.host, self.port))
mc.get('__get_non_existent_key__')
self.dispatch_check_metric(self.OK)
except Exception as e:
msg = 'Fail to query memcached ({}:{}): {}'.format(self.host,
self.port,
e)
self.logger.error(msg)
self.dispatch_check_metric(self.FAIL, msg)
plugin = MemcachedCheckPlugin(collectd)
def init_callback():
plugin.restore_sigchld()
def config_callback(conf):
plugin.config_callback(conf)
def read_callback():
plugin.read_callback()
collectd.register_init(init_callback)
collectd.register_config(config_callback)
collectd.register_read(read_callback)

View File

@@ -15,10 +15,21 @@
class lma_collector::collectd::memcached (
$host,
$port = 11211,
) {
validate_integer($port)
class { 'collectd::plugin::memcached':
host => $host,
port => $port,
}
lma_collector::collectd::python { 'collectd_memcached_check':
config => {
'Host' => "\"${host}\"",
'Port' => "\"${port}\"",
},
}
}

View File

@@ -21,7 +21,14 @@ describe 'lma_collector::collectd::memcached' do
describe 'with host param' do
let(:params) {{:host => 'example.com' }}
it { is_expected.to contain_class('collectd::plugin::memcached') \
.with_host('example.com') }
it {
is_expected.to contain_class('collectd::plugin::memcached') \
.with_host('example.com')
is_expected.to contain_lma_collector__collectd__python('collectd_memcached_check') \
.with_config({
"Host" => '"example.com"',
"Port" => '"11211"',
})
}
end
end