Add support to check Apache

This patch adds the collectd plugin to check Apache and it also adds
a new alarm.

Change-Id: I70dc85dae2de7e7afa1d2a046c96071d242a60b1
This commit is contained in:
Guillaume Thouvenin
2016-08-30 17:47:28 +02:00
parent 1c90e3eea1
commit 20e6fbaab2
6 changed files with 98 additions and 6 deletions

View File

@@ -330,6 +330,18 @@ lma_collector:
window: 60
periods: 0
function: min
- name: 'apache-check'
description: 'Apache cannot be checked'
severity: 'down'
enabled: 'true'
trigger:
rules:
- metric: apache_check
relational_operator: '=='
threshold: 0
window: 60
periods: 0
function: last
- name: 'log-fs-warning'
description: "The log filesystem's free space is low"
severity: 'warning'
@@ -1136,6 +1148,7 @@ lma_collector:
check: ['mysql-check']
apache:
worker: ['apache-warning']
check: ['apache-check']
nova-api:
http_errors: ['nova-api-http-errors']
nova-logs:

View File

@@ -167,6 +167,7 @@ lma_collector:
group_by: hostname
members:
- worker
- check
memcached-service:
policy: majority_of_members
group_by: hostname

View File

@@ -0,0 +1,66 @@
#!/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
import requests
NAME = 'apache'
class ApacheCheckPlugin(base.Base):
def __init__(self, *args, **kwargs):
super(ApacheCheckPlugin, self).__init__(*args, **kwargs)
self.plugin = NAME
self.url = None
def config_callback(self, conf):
super(ApacheCheckPlugin, self).config_callback(conf)
for node in conf.children:
if node.key == 'Url':
self.url = node.values[0]
if self.url is None:
self.logger.error("{}: Missing Url parameter".format(NAME))
def read_callback(self):
try:
requests.get(self.url, timeout=5)
self.dispatch_check_metric(self.OK)
except Exception as err:
msg = "{}: Failed to check service: {}".format(NAME, err)
self.logger.error(msg)
self.dispatch_check_metric(self.FAIL, msg)
plugin = ApacheCheckPlugin(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

@@ -18,12 +18,19 @@ class lma_collector::collectd::apache (
$port = $lma_collector::params::apache_status_port,
) inherits lma_collector::params {
$apache_url = "http://${host}:${port}/server-status?auto"
class { 'collectd::plugin::apache':
instances => {
'localhost' => {
'url' => "http://${host}:${port}/server-status?auto"
'url' => $apache_url,
},
}
}
lma_collector::collectd::python {'collectd_apache_check':
config => {
'Url' => "\"${apache_url}\"",
},
}
}

View File

@@ -25,7 +25,11 @@ describe 'lma_collector::collectd::apache' do
describe 'with "host" and "port" param' do
let(:params) {{:host => 'example.com', :port => '8081'}}
it { is_expected.to contain_class('collectd::plugin::apache') \
.with_instances({'localhost' => {'url' => 'http://example.com:8081/server-status?auto'}}) }
it {
is_expected.to contain_class('collectd::plugin::apache') \
.with_instances({'localhost' => {'url' => 'http://example.com:8081/server-status?auto'}})
is_expected.to contain_lma_collector__collectd__python('collectd_apache_check') \
.with_config({'Url' => "\"http://example.com:8081/server-status?auto\""})
}
end
end