Skip to content

Commit

Permalink
Merge pull request #331 from DataDog/add-hostnames-status
Browse files Browse the repository at this point in the history
Added hostnames to status info fixes #314
  • Loading branch information
conorbranagan committed Jan 9, 2013
2 parents d650455 + 9472b43 commit bed21c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 23 additions & 3 deletions checks/check_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,33 @@ class CollectorStatus(AgentStatus):

NAME = 'Collector'

def __init__(self, check_statuses=None, emitter_statuses=None):
def __init__(self, check_statuses=None, emitter_statuses=None, metadata=None):
AgentStatus.__init__(self)
self.check_statuses = check_statuses or []
self.emitter_statuses = emitter_statuses or []
if metadata is not None:
self.metadata = ','.join(k + ':' + v for (k,v) in metadata.items())
else:
self.metadata = []

def body_lines(self):
# Checks.d Status
# Hostnames
lines = [
'Hostnames',
'=========',
''
]
if not self.metadata:
lines.append(" No host information available yet.")
else:
host_info = dict(item.split(":") for item in self.metadata.split(","))
for key, host in host_info.items():
lines.append(" " + key + ": " + host)

lines.append('')

# Checks.d Status
lines += [
'Checks',
'======',
''
Expand Down Expand Up @@ -276,7 +295,8 @@ def body_lines(self):
lines += [
"",
"Emitters",
"========"
"========",
""
]
if not self.emitter_statuses:
lines.append(" No emitters have run yet.")
Expand Down
4 changes: 3 additions & 1 deletion checks/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self, agentConfig, emitters, systemStats):
socket.setdefaulttimeout(15)
self.run_count = 0
self.continue_running = True
self.metadata_cache = None

# Unix System Checks
self._unix_system_checks = {
Expand Down Expand Up @@ -319,7 +320,7 @@ def run(self, checksd=None):

# Persist the status of the collection run.
try:
CollectorStatus(check_statuses, emitter_statuses).persist()
CollectorStatus(check_statuses, emitter_statuses, self.metadata_cache).persist()
except Exception:
logger.exception("Error persisting collector status")

Expand Down Expand Up @@ -378,6 +379,7 @@ def _build_payload(self):
# Periodically send the host metadata.
if self._is_first_run() or self._should_send_metadata():
payload['meta'] = self._get_metadata()
self.metadata_cache = payload['meta']
# Add static tags from the configuration file
if self.agentConfig['tags'] is not None:
payload['tags'] = self.agentConfig['tags']
Expand Down

0 comments on commit bed21c5

Please sign in to comment.