awslimitchecker.limit module¶
-
class
awslimitchecker.limit.
AwsLimit
(name, service, default_limit, def_warning_threshold, def_critical_threshold, limit_type=None, limit_subtype=None, ta_service_name=None, ta_limit_name=None)[source]¶ Bases:
object
Describes one specific AWS service limit, as well as its current utilization, default limit, thresholds, and any Trusted Advisor information about this limit.
Parameters: - name (str) – the name of this limit (may contain spaces); if possible, this should be the name used by AWS, i.e. TrustedAdvisor
- service (
_AwsService
) – the_AwsService
class that this limit is for - default_limit (int) – the default value of this limit for new accounts
- def_warning_threshold (int) – the default warning threshold, as an integer percentage.
- def_critical_threshold (int) – the default critical threshold, as an integer percentage.
- limit_type – the type of resource this limit describes, specified as one of the type names used in CloudFormation # noqa such as “AWS::EC2::Instance” or “AWS::RDS::DBSubnetGroup”.
- limit_subtype (str) – resource sub-type for this limit, if applicable, such as “t2.micro” or “SecurityGroup”
- ta_service_name (str) – The service name returned by Trusted Advisor
for this limit, if different from the name of
service
- ta_limit_name (str) – The limit name returned by Trusted Advisor for
this limit, if different from
name
.
Raises: ValueError
-
__dict__
= dict_proxy({'__module__': 'awslimitchecker.limit', 'get_current_usage_str': <function get_current_usage_str>, 'check_thresholds': <function check_thresholds>, 'ta_service_name': <property object>, 'get_limit': <function get_limit>, '_set_ta_unlimited': <function _set_ta_unlimited>, '__dict__': <attribute '__dict__' of 'AwsLimit' objects>, '_get_thresholds': <function _get_thresholds>, '_add_current_usage': <function _add_current_usage>, '__init__': <function __init__>, 'ta_limit_name': <property object>, 'set_limit_override': <function set_limit_override>, 'get_criticals': <function get_criticals>, '_set_ta_limit': <function _set_ta_limit>, '__weakref__': <attribute '__weakref__' of 'AwsLimit' objects>, '_set_api_limit': <function _set_api_limit>, 'get_current_usage': <function get_current_usage>, 'set_threshold_override': <function set_threshold_override>, '_reset_usage': <function _reset_usage>, 'get_limit_source': <function get_limit_source>, 'get_warnings': <function get_warnings>, '__doc__': None})¶
-
__init__
(name, service, default_limit, def_warning_threshold, def_critical_threshold, limit_type=None, limit_subtype=None, ta_service_name=None, ta_limit_name=None)[source]¶ Describes one specific AWS service limit, as well as its current utilization, default limit, thresholds, and any Trusted Advisor information about this limit.
Parameters: - name (str) – the name of this limit (may contain spaces); if possible, this should be the name used by AWS, i.e. TrustedAdvisor
- service (
_AwsService
) – the_AwsService
class that this limit is for - default_limit (int) – the default value of this limit for new accounts
- def_warning_threshold (int) – the default warning threshold, as an integer percentage.
- def_critical_threshold (int) – the default critical threshold, as an integer percentage.
- limit_type –
the type of resource this limit describes, specified as one of the type names used in CloudFormation # noqa such as “AWS::EC2::Instance” or “AWS::RDS::DBSubnetGroup”.
- limit_subtype (str) – resource sub-type for this limit, if applicable, such as “t2.micro” or “SecurityGroup”
- ta_service_name (str) – The service name returned by Trusted Advisor
for this limit, if different from the name of
service
- ta_limit_name (str) – The limit name returned by Trusted Advisor for
this limit, if different from
name
.
Raises: ValueError
-
__module__
= 'awslimitchecker.limit'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
_add_current_usage
(value, resource_id=None, aws_type=None)[source]¶ Add a new current usage value for this limit.
Creates a new
AwsLimitUsage
instance and appends it to the internal list. If more than one usage value is given to this service, they should haveid
andaws_type
set.This method should only be called from the
_AwsService
instance that created and manages this Limit.Parameters: - value (
int
orfloat
) – the numeric usage value - resource_id (str) – If there can be multiple usage values for one limit, an AWS ID for the resource this instance describes
- aws_type (str) –
if
id
is not None, the AWS resource type that ID represents. As a convention, we use the AWS Resource Type names used by CloudFormation # noqa
- value (
-
_get_thresholds
()[source]¶ Get the warning and critical thresholds for this Limit.
Return type is a 4-tuple of:
- warning integer (usage) threshold, or None
- warning percent threshold
- critical integer (usage) threshold, or None
- critical percent threshold
Return type: tuple
-
_set_api_limit
(limit_value)[source]¶ Set the value for the limit as reported by the service’s API.
This method should only be called from the Service class.
Parameters: limit_value (int) – the API limit value
-
_set_ta_limit
(limit_value)[source]¶ Set the value for the limit as reported by Trusted Advisor.
This method should only be called by
TrustedAdvisor
.Parameters: limit_value (int) – the Trusted Advisor limit value
-
_set_ta_unlimited
()[source]¶ Set state to indicate that TrustedAdvisor reports this limit as having no maximum (unlimited).
This method should only be called by
TrustedAdvisor
.
-
check_thresholds
()[source]¶ Check this limit’s current usage against the specified default thresholds, and any custom theresholds that have been set on the class instance. Return True if usage is within thresholds, or false if warning or critical thresholds have been surpassed.
This method sets internal variables in this instance which can be queried via
get_warnings()
andget_criticals()
to obtain further details about the thresholds that were crossed.Note This function returns False if any thresholds were crossed. Please be aware of this when setting threshold overrides to suppress alerts. Each threshold (
warn_percent
,warn_count
,crit_percent
,crit_count
) that has been set is evaluated individually and the result appended to a list of warnings or criticals, respectively. If any of these evaluations failed, the method returns False.Returns: False if any thresholds were crossed, True otherwise Return type: bool
-
get_criticals
()[source]¶ Return a list of
AwsLimitUsage
instances that crossed the critical threshold. These objects are comparable and can be sorted.Return type: list
-
get_current_usage
()[source]¶ Get the current usage for this limit, as a list of
AwsLimitUsage
instances.Returns: list of current usage values Return type: list
ofAwsLimitUsage
-
get_current_usage_str
()[source]¶ Get the a string describing the current usage for this limit.
If no usage has been added for this limit, the result will be “<unknown>”.
If the limit has only one current usage instance, this will be that instance’s
__str__()
value.If the limit has more than one current usage instance, this will be the a string of the form
max: X (Y)
whereX
is the__str__()
value of the instance with the maximum value, andY
is a comma-separated list of the__str__()
values of all usage instances in ascending order.Returns: representation of current usage Return type: str
-
get_limit
()[source]¶ Returns the effective limit value for this Limit, taking into account limit overrides and Trusted Advisor data. None is returned for limits that are explicitly unlimited.
Returns: effective limit value, int
orNone
-
get_limit_source
()[source]¶ Return
SOURCE_DEFAULT
ifget_limit()
returns the default limit,SOURCE_OVERRIDE
if it returns a manually-overridden limit,SOURCE_TA
if it returns a limit from Trusted Advisor, orSOURCE_API
if it returns a limit retrieved from the service’s API.Returns: one of SOURCE_DEFAULT
,SOURCE_OVERRIDE
, orSOURCE_TA
, orSOURCE_API
Return type: int
-
get_warnings
()[source]¶ Return a list of
AwsLimitUsage
instances that crossed the warning threshold. These objects are comparable and can be sorted.Return type: list
-
set_limit_override
(limit_value, override_ta=True)[source]¶ Set a new value for this limit, to override the default (such as when AWS Support has increased a limit of yours). If
override_ta
is True, this value will also supersede any found through Trusted Advisor.Parameters:
-
set_threshold_override
(warn_percent=None, warn_count=None, crit_percent=None, crit_count=None)[source]¶ Override the default warning and critical thresholds used to evaluate this limit’s usage. Theresholds can be specified as a percentage of the limit, or as a usage count, or both.
Note: The percent thresholds (
warn_percent
andcrit_percent
) have default values that are set globally for awslimitchecker, unlike the count thresholds. When setting threshold overrides to quiet or suppress alerts for a limit, you must set the percent thresholds. If you only set overrides for thecount
thresholds, the percent thresholds will continue to be evaluated at their awslimitchecker-wide default, and likely prevent alerts from being suppressed.see
check_thresholds()
for further information on threshold evaluation.Parameters:
-
class
awslimitchecker.limit.
AwsLimitUsage
(limit, value, resource_id=None, aws_type=None)[source]¶ Bases:
object
This object describes the usage of an AWS resource, with the capability of containing information about the resource beyond an integer usage.
The simplest case is an account- / region-wide count, such as the number of running EC2 Instances, in which case a simple integer value is sufficient. In this case, the
AwsLimit
would have one instance of this class for the single value.In more complex cases, such as the “Subnets per VPC”, the limit is applied by AWS on multiple resources (once per VPC). In this case, the
AwsLimit
should have one instance of this class per VPC, so we can determine which VPCs have crossed thresholds.AwsLimitUsage objects are comparable based on their numeric
value
.Parameters: - limit (
AwsLimit
) – the AwsLimit that this instance describes - value (
int
orfloat
) – the numeric usage value - resource_id (str) – If there can be multiple usage values for one limit, an AWS ID for the resource this instance describes
- aws_type (str) –
if
id
is not None, the AWS resource type that ID represents. As a convention, we use the AWS Resource Type names used by CloudFormation # noqa
-
__dict__
= dict_proxy({'__ne__': <function __ne__>, '__module__': 'awslimitchecker.limit', '__weakref__': <attribute '__weakref__' of 'AwsLimitUsage' objects>, '__str__': <function __str__>, 'get_value': <function get_value>, '__init__': <function __init__>, '__gt__': <function __gt__>, '__dict__': <attribute '__dict__' of 'AwsLimitUsage' objects>, '__lt__': <function __lt__>, '__eq__': <function __eq__>, '__doc__': None, '__ge__': <function __ge__>})¶
-
__init__
(limit, value, resource_id=None, aws_type=None)[source]¶ This object describes the usage of an AWS resource, with the capability of containing information about the resource beyond an integer usage.
The simplest case is an account- / region-wide count, such as the number of running EC2 Instances, in which case a simple integer value is sufficient. In this case, the
AwsLimit
would have one instance of this class for the single value.In more complex cases, such as the “Subnets per VPC”, the limit is applied by AWS on multiple resources (once per VPC). In this case, the
AwsLimit
should have one instance of this class per VPC, so we can determine which VPCs have crossed thresholds.AwsLimitUsage objects are comparable based on their numeric
value
.Parameters: - limit (
AwsLimit
) – the AwsLimit that this instance describes - value (
int
orfloat
) – the numeric usage value - resource_id (str) – If there can be multiple usage values for one limit, an AWS ID for the resource this instance describes
- aws_type (str) –
if
id
is not None, the AWS resource type that ID represents. As a convention, we use the AWS Resource Type names used by CloudFormation # noqa
- limit (
-
__module__
= 'awslimitchecker.limit'¶
-
__str__
()[source]¶ Return a string representation of this object.
If
id
is not set, returnvalue
formatted as a string; otherwise, return a string of the formatid=value
.Return type: str
-
__weakref__
¶ list of weak references to the object (if defined)
- limit (
-
awslimitchecker.limit.
SOURCE_API
= 3¶ indicates a limit value that came from the service’s API
-
awslimitchecker.limit.
SOURCE_DEFAULT
= 0¶ indicates a limit value that came from hard-coded defaults in awslimitchecker
-
awslimitchecker.limit.
SOURCE_OVERRIDE
= 1¶ indicates a limit value that came from user-defined limit overrides
-
awslimitchecker.limit.
SOURCE_TA
= 2¶ indicates a limit value that came from Trusted Advisor