monasca-api  4.0.0
About: OpenStack Monasca API is a RESTful API server that is designed with a layered architecture and supports Monitoring as a Service (MONaaS).
The "Ussuri" series (maintained release).
  Fossies Dox: monasca-api-4.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

healthchecks.py
Go to the documentation of this file.
1 # Copyright 2017 FUJITSU LIMITED
2 # Copyright 2018 OP5 AB
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15 
16 import falcon
17 
18 from monasca_api.api import healthcheck_api
19 from monasca_api.healthcheck import alarms_db_check
20 from monasca_api.healthcheck import kafka_check
21 from monasca_api.healthcheck import metrics_db_check
22 from monasca_api.v2.reference import helpers
23 
24 
25 class HealthChecks(healthcheck_api.HealthCheckApi):
26  CACHE_CONTROL = ['must-revalidate', 'no-cache', 'no-store']
27 
28  HEALTHY_CODE_GET = falcon.HTTP_OK
29  HEALTHY_CODE_HEAD = falcon.HTTP_NO_CONTENT
30  NOT_HEALTHY_CODE = falcon.HTTP_SERVICE_UNAVAILABLE
31 
32  def __init__(self):
33  super(HealthChecks, self).__init__()
34  self._kafka_check = kafka_check.KafkaHealthCheck()
35  self._alarm_db_check = alarms_db_check.AlarmsDbHealthCheck()
36  self._metrics_db_check = metrics_db_check.MetricsDbCheck()
37 
38  def on_head(self, req, res):
39  res.status = self.HEALTHY_CODE_HEAD
40  res.cache_control = self.CACHE_CONTROL
41 
42  def on_get(self, req, res):
43  helpers.validate_authorization(req, ['api:healthcheck'])
44  kafka_result = self._kafka_check.health_check()
45  alarms_db_result = self._alarm_db_check.health_check()
46  metrics_db_result = self._metrics_db_check.health_check()
47 
48  status_data = {
49  'kafka': kafka_result.message,
50  'alarms_database': alarms_db_result.message,
51  'metrics_database': metrics_db_result.message
52  }
53  health = (kafka_result.healthy and alarms_db_result.healthy and
54  metrics_db_result.healthy)
55  res.status = (self.HEALTHY_CODE_GET
56  if health else self.NOT_HEALTHY_CODE)
57  res.cache_control = self.CACHE_CONTROL
58  res.body = helpers.to_json(status_data)
monasca_api.healthchecks.HealthChecks.on_get
def on_get(self, req, res)
Definition: healthchecks.py:42
health_check
Definition: health_check.py:1
monasca_api.healthchecks.HealthChecks.HEALTHY_CODE_HEAD
HEALTHY_CODE_HEAD
Definition: healthchecks.py:29
monasca_api.healthchecks.HealthChecks.CACHE_CONTROL
list CACHE_CONTROL
Definition: healthchecks.py:26
monasca_api.healthchecks.HealthChecks
Definition: healthchecks.py:25
monasca_api.api
Definition: __init__.py:1
monasca_api.healthchecks.HealthChecks._metrics_db_check
_metrics_db_check
Definition: healthchecks.py:36
monasca_api.healthchecks.HealthChecks.on_head
def on_head(self, req, res)
Definition: healthchecks.py:38
monasca_api.healthchecks.HealthChecks.NOT_HEALTHY_CODE
NOT_HEALTHY_CODE
Definition: healthchecks.py:30
monasca_api.v2.reference
Definition: __init__.py:1
monasca_api.healthcheck
Definition: __init__.py:1
monasca_api.healthchecks.HealthChecks._alarm_db_check
_alarm_db_check
Definition: healthchecks.py:35
monasca_api.healthchecks.HealthChecks.__init__
def __init__(self)
Definition: healthchecks.py:32
monasca_api.healthchecks.HealthChecks._kafka_check
_kafka_check
Definition: healthchecks.py:34
monasca_api.healthchecks.HealthChecks.HEALTHY_CODE_GET
HEALTHY_CODE_GET
Definition: healthchecks.py:28