Commit db742ff0 authored by Alejandro Alvarez Ayllon's avatar Alejandro Alvarez Ayllon
Browse files

FTS-661: Monitor fts-rest

parent 9ee41c1d
Pipeline #144135 passed with stage
in 14 seconds
......@@ -231,6 +231,7 @@ EOF
%{python_sitelib}/fts3rest/lib/app_globals.py*
%{python_sitelib}/fts3rest/lib/base.py*
%{python_sitelib}/fts3rest/lib/gfal2_wrapper.py*
%{python_sitelib}/fts3rest/lib/heartbeat.py*
%{python_sitelib}/fts3rest/lib/helpers/
%{python_sitelib}/fts3rest/lib/http_exceptions.py*
%{python_sitelib}/fts3rest/lib/__init__.py*
......
......@@ -11,6 +11,7 @@ AuthorizedVO=dteam;*
CleanRecordsHost=false
MessagingDirectory=/tmp/rest-msgs
HeartBeatInterval=0
[roles]
Public=vo:transfer;all:datamanagement
......
......@@ -25,6 +25,7 @@ from pylons.middleware import ErrorHandler
from pylons.wsgiapp import PylonsApp
from routes.middleware import RoutesMiddleware
from fts3rest.lib.heartbeat import Heartbeat
from fts3rest.lib.middleware.fts3auth import FTS3AuthMiddleware
from fts3rest.lib.middleware.error_as_json import ErrorAsJson
from fts3rest.lib.middleware.request_logger import RequestLogger
......@@ -90,4 +91,8 @@ def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
static_app = StaticURLParser(config['pylons.paths']['static_files'])
app = Cascade([static_app, app])
app.config = config
# Heartbeat thread
Heartbeat('fts_rest', int(config.get('fts3.HeartBeatInterval', 60))).start()
return app
# Copyright notice:
# Copyright CERN, 2017
#
# 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 logging
import socket
import time
from datetime import datetime
from threading import Thread
from fts3.model import Host
from fts3rest.lib.base import Session
log = logging.getLogger(__name__)
class Heartbeat(Thread):
"""
Keeps running on the background updating the db marking the process as alive
"""
def __init__(self, tag, interval):
"""
Constructor
"""
Thread.__init__(self)
self.tag = tag
self.interval = interval
self.daemon = True
def run(self):
"""
Thread logic
"""
host = Host(
hostname=socket.getfqdn(),
service_name=self.tag,
)
while self.interval:
host.beat = datetime.utcnow()
try:
Session.merge(host)
Session.commit()
log.debug('Hearbeat')
except Exception, e:
log.warning("Failed to update the heartbeat: %s" % str(e))
time.sleep(self.interval)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment