本文整理汇总了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))
示例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)
示例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))
示例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)
示例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)
示例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):
示例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')
示例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()
示例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()
示例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)