Add local API check

This patch creates new plugin check_local_endpoint.py to check openstack
service locally and emits a new metric openstack_check_local_api.

Change-Id: I58290dd685b97354137ad5c0b91aece79fd91695
This commit is contained in:
Guillaume Thouvenin 2016-09-13 15:49:56 +02:00
parent 7cf60c3c33
commit c5eebea265
5 changed files with 137 additions and 1 deletions

View File

@ -237,7 +237,40 @@ if hiera('lma::collector::influxdb::server', false) {
require => Class['lma_collector::collectd::base'],
}
# VIP checks
# Check local endpoint
$cinder_api = get_network_role_property('cinder/api', 'ipaddr')
$glance_api = get_network_role_property('glance/api', 'ipaddr')
$heat_api = get_network_role_property('heat/api', 'ipaddr')
$keystone_api = get_network_role_property('keystone/api', 'ipaddr')
$neutron_api = get_network_role_property('neutron/api', 'ipaddr')
$nova_api = get_network_role_property('nova/api', 'ipaddr')
$swift_api = get_network_role_property('swift/api', 'ipaddr')
class { 'lma_collector::collectd::check_local_endpoint':
urls => {
'cinder-api' => "http://${cinder_api}:8776",
'glance-api' => "http://${glance_api}:9292",
'heat-api' => "http://${heat_api}:8004",
'heat-cfn-api' => "http://${heat_api}:8000",
'keystone-public-api' => "http://${keystone_api}:5000",
'neutron-api' => "http://${neutron_api}:9696",
'nova-api' => "http://${nova_api}:8774",
'swift-api' => "http://${swift_api}:8080/info",
},
expected_codes => {
'cinder-api' => 300,
'glance-api' => 300,
'heat-api' => 300,
'heat-cfn-api' => 300,
'keystone-public-api' => 300,
'neutron-api' => 200,
'nova-api' => 200,
'swift-api' => 200,
},
timeout => 1,
max_retries => 3,
require => Class['lma_collector::collectd::base'],
}
$influxdb_server = hiera('lma::collector::influxdb::server')
$influxdb_port = hiera('lma::collector::influxdb::port')
class { 'lma_collector::collectd::http_check':

View File

@ -0,0 +1,47 @@
#!/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 http_check
NAME = 'check_local_endpoint'
class CheckLocalEndpoint(http_check.HTTPCheckPlugin):
def __init__(self, *args, **kwargs):
super(CheckLocalEndpoint, self).__init__(*args, **kwargs)
self.plugin = NAME
plugin = CheckLocalEndpoint(collectd)
def config_callback(conf):
plugin.config_callback(conf)
def notification_callback(notification):
plugin.notification_callback(notification)
def read_callback():
plugin.conditional_read_callback()
collectd.register_config(config_callback)
collectd.register_notification(notification_callback)
collectd.register_read(read_callback, base.INTERVAL)

View File

@ -415,6 +415,10 @@ function process_message ()
msg['Fields']['name'] = metric_source
msg['Fields']['service'] = sample['type_instance']
table.insert(msg['Fields']['tag_fields'], 'service')
elseif metric_source == 'check_local_endpoint' then
msg['Fields']['name'] = 'openstack_check_local_api'
msg['Fields']['service'] = sample['type_instance']
table.insert(msg['Fields']['tag_fields'], 'service')
else
msg['Fields']['name'] = replace_dot_by_sep(metric_name)
end

View File

@ -0,0 +1,47 @@
# 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.
#
class lma_collector::collectd::check_local_endpoint (
$urls,
$expected_codes = {},
$timeout = 1,
$max_retries = 3,
) {
validate_hash($urls)
validate_hash($expected_codes)
validate_integer($timeout)
validate_integer($max_retries)
# Add quotes around the hash keys and values
$urls_keys = suffix(prefix(keys($urls), '"'), '"')
$urls_values = suffix(prefix(values($urls), '"'), '"')
$real_urls= hash(flatten(zip($urls_keys, $urls_values)))
if ! empty($expected_codes) {
$expected_codes_keys = suffix(prefix(keys($expected_codes), '"'), '"')
$expected_codes_values = suffix(prefix(values($expected_codes), '"'), '"')
$real_expected_codes= hash(flatten(zip($expected_codes_keys, $expected_codes_values)))
} else {
$real_expected_codes= {}
}
lma_collector::collectd::python { 'check_local_endpoint':
config => {
'Url' => $real_urls,
'ExpectedCode' => $real_expected_codes,
'Timeout' => "\"${timeout}\"",
'MaxRetries' => "\"${max_retries}\"",
},
}
}

View File

@ -9,6 +9,11 @@ Service API checks
The metric contains a ``service`` field that identifies
the OpenStack service being checked.
* ``openstack_check_local_api``, the service's API status checked locally. ``1``
if it is responsive, if not, then ``0``. The metric contains a ``service``
field that identifies ``<service>`` identifies the OpenStack service being
checked.
``<service>`` is one of the following values with their respective resource
checks: