Skip to content

Commit

Permalink
Fix stats collector
Browse files Browse the repository at this point in the history
  • Loading branch information
Shay Arbov committed Dec 31, 2017
1 parent fafb9b5 commit 77e525d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile.internal
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ flake8:

pylint:
mkdir -p build/
PYLINTHOME=reports/ pylint -r n docker_test_tools
PYLINTHOME=reports/ pylint -d W0612 -r n docker_test_tools

test:
# Run the unittests and create a junit-xml report
Expand Down
12 changes: 8 additions & 4 deletions docker_test_tools/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def stop(self):

if self.stats_file:
self.stats_file.close()
with open(self.stats_summary_path, 'a') as target:
with open(self.stats_summary_path, 'w') as target:
cluster_stats = ClusterStats(stat_file_path=self.stats_file_path, encoding=self.encoding).to_dict()
json.dump(cluster_stats, target, sort_keys=True, indent=2)

Expand Down Expand Up @@ -147,7 +147,7 @@ def parse_line(self, line):

# Handle bad stats metrics
for key, val in components.items():
if val == '--':
if '--' in val:
components[key] = 0

# Skip bad stats metrics
Expand All @@ -156,8 +156,9 @@ def parse_line(self, line):

name = components['name']

# Get the used CPU percentage as a floating number
components['cpu'] = float(components['cpu'][:-1])
if not isinstance(components['cpu'], int):
# Get the used CPU percentage as a floating number
components['cpu'] = float(components['cpu'][:-1])

# Get the used stats numbers as used bytes number
components['ram'] = self.get_bytes(components['ram'])
Expand All @@ -179,6 +180,9 @@ def parse_line(self, line):
@staticmethod
def get_bytes(raw_value):
"""Get the number as used bytes number"""
if isinstance(raw_value, int):
return raw_value

return humanfriendly.parse_size(raw_value.split('/')[0], binary=True)

def __str__(self):
Expand Down

0 comments on commit 77e525d

Please sign in to comment.