Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
# Note: we don't allow autostacks of Opsworks, so disable warnings about
# `getMatchingResources` not being implemented (disable=W0223 comments below)
from boto.opsworks import layer1
from grok.app.adapters.datasource.cloudwatch.aws_base import (
AWSResourceAdapterBase)
from grok.app.adapters.datasource.cloudwatch.aws_base import ResourceTypeNames
from grok.app.aws.opsworks_utils import retryOnOpsworksTransientError
@AWSResourceAdapterBase.registerResourceAdapter #pylint: disable=W0223
class OpsWorksAdapter(AWSResourceAdapterBase):
RESOURCE_TYPE = ResourceTypeNames.OPSWORKS_STACK
NAMESPACE = "AWS/OpsWorks"
# Cloudwatch metric dimension combinations supported by all metric adapters on
# this resource;
# NOTE: the first dimension name in each group is the dimension that
# identifies the resource
DIMENSION_GROUPS = (("StackId",),)
@retryOnOpsworksTransientError()
def getResourceName(self):
""" Query AWS for the name value of the OpsWorks instance
# Boto doesn't currently support filters for get_all_tags in autoscaling
# groups (not implemented yet). Manually implementing a filter
# http://boto.readthedocs.org/en/2.6.0/ref/autoscale.html
tags = [tag for tag in tags
if tag.resource_type == "auto-scaling-group"
and tag.resource_id == self._dimensions["AutoScalingGroupName"]
and tag.key == "Name"]
if tags:
return tags[0].value
return None
@AWSResourceAdapterBase.registerMetricAdapter #pylint: disable=W0223
class ASGGroupTotalInstancesMetricAdapter(AutoScalingGroupAdapter):
METRIC_NAME = "GroupTotalInstances"
IS_INSTANCE_DEFAULT = True
NAMESPACE = "AWS/AutoScaling"
STATISTIC = "Sum"
UNIT = "None"
# The number of instances may grow a very substantial amount so estimating
# based on a few hundred records may not be very accurate. We pick an
# arbitrary number here instead that should work pretty well in all cases
# (we want a bucket size close to one but any smaller isn't useful).
MIN = 0
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
# Note: we don't allow autostacks of DynamoDB, so disable warnings about
# `getMatchingResources` not being implemented (disable=W0223 comments below)
from boto import dynamodb
from grok.app.adapters.datasource.cloudwatch.aws_base import (
AWSResourceAdapterBase)
from grok.app.adapters.datasource.cloudwatch.aws_base import ResourceTypeNames
@AWSResourceAdapterBase.registerResourceAdapter #pylint: disable=W0223
class DynamoDBTableAdapter(AWSResourceAdapterBase):
RESOURCE_TYPE = ResourceTypeNames.DYNAMODB_TABLE
NAMESPACE = "AWS/DynamoDB"
@classmethod
def describeResources(cls, region):
""" Describe available DynamoDB tables in the given region.
:param region: AWS region
:returns: description of available DynamoDB tables in the given region
::
[
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
# Note: we don't allow autostacks of EBS volumes, so disable warnings about
# `getMatchingResources` not being implemented (disable=W0223 comments below)
from boto import ec2
from grok.app.adapters.datasource.cloudwatch.aws_base import (
AWSResourceAdapterBase)
from grok.app.adapters.datasource.cloudwatch.aws_base import ResourceTypeNames
@AWSResourceAdapterBase.registerResourceAdapter #pylint: disable=W0223
class EBSAdapter(AWSResourceAdapterBase):
RESOURCE_TYPE = ResourceTypeNames.EBS_VOLUME
NAMESPACE = "AWS/EBS"
# Cloudwatch metric dimension combinations supported by all metric adapters on
# this resource;
# NOTE: the first dimension name in each group is the dimension that
# identifies the resource
DIMENSION_GROUPS = (("VolumeId",),)
@classmethod
def describeResources(cls, region):
""" Describe available SNS Topics in the given region.
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
# Note: we don't allow autostacks of ELBs, so disable warnings about
# `getMatchingResources` not being implemented (disable=W0223 comments below)
from grok.app.adapters.datasource.cloudwatch.aws_base import (
AWSResourceAdapterBase, ResourceTypeNames)
from grok.app.aws.elb_utils import getELBInstances
@AWSResourceAdapterBase.registerResourceAdapter #pylint: disable=W0223
class ELBAdapter(AWSResourceAdapterBase):
RESOURCE_TYPE = ResourceTypeNames.ELB_LOAD_BALANCER
NAMESPACE = "AWS/ELB"
# Cloudwatch metric dimension combinations supported by all metric adapters on
# this resource;
# NOTE: the first dimension name in each group is the dimension that
# identifies the resource
DIMENSION_GROUPS = (("LoadBalancerName",),)
def getMetricSummary(self):
""" Get a short description of the metric
NOTE: overrides method in base class
MAX = 100
def getMetricSummary(self):
""" Get a short description of the metric
NOTE: derived classes must override this method
:returns: a short description of the metric
:rtype: string
"""
return ("Amount of free memory for %s in %s"
% (self._dimensions["StackId"], self._region))
@AWSResourceAdapterBase.registerMetricAdapter #pylint: disable=W0223
class OPSMemorySwapMetricAdapter(OpsWorksAdapter):
METRIC_NAME = "memory_swap"
IS_INSTANCE_DEFAULT = True
STATISTIC = "Average"
UNIT = "None"
# default min/max from legacy metric template
MIN = 0
MAX = 100
def getMetricSummary(self):
""" Get a short description of the metric
IS_INSTANCE_DEFAULT = True
# Cloudwatch metric dimension combinations supported by this adapter;
# NOTE: the first dimension name in each group is the dimension that
# identifies the resource
DIMENSION_GROUPS = (("TableName",),)
STATISTIC = "Average"
UNIT = "Count"
MIN = 0
MAX = None
@AWSResourceAdapterBase.registerMetricAdapter #pylint: disable=W0223
class DDBConsumedWriteCapacityUnitsMetricAdapter(DynamoDBTableAdapter):
METRIC_NAME = "ConsumedWriteCapacityUnits"
IS_INSTANCE_DEFAULT = True
# Cloudwatch metric dimension combinations supported by this adapter;
# NOTE: the first dimension name in each group is the dimension that
# identifies the resource
DIMENSION_GROUPS = (("TableName",),)
STATISTIC = "Average"
UNIT = "Count"
MIN = 0
MAX = None
@AWSResourceAdapterBase.registerMetricAdapter
class EC2DiskReadBytesMetricAdapter(InstanceAdapter):
METRIC_NAME = "DiskReadBytes"
STATISTIC = "Average"
UNIT = "Bytes"
# default min/max from legacy metric template
MIN = 0
MAX = 1000000
@AWSResourceAdapterBase.registerMetricAdapter
class EC2DiskWriteBytesMetricAdapter(InstanceAdapter):
METRIC_NAME = "DiskWriteBytes"
IS_INSTANCE_DEFAULT = True
STATISTIC = "Average"
UNIT = "Bytes"
# default min/max from legacy metric template
MIN = 0
MAX = 1000000
def getMetricSummary(self):
""" Get a short description of the metric
NOTE: derived classes must override this method
:returns: a short description of the metric
:rtype: str
"""
return "%s for %s in %s" % (
self.METRIC_NAME, self._dimensions["ClusterIdentifier"], self._region)
@AWSResourceAdapterBase.registerMetricAdapter #pylint: disable=W0223
class RSCDatabaseConnectionsMetricAdapter(RedshiftClusterAdapter):
METRIC_NAME = "DatabaseConnections"
IS_INSTANCE_DEFAULT = True
NAMESPACE = "AWS/Redshift"
STATISTIC = "Sum"
UNIT = "Count"
# default min/max from legacy metric template
MIN = 0
MAX = 500
# ----------------------------------------------------------------------
# Note: we don't allow autostacks of Redshift, so disable warnings about
# `getMatchingResources` not being implemented (disable=W0223 comments below)
import boto.redshift
from grok.app.adapters.datasource.cloudwatch.aws_base import (
AWSResourceAdapterBase)
from grok.app.adapters.datasource.cloudwatch.aws_base import ResourceTypeNames
from grok.app.exceptions import InvalidAWSRegionName
@AWSResourceAdapterBase.registerResourceAdapter #pylint: disable=W0223
class RedshiftClusterAdapter(AWSResourceAdapterBase):
RESOURCE_TYPE = ResourceTypeNames.REDSHIFT_CLUSTER
# Cloudwatch metric dimension combinations supported by all metric adapters
# on this resource;
# NOTE: the first dimension name in each group is the dimension that
# identifies the resource
DIMENSION_GROUPS = (("ClusterIdentifier",),)
@classmethod
def describeResources(cls, region):
""" Describe available Redshift Clusters in the given region.
:param region: AWS region
:returns: description of available Redshift Clusters in the given region