Fixes to make statsd actually work
Change-Id: I10f46507ce452e9a9c8352019c008d3698a341d7
This commit is contained in:
parent
1206a22c5c
commit
184fe83639
@ -18,6 +18,10 @@ import sys
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class APIError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AdminAPI(object):
|
class AdminAPI(object):
|
||||||
def __init__(self, addresses, logger):
|
def __init__(self, addresses, logger):
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
@ -42,7 +46,9 @@ class AdminAPI(object):
|
|||||||
limit = 20
|
limit = 20
|
||||||
lb_list = []
|
lb_list = []
|
||||||
while True:
|
while True:
|
||||||
nodes = self._get_node_list(limit, marker)
|
success, nodes = self._get_node_list(limit, marker)
|
||||||
|
if not success:
|
||||||
|
raise APIError
|
||||||
# if we hit an empty device list we have hit end of list
|
# if we hit an empty device list we have hit end of list
|
||||||
if not len(nodes['devices']):
|
if not len(nodes['devices']):
|
||||||
break
|
break
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import gearman
|
|
||||||
|
|
||||||
from libra.common.json_gearman import JSONGearmanClient
|
from libra.common.json_gearman import JSONGearmanClient
|
||||||
|
|
||||||
|
|
||||||
@ -27,23 +25,23 @@ class GearJobs(object):
|
|||||||
failed_list = []
|
failed_list = []
|
||||||
job_data = {"hpcs_action": "STATS"}
|
job_data = {"hpcs_action": "STATS"}
|
||||||
for node in node_list:
|
for node in node_list:
|
||||||
list_of_jobs.append(dict(task=node, data=job_data))
|
list_of_jobs.append(dict(task=str(node), data=job_data))
|
||||||
submitted_pings = self.gm_client.submit_multiple_jobs(
|
submitted_pings = self.gm_client.submit_multiple_jobs(
|
||||||
list_of_jobs, background=False, wait_until_complete=True,
|
list_of_jobs, background=False, wait_until_complete=True,
|
||||||
poll_timeout=5.0
|
poll_timeout=5.0
|
||||||
)
|
)
|
||||||
for ping in submitted_pings:
|
for ping in submitted_pings:
|
||||||
if ping.state == gearman.JOB_UNKNOWN:
|
if ping.state == 'UNKNOWN':
|
||||||
# TODO: Gearman server failed, ignoring for now
|
# TODO: Gearman server failed, ignoring for now
|
||||||
self.logger.error('Gearman Job server fail')
|
self.logger.error('Gearman Job server fail')
|
||||||
continue
|
continue
|
||||||
if ping.timed_out:
|
if ping.timed_out:
|
||||||
# Ping timeout
|
# Ping timeout
|
||||||
failed_list.append(ping['task'])
|
failed_list.append(ping.job.task)
|
||||||
continue
|
continue
|
||||||
if ping.result['hpcs_response'] == 'FAIL':
|
if ping.result['hpcs_response'] == 'FAIL':
|
||||||
# Error returned by Gearman
|
# Error returned by Gearman
|
||||||
failed_list.append(ping['task'])
|
failed_list.append(ping.job.task)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return failed_list
|
return failed_list
|
||||||
|
@ -82,7 +82,7 @@ class Sched(object):
|
|||||||
failed_nodes = gearman.send_pings(node_list)
|
failed_nodes = gearman.send_pings(node_list)
|
||||||
failed = len(failed_nodes)
|
failed = len(failed_nodes)
|
||||||
if failed > 0:
|
if failed > 0:
|
||||||
self._send_fails(lb_list, failed_nodes, lb_list)
|
self._send_fails(failed_nodes, lb_list)
|
||||||
else:
|
else:
|
||||||
self.logger.error('No working API server found')
|
self.logger.error('No working API server found')
|
||||||
return (0, 0)
|
return (0, 0)
|
||||||
@ -95,14 +95,15 @@ class Sched(object):
|
|||||||
message = (
|
message = (
|
||||||
'Load balancer failed\n'
|
'Load balancer failed\n'
|
||||||
'ID: {0}\n'
|
'ID: {0}\n'
|
||||||
'IP: (1}\n'
|
'IP: {1}\n'
|
||||||
'tenant: {2}\n'.format(
|
'tenant: {2}\n'.format(
|
||||||
data['id'], data['floatingIPAddr'],
|
data['id'], data['floatingIpAddr'],
|
||||||
data['loadBalancers'][0]['hpcs_tenantid']
|
data['loadBalancers'][0]['hpcs_tenantid']
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for driver in self.drivers:
|
for driver in self.drivers:
|
||||||
driver.send_alert(message, data['id'])
|
instance = driver(self.logger)
|
||||||
|
instance.send_alert(message, data['id'])
|
||||||
|
|
||||||
def _get_node(self, node, node_list):
|
def _get_node(self, node, node_list):
|
||||||
for n in node_list:
|
for n in node_list:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user