Skip to content

Commit a98388b

Browse files
authored
Merge branch 'master' into master
2 parents ea54709 + 60a2e3e commit a98388b

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

cloudwatchmon/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '2.0.4'
1+
VERSION = '2.0.5'

cloudwatchmon/cli/get_instance_stats.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
1919

20+
from __future__ import print_function
2021
from cloudwatchmon.cloud_watch_client import *
2122

2223
import argparse
@@ -76,17 +77,17 @@ def print_metric_stats(region, instance_id, namespace, metric, title,
7677
['Average', 'Maximum', 'Minimum'],
7778
dims)
7879

79-
print title
80+
print(title)
8081

8182
if metrics:
8283
max_val = max(m['Maximum'] for m in metrics)
8384
min_val = min(m['Minimum'] for m in metrics)
8485
avg_val = sum(m['Average'] for m in metrics) / float(len(metrics))
8586

86-
print " Average: {0:.2f}%, Minimum: {1:.2f}%, Maximum: {2:.2f}%\n" \
87-
.format(avg_val, min_val, max_val)
87+
print(" Average: {0:.2f}%, Minimum: {1:.2f}%, Maximum: {2:.2f}%\n"
88+
.format(avg_val, min_val, max_val))
8889
else:
89-
print " Average: N/A, Minimum: N/A, Maximum: N/A\n"
90+
print(" Average: N/A, Minimum: N/A, Maximum: N/A\n")
9091

9192

9293
def print_filesystem_stats(region, instance_id, namespace, metric, title,
@@ -117,21 +118,21 @@ def main():
117118
args = parser.parse_args()
118119

119120
if args.version:
120-
print CLIENT_NAME + ' version ' + VERSION
121+
print(CLIENT_NAME + ' version ' + VERSION)
121122
return 0
122123

123124
try:
124125
metadata = get_metadata()
125126

126127
if args.verbose:
127-
print 'Instance metadata: ' + str(metadata)
128+
print('Instance metadata: ' + str(metadata))
128129

129130
region = metadata['placement']['availability-zone'][:-1]
130131
instance_id = metadata['instance-id']
131132

132133
unit = 'hours' if args.recent_hours > 1 else 'hour'
133-
print 'Instance {0} statistics for the last {1} {2}.\n'\
134-
.format(instance_id, args.recent_hours, unit)
134+
print('Instance {0} statistics for the last {1} {2}.\n'
135+
.format(instance_id, args.recent_hours, unit))
135136

136137
print_metric_stats(region, instance_id,
137138
'AWS/EC2',

cloudwatchmon/cli/put_instance_stats.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
1919

20+
from __future__ import print_function
2021
from cloudwatchmon.cloud_watch_client import *
2122

2223
import argparse
@@ -183,7 +184,7 @@ def send(self, verbose):
183184

184185
size = len(self.names)
185186

186-
for idx_start in xrange(0, size, AWS_LIMIT_METRICS_SIZE):
187+
for idx_start in range(0, size, AWS_LIMIT_METRICS_SIZE):
187188
idx_end = idx_start + AWS_LIMIT_METRICS_SIZE
188189
response = conn.put_metric_data('System/Linux',
189190
self.names[idx_start:idx_end],
@@ -282,7 +283,6 @@ def config_parser():
282283
action='store_true',
283284
help='Report load averages for 1min, 5min and 15min divided by the number of CPU cores.')
284285

285-
286286
disk_group = parser.add_argument_group('disk metrics')
287287
disk_group.add_argument('--disk-path',
288288
metavar='PATH',
@@ -307,14 +307,12 @@ def config_parser():
307307
action='store_true',
308308
help='Reports disk inode utilization in percentages.')
309309

310-
311310
process_group = parser.add_argument_group('process metrics')
312311
process_group.add_argument('--process-name',
313312
metavar='PROCNAME',
314313
action='append',
315314
help='Report CPU and Memory utilization metrics of processes.')
316315

317-
318316
exclusive_group = parser.add_mutually_exclusive_group()
319317
exclusive_group.add_argument('--from-cron',
320318
action='store_true',
@@ -364,6 +362,7 @@ def add_memory_metrics(args, metrics):
364362
metrics.add_metric('SwapUsed', mem_unit_name,
365363
mem.swap_used() / mem_unit_div)
366364

365+
367366
def add_loadavg_metrics(args, metrics):
368367
loadavg = LoadAverage()
369368
if args.loadavg:
@@ -389,8 +388,8 @@ def get_disk_info(args):
389388
used = int(line[2]) * 1024
390389
avail = int(line[3]) * 1024
391390
disks.append(Disk(mount, file_system, total, used, avail, 0))
392-
393-
#Gather inode utilization if it is requested
391+
392+
# Gather inode utilization if it is requested
394393
if not args.disk_inode_util:
395394
return disks
396395

@@ -402,7 +401,7 @@ def get_disk_info(args):
402401
used = float(line[2])
403402
total = float(line[1])
404403
inode_util_val = 100.0 * used / total if total > 0 else 0
405-
disks_inode_util.append(inode_util_val)
404+
disks_inode_util.append(inode_util_val)
406405

407406
for index, disk in enumerate(disks):
408407
disk.inode_util = disks_inode_util[index]
@@ -428,7 +427,6 @@ def add_disk_metrics(args, metrics):
428427
if args.disk_inode_util:
429428
metrics.add_metric('InodeUtilization', 'Percent',
430429
disk.inode_util, disk.mount, disk.file_system)
431-
432430

433431
def add_process_metrics(args, metrics):
434432
process_names = args.process_name
@@ -452,7 +450,7 @@ def add_static_file_metrics(args, metrics):
452450
(label, unit, value) = [x.strip() for x in line.split(',')]
453451
metrics.add_metric(label, unit, value)
454452
except ValueError:
455-
print 'Ignore unparseable metric: "' + line + '"'
453+
print('Ignore unparseable metric: "' + line + '"')
456454
pass
457455

458456

@@ -496,8 +494,8 @@ def validate_args(args):
496494
raise ValueError('Metrics to report disk space are provided but '
497495
'disk path is not specified.')
498496

499-
if not report_mem_data and not report_disk_data and not args.from_file and \
500-
not report_loadavg_data:
497+
if not report_mem_data and not report_disk_data and \
498+
not args.from_file and not report_loadavg_data:
501499
raise ValueError('No metrics specified for collection and '
502500
'submission to CloudWatch.')
503501

@@ -515,24 +513,25 @@ def main():
515513
args = parser.parse_args()
516514

517515
if args.version:
518-
print CLIENT_NAME + ' version ' + VERSION
516+
print(CLIENT_NAME + ' version ' + VERSION)
519517
return 0
520518

521519
try:
522-
report_disk_data, report_mem_data, report_loadavg_data, report_process_data = validate_args(args)
520+
report_disk_data, report_mem_data, report_loadavg_data, report_process_data = \
521+
validate_args(args)
523522

524523
# avoid a storm of calls at the beginning of a minute
525524
if args.from_cron:
526525
time.sleep(random.randint(0, 19))
527526

528527
if args.verbose:
529-
print 'Working in verbose mode'
530-
print 'Boto-Version: ' + boto.__version__
528+
print('Working in verbose mode')
529+
print('Boto-Version: ' + boto.__version__)
531530

532531
metadata = get_metadata()
533532

534533
if args.verbose:
535-
print 'Instance metadata: ' + str(metadata)
534+
print('Instance metadata: ' + str(metadata))
536535

537536
region = metadata['placement']['availability-zone'][:-1]
538537
instance_id = metadata['instance-id']
@@ -543,7 +542,7 @@ def main():
543542
args.verbose)
544543

545544
if args.verbose:
546-
print 'Autoscaling group: ' + autoscaling_group_name
545+
print('Autoscaling group: ' + autoscaling_group_name)
547546

548547
metrics = Metrics(region,
549548
instance_id,
@@ -568,16 +567,16 @@ def main():
568567
add_process_metrics(args, metrics)
569568

570569
if args.verbose:
571-
print 'Request:\n' + str(metrics)
570+
print('Request:\n' + str(metrics))
572571

573572
if args.verify:
574573
if not args.from_cron:
575-
print 'Verification completed successfully. ' \
576-
'No actual metrics sent to CloudWatch.'
574+
print('Verification completed successfully. '
575+
'No actual metrics sent to CloudWatch.')
577576
else:
578577
metrics.send(args.verbose)
579578
if not args.from_cron:
580-
print 'Successfully reported metrics to CloudWatch.'
579+
print('Successfully reported metrics to CloudWatch.')
581580
except Exception as e:
582581
log_error(str(e), args.from_cron)
583582
return 1

cloudwatchmon/cloud_watch_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18+
from __future__ import print_function
1819
import boto
1920
import boto.utils
2021
import hashlib
@@ -56,7 +57,7 @@ def __call__(self, *args, **kwargs):
5657

5758
tmp = self.fnc(*args, **kwargs)
5859
with open(filename, 'wb') as f:
59-
os.chmod(filename, 0600)
60+
os.chmod(filename, 0o600)
6061
pickle.dump(tmp, f)
6162

6263
return tmp
@@ -66,7 +67,7 @@ def log_error(message, use_syslog):
6667
if use_syslog:
6768
syslog.syslog(syslog.LOG_ERR, message)
6869
else:
69-
print >> sys.stderr, 'ERROR: ' + message
70+
print('ERROR: ' + message, file=sys.stderr)
7071

7172

7273
@FileCache

0 commit comments

Comments
 (0)