Skip to content

Commit

Permalink
Force-flush our output after each collection cycle.
Browse files Browse the repository at this point in the history
Signed-off-by: Vasiliy Kiryanov <vasiliy.kiryanov@gmail.com>
  • Loading branch information
tsuna authored and vasiliyk committed Apr 14, 2015
1 parent 8b75558 commit e897900
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions collectors/0/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import eossdk
except ImportError:
eossdk = None

import sys
import time

Expand All @@ -27,7 +27,7 @@ class IntfCounterCollector(eossdk.AgentHandler,
intf_types = frozenset([eossdk.INTF_TYPE_ETH,
eossdk.INTF_TYPE_MANAGEMENT,
eossdk.INTF_TYPE_LAG])

def __init__(self, agent_mgr, timeout_mgr, intf_mgr,
intf_counter_mgr, eth_phy_intf_counter_mgr):
self.intf_mgr_ = intf_mgr
Expand All @@ -36,7 +36,7 @@ def __init__(self, agent_mgr, timeout_mgr, intf_mgr,
self.interval_ = 30
eossdk.AgentHandler.__init__(self, agent_mgr)
eossdk.TimeoutHandler.__init__(self, timeout_mgr)

def on_initialized(self):
# Schedule ourselves to run immediately
self.timeout_time_is(eossdk.now())
Expand All @@ -45,14 +45,15 @@ def on_timeout(self):
for intf_id in self.intf_mgr_.intf_iter():
if intf_id.intf_type() in self.intf_types:
self.printIntfCounters(intf_id)
sys.stdout.flush()
self.timeout_time_is(eossdk.now() + self.interval_)

def printIntfCounters(self, intf_id):
ts = int(time.time())

self.intf_counter_mgr_.counters(intf_id)
intf_counters = self.intf_counter_mgr_.counters(intf_id)
counters = [
counters = [
("ucastPkts", {"direction" : "out"},
intf_counters.out_ucast_pkts()),
("multicastPkts", {"direction" : "out"},
Expand Down Expand Up @@ -123,7 +124,7 @@ def printIntfCounters(self, intf_id):
]
for counter, tags, value in eth_counters:
self.printIntfCounter(counter, ts, value, intf_id, tags)

eth_intf_bin_counters = self.eth_phy_intf_counter_mgr_.bin_counters(intf_id)
eth_bin_counters = [
("frameBySize", {"size" : "64", "direction" : "in"},
Expand Down Expand Up @@ -157,19 +158,19 @@ def printIntfCounters(self, intf_id):
]
for counter, tags, value in eth_bin_counters:
self.printIntfCounter(counter, ts, value, intf_id, tags)

def printIntfCounter(self, counter, ts, value, intf_id, tags):
tag_str = " ".join(["%s=%s" % (tag_name, tag_value) for
(tag_name, tag_value) in tags.items()])
print ("eos.interface.%s %d %d iface=%s %s"
sys.stdout.write("eos.interface.%s %d %d iface=%s %s\n"
% (counter, ts, value, intf_id.to_string(), tag_str))


def main():
if eossdk == None:
# This collector requires the eossdk module
return 13 # Ask tcollector to not respawn us

sdk = eossdk.Sdk("tcollector-eos")

# Create the state managers we're going to poll. For now,
Expand All @@ -186,7 +187,7 @@ def main():
intf_mgr,
intf_counter_mgr,
eth_phy_intf_counter_mgr)

# Start the main loop
sdk.main_loop(sys.argv)

Expand Down

0 comments on commit e897900

Please sign in to comment.