Skip to content

Utility to report T2 instance CPU Credit Usage + Balance Metrics

Notifications You must be signed in to change notification settings

CU-CloudCollab/t2-credit-metrics

Repository files navigation

T2 Metrics Reporting Utility

Purpose(s):

  • Basic POC for getting cloudwatch metrics out of API and into Pandas for use in reporting/analysis
  • Implement report for monitoring T2 instance utilization + credit use metrics

Installation

First, build the container:

docker build -t t2-metrics .

Next, use the container to run a report for a specfic t2 instance:

docker run -it --rm -v ~/.aws:/root/.aws t2-metrics python t2_metrics.py i-4419cfd7

Note - this command passes in your .aws folder so that commands can use your credential sets. You can also pass in credentials as environment variables:

docker run -it -e AWS_ACCESS_KEY_ID=[ID] -e AWS_SECRET_ACCESS_KEY=[KEY] t2-metrics python t2_metrics.py i-4419cfd7

Development

To lint code with flake8:

docker run -it --rm -v ~/.aws:/root/.aws t2-metrics ./lint_code.sh

To run unit tests:

docker run -it --rm -v ~/.aws:/root/.aws t2-metrics ./run_tests.sh

Example output

Instance ID: i-4419cfd7
Instance Type: t2.medium
Credits Earned per Hour: 24
Maximum Credit Balance: 576

Three-Day Summary by Hour:
+---------------------------+--------------------------+----------------------+--------------+----------------------------+----------------------------+
|                           |   CPUUtilization_Average |   CPUCreditUsage_Sum |   Credit_Net |   CPUCreditBalance_Minimum |   CPUCreditBalance_Maximum |
|---------------------------+--------------------------+----------------------+--------------+----------------------------+----------------------------|
| 2016-10-12 21:03:00+00:00 |                  1.11383 |                 1.33 |        22.67 |                     547.25 |                     547.28 |
| 2016-10-12 22:03:00+00:00 |                  1.13083 |                 1.34 |        22.66 |                     547.28 |                     547.3  |
| 2016-10-12 23:03:00+00:00 |                  1.1095  |                 1.32 |        22.68 |                     547.3  |                     547.32 |
| 2016-10-13 00:03:00+00:00 |                  1.1515  |                 1.36 |        22.64 |                     547.3  |                     547.33 |
| 2016-10-13 01:03:00+00:00 |                  1.11117 |                 1.32 |        22.68 |                     547.3  |                     547.31 |
| 2016-10-13 02:03:00+00:00 |                  1.11783 |                 1.33 |        22.67 |                     547.31 |                     547.32 |
| 2016-10-13 03:03:00+00:00 |                  1.10283 |                 1.32 |        22.68 |                     547.32 |                     547.33 |
| 2016-10-13 04:03:00+00:00 |                  1.10533 |                 1.32 |        22.68 |                     547.33 |                     547.33 |
| 2016-10-13 05:03:00+00:00 |                  1.10683 |                 1.32 |        22.68 |                     547.33 |                     547.33 |
| 2016-10-13 06:03:00+00:00 |                  1.10567 |                 1.32 |        22.68 |                     547.32 |                     547.33 |
| 2016-10-13 07:03:00+00:00 |                  1.10817 |                 1.32 |        22.68 |                     547.31 |                     547.32 |
| 2016-10-13 08:03:00+00:00 |                  1.1085  |                 1.32 |        22.68 |                     547.32 |                     547.32 |
| 2016-10-13 09:03:00+00:00 |                  1.10667 |                 1.32 |        22.68 |                     547.31 |                     547.32 |
| 2016-10-13 10:03:00+00:00 |                  1.104   |                 1.32 |        22.68 |                     547.31 |                     547.32 |
| 2016-10-13 11:03:00+00:00 |                  1.11767 |                 1.33 |        22.67 |                     547.31 |                     547.32 |
| 2016-10-13 12:03:00+00:00 |                  1.12083 |                 1.32 |        22.68 |                     547.29 |                     547.31 |
| 2016-10-13 13:03:00+00:00 |                  1.1445  |                 1.36 |        22.64 |                     547.26 |                     547.29 |
| 2016-10-13 14:03:00+00:00 |                  1.157   |                 1.39 |        22.61 |                     547.23 |                     547.3  |
| 2016-10-13 15:03:00+00:00 |                  1.144   |                 1.35 |        22.65 |                     547.26 |                     547.38 |
| 2016-10-13 16:03:00+00:00 |                  1.17133 |                 1.4  |        22.6  |                     547.33 |                     547.35 |
| 2016-10-13 17:03:00+00:00 |                  1.24183 |                 1.49 |        22.51 |                     547.19 |                     547.32 |
| 2016-10-13 18:03:00+00:00 |                  1.16683 |                 1.38 |        22.62 |                     547.12 |                     547.18 |
| 2016-10-13 19:03:00+00:00 |                  1.1275  |                 1.34 |        22.66 |                     547.11 |                     547.21 |
| 2016-10-13 20:03:00+00:00 |                  1.21983 |                 1.37 |        22.63 |                     547.19 |                     547.23 |
| 2016-10-13 21:03:00+00:00 |                  1.14883 |                 1.42 |        22.58 |                     547.09 |                     547.13 |
| 2016-10-13 22:03:00+00:00 |                  1.15583 |                 1.36 |        22.64 |                     547.04 |                     547.07 |
| 2016-10-13 23:03:00+00:00 |                  1.138   |                 1.33 |        22.67 |                     547.03 |                     547.06 |
| 2016-10-14 00:03:00+00:00 |                  1.146   |                 1.34 |        22.66 |                     547.01 |                     547.04 |
| 2016-10-14 01:03:00+00:00 |                  1.14767 |                 1.33 |        22.67 |                     547.01 |                     547.04 |
| 2016-10-14 02:03:00+00:00 |                  1.14483 |                 1.36 |        22.64 |                     546.96 |                     547    |
| 2016-10-14 03:03:00+00:00 |                  1.11383 |                 1.32 |        22.68 |                     546.96 |                     546.97 |
| 2016-10-14 04:03:00+00:00 |                  1.11233 |                 1.32 |        22.68 |                     546.95 |                     546.96 |
| 2016-10-14 05:03:00+00:00 |                  1.10817 |                 1.32 |        22.68 |                     546.95 |                     546.95 |
| 2016-10-14 06:03:00+00:00 |                  1.10817 |                 1.33 |        22.67 |                     546.94 |                     546.95 |
| 2016-10-14 07:03:00+00:00 |                  1.1055  |                 1.32 |        22.68 |                     546.94 |                     546.95 |
| 2016-10-14 08:03:00+00:00 |                  1.10683 |                 1.32 |        22.68 |                     546.95 |                     546.95 |
| 2016-10-14 09:03:00+00:00 |                  1.10667 |                 1.32 |        22.68 |                     546.95 |                     546.95 |
| 2016-10-14 10:03:00+00:00 |                  1.10933 |                 1.32 |        22.68 |                     546.94 |                     546.95 |
| 2016-10-14 11:03:00+00:00 |                  1.14283 |                 1.35 |        22.65 |                     546.9  |                     546.94 |
| 2016-10-14 12:03:00+00:00 |                  1.143   |                 1.34 |        22.66 |                     546.88 |                     546.91 |
| 2016-10-14 13:03:00+00:00 |                  1.18733 |                 1.41 |        22.59 |                     546.83 |                     546.88 |
| 2016-10-14 14:03:00+00:00 |                  1.15817 |                 1.38 |        22.62 |                     546.78 |                     546.83 |
| 2016-10-14 15:03:00+00:00 |                  1.20017 |                 1.42 |        22.58 |                     546.74 |                     546.83 |
| 2016-10-14 16:03:00+00:00 |                  1.16267 |                 1.39 |        22.61 |                     546.74 |                     546.79 |
| 2016-10-14 17:03:00+00:00 |                  1.12217 |                 1.32 |        22.68 |                     546.77 |                     546.89 |
| 2016-10-14 18:03:00+00:00 |                  1.1825  |                 1.39 |        22.61 |                     546.9  |                     546.95 |
| 2016-10-14 19:03:00+00:00 |                  1.17767 |                 1.4  |        22.6  |                     546.83 |                     546.9  |
| 2016-10-14 20:03:00+00:00 |                  1.13767 |                 1.33 |        22.67 |                     546.83 |                     546.88 |
| 2016-10-14 21:03:00+00:00 |                  1.1075  |                 1.32 |        22.68 |                     546.88 |                     546.99 |
| 2016-10-14 22:03:00+00:00 |                  1.118   |                 1.34 |        22.66 |                     546.99 |                     547.05 |
| 2016-10-14 23:03:00+00:00 |                  1.1055  |                 1.32 |        22.68 |                     547.04 |                     547.08 |
| 2016-10-15 00:03:00+00:00 |                  1.10933 |                 1.32 |        22.68 |                     547.08 |                     547.1  |
| 2016-10-15 01:03:00+00:00 |                  1.12067 |                 1.33 |        22.67 |                     547.11 |                     547.14 |
| 2016-10-15 02:03:00+00:00 |                  1.13933 |                 1.33 |        22.67 |                     547.13 |                     547.15 |
| 2016-10-15 03:03:00+00:00 |                  1.12667 |                 1.32 |        22.68 |                     547.13 |                     547.15 |
| 2016-10-15 04:03:00+00:00 |                  1.108   |                 1.32 |        22.68 |                     547.13 |                     547.14 |
| 2016-10-15 05:03:00+00:00 |                  1.11217 |                 1.32 |        22.68 |                     547.14 |                     547.14 |
| 2016-10-15 06:03:00+00:00 |                  1.15283 |                 1.39 |        22.61 |                     547.08 |                     547.13 |
| 2016-10-15 07:03:00+00:00 |                  1.1095  |                 1.32 |        22.68 |                     547.08 |                     547.08 |
| 2016-10-15 08:03:00+00:00 |                  1.10667 |                 1.32 |        22.68 |                     547.08 |                     547.08 |
| 2016-10-15 09:03:00+00:00 |                  1.108   |                 1.32 |        22.68 |                     547.07 |                     547.08 |
| 2016-10-15 10:03:00+00:00 |                  1.108   |                 1.32 |        22.68 |                     547.07 |                     547.08 |
| 2016-10-15 11:03:00+00:00 |                  1.10667 |                 1.32 |        22.68 |                     547.08 |                     547.09 |
| 2016-10-15 12:03:00+00:00 |                  1.10667 |                 1.32 |        22.68 |                     547.12 |                     547.16 |
| 2016-10-15 13:03:00+00:00 |                  1.104   |                 1.32 |        22.68 |                     547.16 |                     547.23 |
| 2016-10-15 14:03:00+00:00 |                  1.101   |                 1.32 |        22.68 |                     547.25 |                     547.32 |
| 2016-10-15 15:03:00+00:00 |                  1.10167 |                 1.32 |        22.68 |                     547.33 |                     547.44 |
| 2016-10-15 16:03:00+00:00 |                  1.10133 |                 1.32 |        22.68 |                     547.44 |                     547.51 |
| 2016-10-15 17:03:00+00:00 |                  1.1     |                 1.32 |        22.68 |                     547.51 |                     547.54 |
| 2016-10-15 18:03:00+00:00 |                  1.10133 |                 1.32 |        22.68 |                     547.54 |                     547.63 |
| 2016-10-15 19:03:00+00:00 |                  1.10133 |                 1.32 |        22.68 |                     547.63 |                     547.72 |
| 2016-10-15 20:03:00+00:00 |                  1.10145 |                 1.21 |        22.79 |                     547.72 |                     547.76 |
+---------------------------+--------------------------+----------------------+--------------+----------------------------+----------------------------+

Summary by day:
+---------------------------+--------------------------+----------------------+--------------+----------------------------+----------------------------+
|                           |   CPUUtilization_Average |   CPUCreditUsage_Sum |   Credit_Net |   CPUCreditBalance_Minimum |   CPUCreditBalance_Maximum |
|---------------------------+--------------------------+----------------------+--------------+----------------------------+----------------------------|
| 2016-10-14 21:03:00+00:00 |                  1.11077 |                31.68 |       544.32 |                     546.88 |                     547.76 |
| 2016-10-12 21:03:00+00:00 |                  1.13308 |                32.29 |       543.71 |                     547.11 |                     547.38 |
| 2016-10-13 21:03:00+00:00 |                  1.14026 |                32.44 |       543.56 |                     546.74 |                     547.13 |
+---------------------------+--------------------------+----------------------+--------------+----------------------------+----------------------------+

About

Utility to report T2 instance CPU Credit Usage + Balance Metrics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published