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
@@ -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+
367366def 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
433431def 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
0 commit comments