当前位置: 首页>>代码示例>>Python>>正文


Python CloudWatchConnection.put_metric_data方法代码示例

本文整理汇总了Python中boto.ec2.cloudwatch.CloudWatchConnection.put_metric_data方法的典型用法代码示例。如果您正苦于以下问题:Python CloudWatchConnection.put_metric_data方法的具体用法?Python CloudWatchConnection.put_metric_data怎么用?Python CloudWatchConnection.put_metric_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto.ec2.cloudwatch.CloudWatchConnection的用法示例。


在下文中一共展示了CloudWatchConnection.put_metric_data方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AWSSendStatusSDK

# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import put_metric_data [as 别名]
def AWSSendStatusSDK(service):
  """Send status to AWS using SDK
  pip install boto"""
  status = service[1]
  service_name = service[0]

  cwc = CloudWatchConnection(aws_access_key_id, \
      aws_secret_access_key)
  if status:
    value = 1
  else:
    value = 0

  cwc.put_metric_data(namespace, name = service_name, value = str(value))
开发者ID:cbiphuk,项目名称:python,代码行数:16,代码来源:service_monitoring.py

示例2: put_cloudwatch_metric_data

# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import put_metric_data [as 别名]
def put_cloudwatch_metric_data(name, value, unit, namespace,
                               use_autoscaling_group=True):
    # TODO: Make this more efficient? There are some uses of this function that
    # call it multiple times in succession -- should there be a batch mode?

    dimensions = None
    if use_autoscaling_group:
        autoscaling_group = _get_autoscaling_group()
        dimensions = { 'AutoScalingGroupName': autoscaling_group } if autoscaling_group else None

    cloudwatch = CloudWatchConnection()
    cloudwatch.put_metric_data(namespace,
                               name,
                               value,
                               unit=unit,
                               dimensions=dimensions)
开发者ID:PowerOlive,项目名称:mail-responder,代码行数:18,代码来源:aws_helpers.py

示例3: main

# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import put_metric_data [as 别名]
def main():
    queues = os.getenv('RABBITMQ_CLOUWATCH_QUEUES', '').split(',')
    aws_access_key_id = os.getenv('AWS_ACCESS_KEY_ID')
    aws_secret_access_key = os.getenv('AWS_SECRET_ACCESS_KEY')
    cloudwatch_namespace = os.getenv(
        'RABBITMQ_CLOUWATCH_NAMESPACE', 'rabbitmq_cloudwatch')

    if not queues or not queues[0]:
        raise RabbitmqCloudwatchException('Queues may not be empty')

    broker_url = os.getenv('RABBITMQ_HTTP_URL')

    if not broker_url:
        raise RabbitmqCloudwatchException('Invalid URL')

    broker_url = urlparse(broker_url)

    if not all([
            broker_url.hostname, broker_url.username, broker_url.password]):
        raise RabbitmqCloudwatchException('Invalid URL')

    if not all([aws_access_key_id, aws_secret_access_key]):
        raise RabbitmqCloudwatchException('Invalid AWS Credentials')

    cwc = CloudWatchConnection(aws_access_key_id, aws_secret_access_key)

    for queue in queues:

        response = requests.get(broker_url.geturl() + queue)

        if response.status_code == 200:
            queue_messages = response.json()['messages']

            print 'Queue {} currently has {} messages'.format(
                queue, queue_messages)

            cwc.put_metric_data(cloudwatch_namespace, queue, queue_messages)
        else:
            raise RabbitmqCloudwatchException(
                'Unable to fetch queue {} from url: {}. '
                'Error: {}={}'.format(
                    queue,
                    broker_url.geturl() + queue,
                    response.status_code,
                    response.reason))
开发者ID:brockhaywood,项目名称:rabbitmq_cloudwatch,代码行数:47,代码来源:rabbitmq_cloudwatch.py

示例4: BotoWatchInterface

# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import put_metric_data [as 别名]
class BotoWatchInterface(WatchInterface):
    conn = None
    saveclcdata = False

    def __init__(self, clc_host, access_id, secret_key, token):
        #boto.set_stream_logger('foo')
        path='/services/CloudWatch'
        port=8773
        if clc_host[len(clc_host)-13:] == 'amazonaws.com':
            clc_host = clc_host.replace('ec2', 'monitoring', 1)
            path = '/'
            reg = None
            port=443
        reg = RegionInfo(name='eucalyptus', endpoint=clc_host)
        if boto.__version__ < '2.6':
            self.conn = CloudWatchConnection(access_id, secret_key, region=reg,
                                  port=port, path=path,
                                  is_secure=True, security_token=token, debug=0)
        else:
            self.conn = CloudWatchConnection(access_id, secret_key, region=reg,
                                  port=port, path=path, validate_certs=False,
                                  is_secure=True, security_token=token, debug=0)
        self.conn.http_connection_kwargs['timeout'] = 30

    def __save_json__(self, obj, name):
        f = open(name, 'w')
        json.dump(obj, f, cls=BotoJsonWatchEncoder, indent=2)
        f.close()

    def get_metric_statistics(self, period, start_name, end_time, metric_name, namespace, statistics, dimensions, unit):
        obj = self.conn.get_metric_statistics(period, start_name, end_time, metric_name, namespace, statistics, dimensions, unit)
        if self.saveclcdata:
            self.__save_json__(obj, "mockdata/CW_Statistics.json")
        return obj

    def list_metrics(self, next_token, dimensions, metric_name, namespace):
        obj = self.conn.list_metrics(next_token, dimensions, metric_name, namespace)
        if self.saveclcdata:
            self.__save_json__(obj, "mockdata/CW_Metrics.json")
        return obj

    def put_metric_data(self, namespace, name, value, timestamp, unit, dimensions, statistics):
        return self.conn.put_metric_data(namespace, name, value, timestamp, unit, dimensions, statistics)
开发者ID:NalaGinrut,项目名称:eucalyptus,代码行数:45,代码来源:botowatchinterface.py

示例5: BotoWatchInterface

# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import put_metric_data [as 别名]
class BotoWatchInterface(WatchInterface):
    conn = None
    saveclcdata = False

    def __init__(self, clc_host, access_id, secret_key, token):
        # boto.set_stream_logger('foo')
        path = "/services/CloudWatch"
        port = 8773
        if clc_host[len(clc_host) - 13 :] == "amazonaws.com":
            clc_host = clc_host.replace("ec2", "monitoring", 1)
            path = "/"
            reg = None
            port = 443
        reg = RegionInfo(name="eucalyptus", endpoint=clc_host)
        self.conn = CloudWatchConnection(
            access_id, secret_key, region=reg, port=port, path=path, is_secure=True, security_token=token, debug=0
        )
        self.conn.https_validate_certificates = False
        self.conn.http_connection_kwargs["timeout"] = 30

    def __save_json__(self, obj, name):
        f = open(name, "w")
        json.dump(obj, f, cls=BotoJsonWatchEncoder, indent=2)
        f.close()

    def get_metric_statistics(self, period, start_name, end_time, metric_name, namespace, statistics, dimensions, unit):
        obj = self.conn.get_metric_statistics(
            period, start_name, end_time, metric_name, namespace, statistics, dimensions, unit
        )
        if self.saveclcdata:
            self.__save_json__(obj, "mockdata/CW_Statistics.json")
        return obj

    def list_metrics(self, next_token=None, dimensions=None, metric_name=None, namespace=None):
        obj = self.conn.list_metrics(next_token, dimensions, metric_name, namespace)
        if self.saveclcdata:
            self.__save_json__(obj, "mockdata/CW_Metrics.json")
        return obj

    def put_metric_data(self, namespace, name, value, timestamp, unit, dimensions, statistics):
        return self.conn.put_metric_data(namespace, name, value, timestamp, unit, dimensions, statistics)

    def describe_alarms(
        self,
        action_prefix=None,
        alarm_name_prefix=None,
        alarm_names=None,
        max_records=None,
        state_value=None,
        next_token=None,
    ):
        obj = self.conn.describe_alarms(
            action_prefix, alarm_name_prefix, alarm_names, max_records, state_value, next_token
        )
        if self.saveclcdata:
            self.__save_json__(obj, "mockdata/CW_Alarms.json")
        return obj

    def delete_alarms(self, alarm_names):
        return self.conn.delete_alarms(alarm_names)

    def enable_alarm_actions(self, alarm_names):
        return self.conn.enable_alarm_actions(alarm_names)

    def disable_alarm_actions(self, alarm_names):
        return self.conn.disable_alarm_actions(alarm_names)

    def put_metric_alarm(self, alarm):
        return self.conn.put_metric_alarm(alarm)
开发者ID:remtcs,项目名称:eucalyptus,代码行数:71,代码来源:botowatchinterface.py

示例6: __init__

# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import put_metric_data [as 别名]

#.........这里部分代码省略.........

		names.append("pgbouncer_sv_tested")
		values.append(float(pools[5]))
		units.append("Count")

		names.append("pgbouncer_sv_login")
		values.append(float(pools[6]))
		units.append("Count")

		names.append("pgbouncer_maxwait")
		values.append(float(pools[7]))
		units.append("Count")

		return [names, values, units, dimensions]

	def put(self):
		result = False
		try:
			# only monitor if we are told to (this will break, if not set)
			monitoring = self.userdata['monitoring']
		except:
			monitoring = 'on'

		if monitoring in ['on', 'all']:
			# first get all we need
			[names, values, units, dimensions] = self.collect(monitoring)
			while len(names) > 0:
				names20 = names[:20]
				values20 = values[:20]
				units20 = units[:20]

				# we can't send all at once, only 20 at a time
				# first aggregated over all
				result = self.cloudwatch.put_metric_data(self.namespace,
								names20, value=values20, unit=units20)
				for dimension in dimensions:
					dimension = { dimension : dimensions[dimension] }
					result &= self.cloudwatch.put_metric_data(
								self.namespace, names20, value=values20,
								unit=units20, dimensions=dimension)

				del names[:20]
				del values[:20]
				del units[:20]
		else:
			print "we are not monitoring"

		return result
	
	def metrics(self):
		return self.cloudwatch.list_metrics()

	def _get_nr_wal_files(self):
		try:
			cursor = self.connection.cursor()

			sql = "select count(name) from (select pg_ls_dir('pg_xlog') as name) as xlogs where name != 'archive_status'"
			cursor.execute(sql)
			
			[size] = cursor.fetchone()
		finally:
			cursor.close()

		return size

	def _get_tables_size(self, connection):
开发者ID:9apps,项目名称:pgRDS,代码行数:70,代码来源:monitor.py

示例7: test_put_metric_data

# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import put_metric_data [as 别名]
 def test_put_metric_data(self):
     c = CloudWatchConnection()
     now = datetime.datetime.now()
     name, namespace = 'unit-test-metric', 'boto-unit-test'
     c.put_metric_data(namespace, name, 5, now, 'Bytes')
开发者ID:der4im,项目名称:boto,代码行数:7,代码来源:test_connection.py

示例8: __init__

# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import put_metric_data [as 别名]

#.........这里部分代码省略.........
		units.append('Count')

		#
		names.append('loading')
		values.append(items['loading'])
		units.append('Count')

		names.append('bgsave_in_progress')
		values.append(items['bgsave_in_progress'])
		units.append('Count')

		# clients
		names.append('connected_clients')
		values.append(items['connected_clients'])
		units.append('Count')

		names.append('blocked_clients')
		values.append(items['blocked_clients'])
		units.append('Count')

		# connection/command totals
		#names.append('total_connections_received')
		#values.append(items['total_connections_received'])
		#units.append('Count')

		#names.append('total_commands_processed')
		#values.append(items['total_commands_processed'])
		#units.append('Count')

		# client input/output
		names.append('client_biggest_input_buf')
		values.append(items['client_biggest_input_buf'])
		units.append('Bytes')

		names.append('client_longest_output_list')
		values.append(items['client_longest_output_list'])
		units.append('Bytes')

		# keys
		names.append('expired_keys')
		values.append(items['expired_keys'])
		units.append('Count')

		names.append('evicted_keys')
		values.append(items['evicted_keys'])
		units.append('Count')

		# last_save
		names.append('changes_since_last_save')
		values.append(items['changes_since_last_save'])
		units.append('Count')

		# keyspace
		#names.append('keyspace_misses')
		#values.append(items['keyspace_misses'])
		#units.append('Count')

		#names.append('keyspace_hits')
		#values.append(items['keyspace_hits'])
		#units.append('Count')

		return [names, values, units, dimensions]

	def put(self):
		result = False
		try:
			# only monitor if we are told to (this will break, if not set)
			monitoring = self.userdata['monitoring']
		except:
			monitoring = 'on'

		if monitoring in ['on', 'all']:
			# first get all we need
			[names, values, units, dimensions] = self.collect(monitoring)
			print [names, values, units, dimensions]
			while len(names) > 0:
				names20 = names[:20]
				values20 = values[:20]
				units20 = units[:20]

				# we can't send all at once, only 20 at a time
				# first aggregated over all
				result = self.cloudwatch.put_metric_data(self.namespace,
								names20, value=values20, unit=units20)
				for dimension in dimensions:
					dimension = { dimension : dimensions[dimension] }
					result &= self.cloudwatch.put_metric_data(
								self.namespace, names20, value=values20,
								unit=units20, dimensions=dimension)

				del names[:20]
				del values[:20]
				del units[:20]
		else:
			print "we are not monitoring"

		return result
	
	def metrics(self):
		return self.cloudwatch.list_metrics()
开发者ID:9apps,项目名称:ReDiS,代码行数:104,代码来源:monitor.py

示例9: __init__

# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import put_metric_data [as 别名]

#.........这里部分代码省略.........
		values.append(items['used_memory_rss'])
		units.append('Bytes')

		names.append('mem_fragmentation_ratio')
		values.append(items['mem_fragmentation_ratio'])
		units.append('None')

		names.append('connected_slaves')
		values.append(items['connected_slaves'])
		units.append('Count')

		#
		names.append('loading')
		values.append(items['loading'])
		units.append('Count')

		names.append('bgsave_in_progress')
		values.append(items['bgsave_in_progress'])
		units.append('Count')

		# clients
		names.append('connected_clients')
		values.append(items['connected_clients'])
		units.append('Count')

		names.append('blocked_clients')
		values.append(items['blocked_clients'])
		units.append('Count')

		# connection/command totals
		names.append('total_connections_received')
		values.append(items['total_connections_received'])
		units.append('Count')

		names.append('total_commands_processed')
		values.append(items['total_commands_processed'])
		units.append('Count')

		# client input/output
		names.append('client_biggest_input_buf')
		values.append(items['client_biggest_input_buf'])
		units.append('Bytes')

		names.append('client_longest_output_list')
		values.append(items['client_longest_output_list'])
		units.append('Bytes')

		# keys
		names.append('expired_keys')
		values.append(items['expired_keys'])
		units.append('Count')

		names.append('evicted_keys')
		values.append(items['evicted_keys'])
		units.append('Count')

		# last_save
		names.append('changes_since_last_save')
		values.append(items['changes_since_last_save'])
		units.append('Count')

		# keyspace
		names.append('keyspace_misses')
		values.append(items['keyspace_misses'])
		units.append('Count')

		names.append('keyspace_hits')
		values.append(items['keyspace_hits'])
		units.append('Count')

		return [names, values, units, dimensions]

	def put(self):
		# first get all we need
		[names, values, units, dimensions] = self.collect()
		while len(names) > 0:
			names20 = names[:20]
			values20 = values[:20]
			units20 = units[:20]

			# we can't send all at once, only 20 at a time
			# first aggregated over all
			self.__log('put aggregated ReDiS metrics data', 'info')
			result = self.cloudwatch.put_metric_data(self.namespace,
									names20, value=values20, unit=units20)
			for dimension in dimensions:
				self.__log('put ReDiS metrics data for {0}'.format(dimensions[dimension]), 'info')
				dimension = { dimension : dimensions[dimension] }
				result &= self.cloudwatch.put_metric_data(self.namespace,
									names20, value=values20, unit=units20,
									dimensions=dimension)

			del names[:20]
			del values[:20]
			del units[:20]

		return result
	
	def metrics(self):
		return self.cloudwatch.list_metrics()
开发者ID:numan,项目名称:ReDiS,代码行数:104,代码来源:monitor.py

示例10: ArgumentParser

# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import put_metric_data [as 别名]
#!/usr/bin/env python3
__author__ = 'shiroyp'
from urllib.request import urlopen
from boto.ec2.cloudwatch import CloudWatchConnection
from argparse import ArgumentParser
import csv
import io

parser = ArgumentParser(description='Converts the currency as per current exchange rate')
parser.add_argument('-f', '--from', default='EUR')
parser.add_argument('-t', '--to', default='INR')
parser.add_argument('--version', action='version', version='%(prog)s 1.0')
args = (vars(parser.parse_args()))
from_currency = args['from']
to_currency = args['to']

URL = 'http://download.finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=' + from_currency + to_currency +'=X'
webpage = urlopen(URL)
datareader = csv.reader(io.TextIOWrapper(webpage))
# readdata = webpage.read()
# csvdata = csv.reader(readdata.decode())
for row in datareader:
    #print ('1 %s = %s %s' % (from_currency, row[1], to_currency))
    rate = float(row[1])


cwc = CloudWatchConnection()
cwc.put_metric_data(namespace="ExchangeRate",name=from_currency+"-to-"+to_currency,unit="None",value=rate)
开发者ID:shiroyp,项目名称:Exchange-Rate-Reporter,代码行数:30,代码来源:exchange_rate_reporter_cloudwatch.py


注:本文中的boto.ec2.cloudwatch.CloudWatchConnection.put_metric_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。