Skip to content

Commit

Permalink
Give the meta stats a host tag, fixes OpenTSDB#126.
Browse files Browse the repository at this point in the history
Signed-off-by: Vasiliy Kiryanov <[email protected]>
  • Loading branch information
mikebryant authored and vasiliyk committed Jan 17, 2014
1 parent 03b16ed commit 316303a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tcollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def __init__(self, dedupinterval, evictinterval, default_host_tag):
combination of (metric, tags). Values older than
evictinterval will be removed from the cache to save RAM.
Invariant: evictinterval > dedupinterval
default_host_tag: The default host tag to be added if the host tag
default_host_tag: The default host tag to be added if the host tag
is not present.
"""
assert evictinterval > dedupinterval, "%r <= %r" % (evictinterval,
Expand Down Expand Up @@ -408,7 +408,7 @@ class SenderThread(threading.Thread):
buffering we might need to do if we can't establish a connection
and we need to spool to disk. That isn't implemented yet."""

def __init__(self, reader, dryrun, hosts, self_report_stats, tags):
def __init__(self, reader, dryrun, hosts, self_report_stats, tags, default_host_tag):
"""Constructor.
Args:
Expand Down Expand Up @@ -437,6 +437,7 @@ def __init__(self, reader, dryrun, hosts, self_report_stats, tags):
self.last_verify = 0
self.sendq = []
self.self_report_stats = self_report_stats
self.default_host_tag = default_host_tag

def pick_connection(self):
"""Picks up a random host/port connection."""
Expand Down Expand Up @@ -575,8 +576,8 @@ def verify_conn(self):
+ col.name, col.lines_invalid))

ts = int(time.time())
strout = ["tcollector.%s %d %d %s"
% (x[0], ts, x[2], x[1]) for x in strs]
strout = ["tcollector.%s %d %d host=%s %s"
% (x[0], ts, x[2], self.default_host_tag, x[1]) for x in strs]
for string in strout:
self.sendq.append(string)

Expand Down Expand Up @@ -654,7 +655,7 @@ def send_data(self):
LOG.debug('SENDING: %s', line)
else:
out = "".join("put %s%s\n" % (line, self.tagstr) for line in self.sendq)

if not out:
LOG.debug('send_data no data?')
return
Expand Down Expand Up @@ -883,7 +884,7 @@ def splitHost(hostport):

# and setup the sender to start writing out to the tsd
sender = SenderThread(reader, options.dryrun, options.hosts,
not options.no_tcollector_stats, tagstr)
not options.no_tcollector_stats, tagstr, default_host_tag)
sender.start()
LOG.info('SenderThread startup complete')

Expand Down Expand Up @@ -1148,7 +1149,7 @@ def check_children():
col.shutdown()
register_collector(Collector(col.name, col.interval, col.filename,
col.mtime, col.lastspawn))


def set_nonblocking(fd):
"""Sets the given file descriptor to non-blocking mode."""
Expand Down

0 comments on commit 316303a

Please sign in to comment.