libra/libra/worker/stats_client.py
David Shrewsbury 3ec02bcdb1 Start of obtaining worker stats.
The worker now gets the bytes-in/bytes-out for the specified
protocol (http or tcp). For now, these values are only logged,
and then only in debug mode. Added a test for setting these
values in the new LBStatistics class.

Updated README for the 'socat' requirement and to mention that
the PID file directory must be writable by the user.

Change-Id: I79f218747255cba84b25c4a69d0b210c9d1dfee5
2012-11-12 16:51:57 -05:00

39 lines
1.4 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 eventlet
def stats_manager(logger, driver, stats_poll):
logger.debug("[stats] Statistics gathering process started.")
logger.debug("[stats] Polling interval: %d" % stats_poll)
while True:
try:
http_stats = driver.get_stats('http')
tcp_stats = driver.get_stats('tcp')
except NotImplementedError:
logger.warn(
"[stats] Driver does not implement statisics gathering."
)
break
logger.debug("[stats] HTTP bytes in/out: (%d, %d)" %
(http_stats.bytes_in, http_stats.bytes_out))
logger.debug("[stats] TCP bytes in/out: (%d, %d)" %
(tcp_stats.bytes_in, tcp_stats.bytes_out))
eventlet.sleep(stats_poll)
logger.info("[stats] Statistics gathering process terminated.")