Files
libra/libra/common/lbstats.py
David Shrewsbury eef66c4128 [WORKER] Return node status in STATS message
The message returned to the statsd daemon will now contain a
list of all nodes defined in the haproxy.cfg file and their status.
Status is currently as reported from HAProxy (UP/DOWN/no check/etc.)

Fields added to the returned JSON response:

 "nodes": [ { "id": "1234", "status": "UP" } ]

The 'id' part of the JSON response will contain either the unique
ID of the node (as defined during the UPDATE message), or "serverN"
for older configs that haven't been updated to use the node ID.

Change-Id: I794b4901f542d922ebccd9ece9d86236584d4b46
2013-07-24 14:46:53 -04:00

65 lines
2.0 KiB
Python

# Copyright 2012 Hewlett-Packard Development Company, L.P.
#
# 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 datetime
class LBStatistics(object):
""" Load balancer statistics class. """
def __init__(self):
self.stats = {}
self.bytes_out = 0L
self.bytes_in = 0L
self.nodes = dict()
self.utc_timestamp = datetime.datetime.utcnow()
@property
def bytes_out(self):
return self.stats['bytes_out']
@bytes_out.setter
def bytes_out(self, value):
if not isinstance(value, long):
raise TypeError("Must be a long integer: '%s'" % value)
self.stats['bytes_out'] = value
@property
def bytes_in(self):
return self.stats['bytes_in']
@bytes_in.setter
def bytes_in(self, value):
if not isinstance(value, long):
raise TypeError("Must be a long integer: '%s'" % value)
self.stats['bytes_in'] = value
@property
def utc_timestamp(self):
""" UTC timestamp for when these statistics are generated. """
return self._utc_ts
@utc_timestamp.setter
def utc_timestamp(self, value):
if not isinstance(value, datetime.datetime):
raise TypeError("Must be a datetime.datetime: '%s'" % value)
self._utc_ts = value
def add_node_status(self, node, status):
self.nodes[node] = status
def node_status_map(self):
""" Return a dictionary, indexed by node ID, of the node status """
return self.nodes