From f649d6e7af0a1db37e30486f3bf215b8878304e3 Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Sat, 18 Mar 2017 14:48:58 +0100 Subject: [PATCH 01/20] encode sig before hashing #17 --- cloudwatchmon/cloud_watch_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cloudwatchmon/cloud_watch_client.py b/cloudwatchmon/cloud_watch_client.py index bee4e99..e564e18 100644 --- a/cloudwatchmon/cloud_watch_client.py +++ b/cloudwatchmon/cloud_watch_client.py @@ -44,9 +44,9 @@ def __init__(self, fnc): def __call__(self, *args, **kwargs): sig = ":".join([VERSION, str(self.fnc.__name__), str(args), str(kwargs)]) + sig_hash = hashlib.md5(sig.encode('utf-8')).hexdigest() filename = os.path.join(META_DATA_CACHE_DIR, '{0}-{1}.bin' - .format(self.CLIENT_NAME, - hashlib.md5(sig).hexdigest())) + .format(self.CLIENT_NAME, sig_hash)) if os.path.exists(filename): mtime = os.path.getmtime(filename) From 31d2c65bbea4ba51d82e67b14d46963282964c96 Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Sat, 18 Mar 2017 14:49:41 +0100 Subject: [PATCH 02/20] updated email address --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2361d0b..ea477c1 100755 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ def readme(): long_description=readme(), url='https://github.com/osiegmar/cloudwatch-mon-scripts-python', author='Oliver Siegmar', - author_email='oliver@siegmar.net', + author_email='oliver@siegmar.de', license='Apache License (2.0)', keywords="monitoring cloudwatch amazon web services aws ec2", zip_safe=True, From 11b44d79eff29c920ed9237febfddd341a34317c Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Sat, 18 Mar 2017 15:37:03 +0100 Subject: [PATCH 03/20] add Python 3 compatibility #12 --- cloudwatchmon/cli/get_instance_stats.py | 2 +- cloudwatchmon/cli/put_instance_stats.py | 4 +++- setup.py | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cloudwatchmon/cli/get_instance_stats.py b/cloudwatchmon/cli/get_instance_stats.py index 93d3404..6e800e6 100755 --- a/cloudwatchmon/cli/get_instance_stats.py +++ b/cloudwatchmon/cli/get_instance_stats.py @@ -71,7 +71,7 @@ def print_metric_stats(region, instance_id, namespace, metric, title, start_time = end_time - datetime.timedelta(hours=recent_hours) dims = {'InstanceId': instance_id} if xdims: - dims = dict(dims.items() + xdims.items()) + dims.update(xdims) metrics = conn.get_metric_statistics(300, start_time, end_time, metric, namespace, ['Average', 'Maximum', 'Minimum'], diff --git a/cloudwatchmon/cli/put_instance_stats.py b/cloudwatchmon/cli/put_instance_stats.py index 9e30e41..3f1ab94 100755 --- a/cloudwatchmon/cli/put_instance_stats.py +++ b/cloudwatchmon/cli/put_instance_stats.py @@ -170,7 +170,9 @@ def __add_metric_dimensions(self, name, unit, value, common_dims, dims): self.names.append(name) self.units.append(unit) self.values.append(value) - self.dimensions.append(dict(common_dims.items() + dim.items())) + metric_dims = common_dims.copy() + metric_dims.update(dim) + self.dimensions.append(metric_dims) def send(self, verbose): boto_debug = 2 if verbose else 0 diff --git a/setup.py b/setup.py index ea477c1..746ad77 100755 --- a/setup.py +++ b/setup.py @@ -30,7 +30,13 @@ def readme(): ] }, classifiers=[ - 'Programming Language :: Python :: 2 :: Only', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', 'License :: OSI Approved :: Apache Software License', 'Topic :: System :: Monitoring' ] From 93277ef49ebb70f7033fdfeee682e643a22e70da Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Sat, 18 Mar 2017 15:37:28 +0100 Subject: [PATCH 04/20] version bump --- cloudwatchmon/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudwatchmon/__init__.py b/cloudwatchmon/__init__.py index fa8968b..f1f5a0e 100644 --- a/cloudwatchmon/__init__.py +++ b/cloudwatchmon/__init__.py @@ -1 +1 @@ -VERSION = '2.0.5' +VERSION = '2.0.6' From 5236f977010463f73b38c7b1f1699c1569cb9dbd Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Sat, 18 Mar 2017 15:59:17 +0100 Subject: [PATCH 05/20] markdown highlighting --- README.md | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 18994e3..66b7f3f 100644 --- a/README.md +++ b/README.md @@ -46,20 +46,22 @@ Configuration To allow an EC2 instance to read and post metric data to Amazon CloudWatch, this IAM policy is required: +```json +{ + "Statement": [ { - "Statement": [ - { - "Action": [ - "cloudwatch:ListMetrics", - "cloudwatch:GetMetricStatistics", - "cloudwatch:PutMetricData", - "autoscaling:DescribeAutoScalingInstances" - ], - "Effect": "Allow", - "Resource": "*" - } - ] + "Action": [ + "cloudwatch:ListMetrics", + "cloudwatch:GetMetricStatistics", + "cloudwatch:PutMetricData", + "autoscaling:DescribeAutoScalingInstances" + ], + "Effect": "Allow", + "Resource": "*" } + ] +} +``` If the policy is configured via an IAM role that is assigned to the EC2 server this script runs on, you're done. @@ -67,15 +69,18 @@ server this script runs on, you're done. Otherwise you can configure the policy for a user account and export the credentials before running the script: - export AWS_ACCESS_KEY_ID=[Your AWS Access Key ID] - export AWS_SECRET_ACCESS_KEY=[Your AWS Secret Access Key] +```sh +export AWS_ACCESS_KEY_ID=[Your AWS Access Key ID] +export AWS_SECRET_ACCESS_KEY=[Your AWS Secret Access Key] +``` Third option is to create a _~/.boto_ file with this content: - [Credentials] - aws_access_key_id = Your AWS Access Key ID - aws_secret_access_key = Your AWS Secret Access Key - +``` +[Credentials] +aws_access_key_id = Your AWS Access Key ID +aws_secret_access_key = Your AWS Secret Access Key +``` Copyright --------- From 4db74964b46d4dbca8acd69a38da7f1f0a47aa63 Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Sun, 19 Mar 2017 11:18:53 +0100 Subject: [PATCH 06/20] Trove update --- setup.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 746ad77..80739d9 100755 --- a/setup.py +++ b/setup.py @@ -30,6 +30,12 @@ def readme(): ] }, classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Environment :: Console', + 'Intended Audience :: System Administrators', + 'License :: OSI Approved :: Apache Software License', + 'Natural Language :: English', + 'Operating System :: POSIX :: Linux', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', @@ -37,7 +43,6 @@ def readme(): 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', - 'License :: OSI Approved :: Apache Software License', 'Topic :: System :: Monitoring' ] ) From 690376b626d9d5036ac6cca2dbb66167afd39885 Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Sun, 19 Mar 2017 11:24:53 +0100 Subject: [PATCH 07/20] removed the .py suffix from the executable --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 80739d9..d2fdab8 100755 --- a/setup.py +++ b/setup.py @@ -25,8 +25,8 @@ def readme(): packages=find_packages(), install_requires=['boto>=2.33.0', 'argparse'], entry_points={'console_scripts': [ - 'mon-get-instance-stats.py=cloudwatchmon.cli.get_instance_stats:main', - 'mon-put-instance-stats.py=cloudwatchmon.cli.put_instance_stats:main', + 'mon-get-instance-stats=cloudwatchmon.cli.get_instance_stats:main', + 'mon-put-instance-stats=cloudwatchmon.cli.put_instance_stats:main', ] }, classifiers=[ From c7dd9f77e4f51f439d08688368ddcf5a0ad6ee13 Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Sun, 19 Mar 2017 11:25:05 +0100 Subject: [PATCH 08/20] version bump --- cloudwatchmon/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudwatchmon/__init__.py b/cloudwatchmon/__init__.py index f1f5a0e..780e307 100644 --- a/cloudwatchmon/__init__.py +++ b/cloudwatchmon/__init__.py @@ -1 +1 @@ -VERSION = '2.0.6' +VERSION = '2.0.7' From 12169580edb7b302edf70494c8bbd7e193b9322e Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Sun, 19 Mar 2017 11:50:28 +0100 Subject: [PATCH 09/20] README update --- README.md | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 66b7f3f..4708f93 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,28 @@ cloudwatch-mon-scripts-python [![PyPI version](https://badge.fury.io/py/cloudwatchmon.svg)](https://badge.fury.io/py/cloudwatchmon) -Linux monitoring scripts for CloudWatch. +Linux monitoring scripts for the [AWS CloudWatch Service](https://aws.amazon.com/de/cloudwatch/). + +Initially, this project was created, because the +original [AWS monitoring scripts](https://aws.amazon.com/code/8720044071969977) +lacked support for the eu-central-1 (Frankfurt) region for about 4 months +(2014-10-23 to 2015-02-25). + +Now, this project has a couple of additional features (compared to v1.1.0 of +the original AWS monitoring scripts): + +- Memory monitoring incl. buffers +- Load monitoring (overall and per CPU core) +- Monitoring of disk inode usage +- Process monitoring +- Fewer dependencies +- Simpler installation Requirements ------------ -- Python >= 2.6 +- Python 2 (>= 2.6) or Python 3 (>= 3.3) - Boto >= 2.33.0 @@ -17,7 +32,7 @@ Installation ------------ Optionally create a virtual environment and activate it. Then just run -`pip install cloudwatchmon`. Install the scripts in /usr/local/bin folder. +`pip install cloudwatchmon`. Install the scripts in `/usr/local/bin` folder. For script usage, run: @@ -27,15 +42,15 @@ For script usage, run: Examples -------- -To perform a simple test run without posting data to Amazon CloudWatch +To perform a simple test run without posting data to Amazon CloudWatch: mon-put-instance-stats.py --mem-util --verify --verbose -Report memory and disk space utilization to Amazon CloudWatch +Report memory and disk space utilization to Amazon CloudWatch: mon-put-instance-stats.py --mem-util --disk-space-util --disk-path=/ -To get utilization statistics for the last 12 hours +To get utilization statistics for the last 12 hours: mon-get-instance-stats.py --recent-hours=12 From f86cbb257aebe623a1d9ae0c2bc61bfccb7b74c3 Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Sun, 19 Mar 2017 12:05:19 +0100 Subject: [PATCH 10/20] removed the .py suffix from the executable --- README.md | 8 ++++---- cloudwatchmon/cli/put_instance_stats.py | 21 +++++++++------------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4708f93..bf07b3d 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Optionally create a virtual environment and activate it. Then just run For script usage, run: - mon-put-instance-stats.py --help + mon-put-instance-stats --help Examples @@ -44,15 +44,15 @@ Examples To perform a simple test run without posting data to Amazon CloudWatch: - mon-put-instance-stats.py --mem-util --verify --verbose + mon-put-instance-stats --mem-util --verify --verbose Report memory and disk space utilization to Amazon CloudWatch: - mon-put-instance-stats.py --mem-util --disk-space-util --disk-path=/ + mon-put-instance-stats --mem-util --disk-space-util --disk-path=/ To get utilization statistics for the last 12 hours: - mon-get-instance-stats.py --recent-hours=12 + mon-get-instance-stats --recent-hours=12 Configuration diff --git a/cloudwatchmon/cli/put_instance_stats.py b/cloudwatchmon/cli/put_instance_stats.py index 3f1ab94..bc080d8 100755 --- a/cloudwatchmon/cli/put_instance_stats.py +++ b/cloudwatchmon/cli/put_instance_stats.py @@ -224,23 +224,20 @@ def config_parser(): Examples - To perform a simple test run without posting data to Amazon CloudWatch + To perform a simple test run without posting data to Amazon CloudWatch - ./put_instance_stats.py --mem-util --verify --verbose - or - # If installed via pip install cloudwatchmon - mon-put-instance-stats.py --mem-util --verify --verbose + mon-put-instance-stats --mem-util --verify --verbose - To set a five-minute cron schedule to report memory and disk space utilization - to CloudWatch - */5 * * * * ~/cloudwatchmon/put_instance_stats.py --mem-util --disk-space-util --disk-path=/ --from-cron - or - # If installed via pip install cloudwatchmon - * /5 * * * * /usr/local/bin/mon-put-instance-stats.py --mem-util --disk-space-util --disk-path=/ --from-cron + To set a five-minute cron schedule to report memory and disk space utilization + to CloudWatch + + */5 * * * * mon-put-instance-stats --mem-util --disk-space-util --disk-path=/ --from-cron + To report metrics from file - mon-put-instance-stats.py --from-file filename.csv + + mon-put-instance-stats --from-file filename.csv For more information on how to use this utility, see project home on GitHub: https://github.com/osiegmar/cloudwatch-mon-scripts-python From 0439f8f5e44ea723775f6d11346c68030b14f3f8 Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Sun, 19 Mar 2017 13:27:02 +0100 Subject: [PATCH 11/20] keep .py extension for compatibility --- README.md | 8 ++++---- cloudwatchmon/cli/put_instance_stats.py | 6 +++--- setup.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bf07b3d..4708f93 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Optionally create a virtual environment and activate it. Then just run For script usage, run: - mon-put-instance-stats --help + mon-put-instance-stats.py --help Examples @@ -44,15 +44,15 @@ Examples To perform a simple test run without posting data to Amazon CloudWatch: - mon-put-instance-stats --mem-util --verify --verbose + mon-put-instance-stats.py --mem-util --verify --verbose Report memory and disk space utilization to Amazon CloudWatch: - mon-put-instance-stats --mem-util --disk-space-util --disk-path=/ + mon-put-instance-stats.py --mem-util --disk-space-util --disk-path=/ To get utilization statistics for the last 12 hours: - mon-get-instance-stats --recent-hours=12 + mon-get-instance-stats.py --recent-hours=12 Configuration diff --git a/cloudwatchmon/cli/put_instance_stats.py b/cloudwatchmon/cli/put_instance_stats.py index bc080d8..5584906 100755 --- a/cloudwatchmon/cli/put_instance_stats.py +++ b/cloudwatchmon/cli/put_instance_stats.py @@ -226,18 +226,18 @@ def config_parser(): To perform a simple test run without posting data to Amazon CloudWatch - mon-put-instance-stats --mem-util --verify --verbose + mon-put-instance-stats.py --mem-util --verify --verbose To set a five-minute cron schedule to report memory and disk space utilization to CloudWatch - */5 * * * * mon-put-instance-stats --mem-util --disk-space-util --disk-path=/ --from-cron + */5 * * * * mon-put-instance-stats.py --mem-util --disk-space-util --disk-path=/ --from-cron To report metrics from file - mon-put-instance-stats --from-file filename.csv + mon-put-instance-stats.py --from-file filename.csv For more information on how to use this utility, see project home on GitHub: https://github.com/osiegmar/cloudwatch-mon-scripts-python diff --git a/setup.py b/setup.py index d2fdab8..80739d9 100755 --- a/setup.py +++ b/setup.py @@ -25,8 +25,8 @@ def readme(): packages=find_packages(), install_requires=['boto>=2.33.0', 'argparse'], entry_points={'console_scripts': [ - 'mon-get-instance-stats=cloudwatchmon.cli.get_instance_stats:main', - 'mon-put-instance-stats=cloudwatchmon.cli.put_instance_stats:main', + 'mon-get-instance-stats.py=cloudwatchmon.cli.get_instance_stats:main', + 'mon-put-instance-stats.py=cloudwatchmon.cli.put_instance_stats:main', ] }, classifiers=[ From cbe2b23f07b9dd3a99b051d149c7662871e17f8e Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 10 May 2018 12:22:25 -0400 Subject: [PATCH 12/20] Allow AWS Profile for CloudWatch Send --- cloudwatchmon/cli/put_instance_stats.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cloudwatchmon/cli/put_instance_stats.py b/cloudwatchmon/cli/put_instance_stats.py index 5584906..8badb21 100755 --- a/cloudwatchmon/cli/put_instance_stats.py +++ b/cloudwatchmon/cli/put_instance_stats.py @@ -174,11 +174,11 @@ def __add_metric_dimensions(self, name, unit, value, common_dims, dims): metric_dims.update(dim) self.dimensions.append(metric_dims) - def send(self, verbose): + def send(self, verbose, awsProfile): boto_debug = 2 if verbose else 0 # TODO add timeout - conn = boto.ec2.cloudwatch.connect_to_region(self.region, + conn = boto.ec2.cloudwatch.connect_to_region(self.region, profile_name=awsProfile, debug=boto_debug) if not conn: @@ -338,6 +338,9 @@ def config_parser(): parser.add_argument('--version', action='store_true', help='Displays the version number and exits.') + parser.add_argument('--aws-profile-name', + action='store', + help='Use AWS profile of this name when posting to CloudWatch.') return parser @@ -569,12 +572,17 @@ def main(): if args.verbose: print('Request:\n' + str(metrics)) + # Check for AWS profile + awsProfile = None + if args.aws_profile_name: + awsProfile = args.aws_profile_name + if args.verify: if not args.from_cron: print('Verification completed successfully. ' 'No actual metrics sent to CloudWatch.') else: - metrics.send(args.verbose) + metrics.send(args.verbose, awsProfile) if not args.from_cron: print('Successfully reported metrics to CloudWatch.') except Exception as e: From db1357bf2fc73da750f0340baf71af529ab53e92 Mon Sep 17 00:00:00 2001 From: Tim G Date: Thu, 13 Sep 2018 10:16:14 +1000 Subject: [PATCH 13/20] Use 'MemAvailable' metric on Linux 3.x kernels --- cloudwatchmon/cli/put_instance_stats.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cloudwatchmon/cli/put_instance_stats.py b/cloudwatchmon/cli/put_instance_stats.py index 5584906..95b8079 100755 --- a/cloudwatchmon/cli/put_instance_stats.py +++ b/cloudwatchmon/cli/put_instance_stats.py @@ -50,6 +50,7 @@ def __init__(self, mem_used_incl_cache_buff): mem_info = self.__gather_mem_info() self.mem_total = mem_info['MemTotal'] self.mem_free = mem_info['MemFree'] + self.mem_available = mem_info.get('MemAvailable') # Linux >= 3.14 self.mem_cached = mem_info['Cached'] self.mem_buffers = mem_info['Buffers'] self.swap_total = mem_info['SwapTotal'] @@ -74,9 +75,14 @@ def mem_used(self): return self.mem_total - self.mem_avail() def mem_avail(self): - mem_avail = self.mem_free - if not self.mem_used_incl_cache_buff: - mem_avail += self.mem_cached + self.mem_buffers + # Linux 3.14 kernel added 'MemAvailable' to /proc/meminfo + if self.mem_available: + mem_avail = self.mem_available + else: + mem_avail = self.mem_free + self.mem_cached + self.mem_buffers + + if self.mem_used_incl_cache_buff: + mem_avail -= self.mem_cached + self.mem_buffers return mem_avail From 2b17bc9a1974710c53e323055b3efe805a004c1d Mon Sep 17 00:00:00 2001 From: Reha Sterbin Date: Mon, 24 Aug 2020 16:24:46 -0400 Subject: [PATCH 14/20] Allow stats to be sent, even if only the process flags are set --- cloudwatchmon/cli/put_instance_stats.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cloudwatchmon/cli/put_instance_stats.py b/cloudwatchmon/cli/put_instance_stats.py index 5584906..d9d355f 100755 --- a/cloudwatchmon/cli/put_instance_stats.py +++ b/cloudwatchmon/cli/put_instance_stats.py @@ -495,7 +495,8 @@ def validate_args(args): 'disk path is not specified.') if not report_mem_data and not report_disk_data and \ - not args.from_file and not report_loadavg_data: + not args.from_file and not report_loadavg_data and \ + not report_process_data: raise ValueError('No metrics specified for collection and ' 'submission to CloudWatch.') From fcf7bc25cd7686a2229a7e6d172497d7ffde7b5b Mon Sep 17 00:00:00 2001 From: Reha Sterbin Date: Tue, 25 Aug 2020 14:38:32 -0400 Subject: [PATCH 15/20] Added process count as a new metric --- cloudwatchmon/cli/put_instance_stats.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cloudwatchmon/cli/put_instance_stats.py b/cloudwatchmon/cli/put_instance_stats.py index 5584906..f1c45ad 100755 --- a/cloudwatchmon/cli/put_instance_stats.py +++ b/cloudwatchmon/cli/put_instance_stats.py @@ -310,7 +310,7 @@ def config_parser(): process_group.add_argument('--process-name', metavar='PROCNAME', action='append', - help='Report CPU and Memory utilization metrics of processes.') + help='Report process count, CPU utilization, and memory utilization metrics for a process.') exclusive_group = parser.add_mutually_exclusive_group() exclusive_group.add_argument('--from-cron', @@ -432,13 +432,16 @@ def add_process_metrics(args, metrics): process_names = args.process_name for process_name in process_names: processes = subprocess.Popen(["ps", "axco", "command,pcpu,pmem"], stdout=subprocess.PIPE) + total_cnt = 0 total_cpu = 0.0 total_mem = 0.0 for line in processes.stdout: if re.search(process_name, line): + total_cnt++ out = line.split() total_cpu += float(out[1]) total_mem += float(out[2]) + metrics.add_metric(process_name+'-Count', 'Count', total_cpu) metrics.add_metric(process_name+'-CpuUtilization', 'Percent', total_cpu) metrics.add_metric(process_name+'-MemoryUtilization', 'Percent', total_mem) From f3bd9afd5f8f5d101a78517a6ba73b4445b5b949 Mon Sep 17 00:00:00 2001 From: Reha Sterbin Date: Tue, 25 Aug 2020 14:41:22 -0400 Subject: [PATCH 16/20] Wrong syntax oops --- cloudwatchmon/cli/put_instance_stats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudwatchmon/cli/put_instance_stats.py b/cloudwatchmon/cli/put_instance_stats.py index f1c45ad..5d9919c 100755 --- a/cloudwatchmon/cli/put_instance_stats.py +++ b/cloudwatchmon/cli/put_instance_stats.py @@ -437,7 +437,7 @@ def add_process_metrics(args, metrics): total_mem = 0.0 for line in processes.stdout: if re.search(process_name, line): - total_cnt++ + total_cnt += 1 out = line.split() total_cpu += float(out[1]) total_mem += float(out[2]) From fcb797e9bb8f19f15415337b7572bdaf2df351bf Mon Sep 17 00:00:00 2001 From: Reha Sterbin Date: Tue, 25 Aug 2020 14:45:43 -0400 Subject: [PATCH 17/20] Autocomplete did me wrong --- cloudwatchmon/cli/put_instance_stats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudwatchmon/cli/put_instance_stats.py b/cloudwatchmon/cli/put_instance_stats.py index 5d9919c..c4518ea 100755 --- a/cloudwatchmon/cli/put_instance_stats.py +++ b/cloudwatchmon/cli/put_instance_stats.py @@ -441,7 +441,7 @@ def add_process_metrics(args, metrics): out = line.split() total_cpu += float(out[1]) total_mem += float(out[2]) - metrics.add_metric(process_name+'-Count', 'Count', total_cpu) + metrics.add_metric(process_name+'-Count', 'Count', total_cnt) metrics.add_metric(process_name+'-CpuUtilization', 'Percent', total_cpu) metrics.add_metric(process_name+'-MemoryUtilization', 'Percent', total_mem) From d3b588c35511274c4f96e71fedc51a1509f1443f Mon Sep 17 00:00:00 2001 From: Reha Sterbin Date: Tue, 25 Aug 2020 14:38:32 -0400 Subject: [PATCH 18/20] Added process count as a new metric --- cloudwatchmon/cli/put_instance_stats.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cloudwatchmon/cli/put_instance_stats.py b/cloudwatchmon/cli/put_instance_stats.py index d9d355f..d2f2422 100755 --- a/cloudwatchmon/cli/put_instance_stats.py +++ b/cloudwatchmon/cli/put_instance_stats.py @@ -310,7 +310,7 @@ def config_parser(): process_group.add_argument('--process-name', metavar='PROCNAME', action='append', - help='Report CPU and Memory utilization metrics of processes.') + help='Report process count, CPU utilization, and memory utilization metrics for a process.') exclusive_group = parser.add_mutually_exclusive_group() exclusive_group.add_argument('--from-cron', @@ -432,13 +432,16 @@ def add_process_metrics(args, metrics): process_names = args.process_name for process_name in process_names: processes = subprocess.Popen(["ps", "axco", "command,pcpu,pmem"], stdout=subprocess.PIPE) + total_cnt = 0 total_cpu = 0.0 total_mem = 0.0 for line in processes.stdout: if re.search(process_name, line): + total_cnt++ out = line.split() total_cpu += float(out[1]) total_mem += float(out[2]) + metrics.add_metric(process_name+'-Count', 'Count', total_cpu) metrics.add_metric(process_name+'-CpuUtilization', 'Percent', total_cpu) metrics.add_metric(process_name+'-MemoryUtilization', 'Percent', total_mem) From b77402fa63b93fd992216d55aa64f82a7ee96c52 Mon Sep 17 00:00:00 2001 From: Reha Sterbin Date: Tue, 25 Aug 2020 14:41:22 -0400 Subject: [PATCH 19/20] Wrong syntax oops --- cloudwatchmon/cli/put_instance_stats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudwatchmon/cli/put_instance_stats.py b/cloudwatchmon/cli/put_instance_stats.py index d2f2422..3ed716e 100755 --- a/cloudwatchmon/cli/put_instance_stats.py +++ b/cloudwatchmon/cli/put_instance_stats.py @@ -437,7 +437,7 @@ def add_process_metrics(args, metrics): total_mem = 0.0 for line in processes.stdout: if re.search(process_name, line): - total_cnt++ + total_cnt += 1 out = line.split() total_cpu += float(out[1]) total_mem += float(out[2]) From f77f7b4a6120b946b431e252a7943081368df6e6 Mon Sep 17 00:00:00 2001 From: Reha Sterbin Date: Tue, 25 Aug 2020 14:45:43 -0400 Subject: [PATCH 20/20] Autocomplete did me wrong --- cloudwatchmon/cli/put_instance_stats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudwatchmon/cli/put_instance_stats.py b/cloudwatchmon/cli/put_instance_stats.py index 3ed716e..7b31f08 100755 --- a/cloudwatchmon/cli/put_instance_stats.py +++ b/cloudwatchmon/cli/put_instance_stats.py @@ -441,7 +441,7 @@ def add_process_metrics(args, metrics): out = line.split() total_cpu += float(out[1]) total_mem += float(out[2]) - metrics.add_metric(process_name+'-Count', 'Count', total_cpu) + metrics.add_metric(process_name+'-Count', 'Count', total_cnt) metrics.add_metric(process_name+'-CpuUtilization', 'Percent', total_cpu) metrics.add_metric(process_name+'-MemoryUtilization', 'Percent', total_mem)