expvar enable/disable

This commit is contained in:
Alexey Lavrenuke 2017-04-05 20:54:04 +03:00
parent 4293e79d2c
commit 47e6a36e3d
3 changed files with 17 additions and 2 deletions

View File

@ -694,6 +694,9 @@ Disable phantom first (unless you really want to keep it active alongside at you
; Pandora executable path
pandora_cmd=/usr/bin/pandora
; Enable/disable expvar monitoring
expvar = 1 ; default
; Pandora config contents (json)
config_content = {
"pools": [

View File

@ -30,6 +30,7 @@ class Plugin(AbstractPlugin, GeneratorPlugin):
self.process_start_time = None
self.custom_config = False
self.sample_log = "./phout.log"
self.expvar = True
@staticmethod
def get_key():
@ -39,10 +40,12 @@ class Plugin(AbstractPlugin, GeneratorPlugin):
opts = [
"pandora_cmd", "buffered_seconds",
"config_content", "config_file",
"expvar"
]
return opts
def configure(self):
self.expvar = self.get_option("expvar", "1") == "1"
self.pandora_cmd = self.get_option("pandora_cmd", "pandora")
self.buffered_seconds = int(
self.get_option("buffered_seconds", self.buffered_seconds))
@ -82,7 +85,7 @@ class Plugin(AbstractPlugin, GeneratorPlugin):
"Linking sample and stats readers to aggregator. Reading samples from %s",
self.sample_log)
aggregator.reader = PhantomReader(self.sample_log)
aggregator.stats_reader = PandoraStatsReader()
aggregator.stats_reader = PandoraStatsReader(self.expvar)
try:
console = self.core.get_plugin_of_type(ConsolePlugin)

View File

@ -7,12 +7,21 @@ logger = logging.getLogger(__name__)
class PandoraStatsReader(object):
# TODO: maybe make stats collection asyncronous
def __init__(self):
def __init__(self, expvar):
self.closed = False
self.expvar = expvar
def next(self):
if self.closed:
raise StopIteration()
if not self.expvar:
return [{
'ts': int(time.time() - 1),
'metrics': {
'instances': 0,
'reqps': 0
}
}]
try:
pandora_response = requests.get("http://localhost:1234/debug/vars")
pandora_stat = pandora_response.json()