1717# See the License for the specific language governing permissions and
1818# limitations under the License.
1919
20+ from __future__ import print_function
2021from cloudwatchmon .cloud_watch_client import *
2122
2223import argparse
@@ -182,7 +183,7 @@ def send(self, verbose):
182183
183184 size = len (self .names )
184185
185- for idx_start in xrange (0 , size , AWS_LIMIT_METRICS_SIZE ):
186+ for idx_start in range (0 , size , AWS_LIMIT_METRICS_SIZE ):
186187 idx_end = idx_start + AWS_LIMIT_METRICS_SIZE
187188 response = conn .put_metric_data ('System/Linux' ,
188189 self .names [idx_start :idx_end ],
@@ -281,7 +282,6 @@ def config_parser():
281282 action = 'store_true' ,
282283 help = 'Report load averages for 1min, 5min and 15min divided by the number of CPU cores.' )
283284
284-
285285 disk_group = parser .add_argument_group ('disk metrics' )
286286 disk_group .add_argument ('--disk-path' ,
287287 metavar = 'PATH' ,
@@ -306,7 +306,6 @@ def config_parser():
306306 action = 'store_true' ,
307307 help = 'Reports disk inode utilization in percentages.' )
308308
309-
310309 exclusive_group = parser .add_mutually_exclusive_group ()
311310 exclusive_group .add_argument ('--from-cron' ,
312311 action = 'store_true' ,
@@ -356,6 +355,7 @@ def add_memory_metrics(args, metrics):
356355 metrics .add_metric ('SwapUsed' , mem_unit_name ,
357356 mem .swap_used () / mem_unit_div )
358357
358+
359359def add_loadavg_metrics (args , metrics ):
360360 loadavg = LoadAverage ()
361361 if args .loadavg :
@@ -381,8 +381,8 @@ def get_disk_info(args):
381381 used = int (line [2 ]) * 1024
382382 avail = int (line [3 ]) * 1024
383383 disks .append (Disk (mount , file_system , total , used , avail , 0 ))
384-
385- #Gather inode utilization if it is requested
384+
385+ # Gather inode utilization if it is requested
386386 if not args .disk_inode_util :
387387 return disks
388388
@@ -394,7 +394,7 @@ def get_disk_info(args):
394394 used = float (line [2 ])
395395 total = float (line [1 ])
396396 inode_util_val = 100.0 * used / total if total > 0 else 0
397- disks_inode_util .append (inode_util_val )
397+ disks_inode_util .append (inode_util_val )
398398
399399 for index , disk in enumerate (disks ):
400400 disk .inode_util = disks_inode_util [index ]
@@ -420,7 +420,6 @@ def add_disk_metrics(args, metrics):
420420 if args .disk_inode_util :
421421 metrics .add_metric ('InodeUtilization' , 'Percent' ,
422422 disk .inode_util , disk .mount , disk .file_system )
423-
424423
425424
426425def add_static_file_metrics (args , metrics ):
@@ -430,7 +429,7 @@ def add_static_file_metrics(args, metrics):
430429 (label , unit , value ) = [x .strip () for x in line .split (',' )]
431430 metrics .add_metric (label , unit , value )
432431 except ValueError :
433- print 'Ignore unparseable metric: "' + line + '"'
432+ print ( 'Ignore unparseable metric: "' + line + '"' )
434433 pass
435434
436435
@@ -473,8 +472,8 @@ def validate_args(args):
473472 raise ValueError ('Metrics to report disk space are provided but '
474473 'disk path is not specified.' )
475474
476- if not report_mem_data and not report_disk_data and not args . from_file and \
477- not report_loadavg_data :
475+ if not report_mem_data and not report_disk_data and \
476+ not args . from_file and not report_loadavg_data :
478477 raise ValueError ('No metrics specified for collection and '
479478 'submission to CloudWatch.' )
480479
@@ -492,24 +491,25 @@ def main():
492491 args = parser .parse_args ()
493492
494493 if args .version :
495- print CLIENT_NAME + ' version ' + VERSION
494+ print ( CLIENT_NAME + ' version ' + VERSION )
496495 return 0
497496
498497 try :
499- report_disk_data , report_mem_data , report_loadavg_data = validate_args (args )
498+ report_disk_data , report_mem_data , report_loadavg_data = \
499+ validate_args (args )
500500
501501 # avoid a storm of calls at the beginning of a minute
502502 if args .from_cron :
503503 time .sleep (random .randint (0 , 19 ))
504504
505505 if args .verbose :
506- print 'Working in verbose mode'
507- print 'Boto-Version: ' + boto .__version__
506+ print ( 'Working in verbose mode' )
507+ print ( 'Boto-Version: ' + boto .__version__ )
508508
509509 metadata = get_metadata ()
510510
511511 if args .verbose :
512- print 'Instance metadata: ' + str (metadata )
512+ print ( 'Instance metadata: ' + str (metadata ) )
513513
514514 region = metadata ['placement' ]['availability-zone' ][:- 1 ]
515515 instance_id = metadata ['instance-id' ]
@@ -520,7 +520,7 @@ def main():
520520 args .verbose )
521521
522522 if args .verbose :
523- print 'Autoscaling group: ' + autoscaling_group_name
523+ print ( 'Autoscaling group: ' + autoscaling_group_name )
524524
525525 metrics = Metrics (region ,
526526 instance_id ,
@@ -542,16 +542,16 @@ def main():
542542 add_disk_metrics (args , metrics )
543543
544544 if args .verbose :
545- print 'Request:\n ' + str (metrics )
545+ print ( 'Request:\n ' + str (metrics ) )
546546
547547 if args .verify :
548548 if not args .from_cron :
549- print 'Verification completed successfully. ' \
550- 'No actual metrics sent to CloudWatch.'
549+ print ( 'Verification completed successfully. '
550+ 'No actual metrics sent to CloudWatch.' )
551551 else :
552552 metrics .send (args .verbose )
553553 if not args .from_cron :
554- print 'Successfully reported metrics to CloudWatch.'
554+ print ( 'Successfully reported metrics to CloudWatch.' )
555555 except Exception as e :
556556 log_error (str (e ), args .from_cron )
557557 return 1
0 commit comments