def upload_metrics(self, metrics=None): """Upload metrics to API address. """ count_average_data = metrics['count_average'] probes_per_minute_data = metrics['probes_per_minute'] longest_probe_data = metrics['longest_probe'] api = appoptics_metrics.connect(self.get_api_token()) try: with api.new_queue( tags={'swicloud_sre_solution': 'vladimir_germanov' }) as queue: for data in count_average_data: queue.add(data['name'], data['value']) for data in longest_probe_data: queue.add(data['name'], data['value']) for data in probes_per_minute_data: queue.add(data['name'], data['value'], data['time']) print("Metrics uploaded successfully! Check: {}".format( self.get_dashboard())) except appoptics_metrics.exceptions.Unauthorized as error: print("Authorization failed! Token: {} is not corret!".format( self.get_api_token())) print("Error code: {}".format(error)) except appoptics_metrics.exceptions.Forbidden as error: print("Not allowed operation with TOKEN: {}!".format( self.get_api_token())) print("Error code: {}".format(error))
def setUpClass(cls): """ Auth """ token = os.environ.get('APPOPTICS_TOKEN') assert token, "Must set APPOPTICS_TOKEN to run tests" six.print_("Token: %s" % token) """ Ensure user really wants to run these tests """ are_you_sure = os.environ.get('APPOPTICS_ALLOW_INTEGRATION_TESTS') assert are_you_sure == 'Y', "INTEGRATION TESTS WILL DELETE METRICS " \ "IN YOUR ACCOUNT!!! " \ "If you are absolutely sure that you want to run tests against "\ "the Org with %s, please set APPOPTICS_ALLOW_INTEGRATION_TESTS "\ "to 'Y'" % token """Initialize the APPOPTICS Connection""" cls.conn = appoptics_metrics.connect(token) cls.conn_sanitize = appoptics_metrics.connect(token, sanitizer=appoptics_metrics.sanitize_metric_name)
def test_constructor_tags(self): conn = appoptics_metrics.connect('key_test', tags={'sky': 'blue'}) q = conn.new_queue(tags={'sky': 'red', 'coal': 'black'}) tags = q.get_tags() assert len(tags) == 2 assert 'sky' in tags assert tags['sky'] == 'red' assert 'coal' in tags assert tags['coal'] == 'black'
def setUp(self): self.conn = appoptics_metrics.connect('key_test') self.sample_payload = { 'title': 'Email Ops', 'type': 'mail', 'settings': { 'addresses': '*****@*****.**' } } server.clean()
def test_inherit_connection_level_tags_through_add(self): """test if connection level tags are recognized when using the add function""" conn = appoptics_metrics.connect('key_test', tags={'sky': 'blue', 'company': 'AppOptics'}) q = conn.new_queue() q.add('user_cpu', 100) measurements = q.tagged_chunks[0]['measurements'] assert len(measurements) == 1 assert measurements[0].get('tags', {}) == {'sky': 'blue', 'company': 'AppOptics'}
def _get_appoptics(options): ''' Return an appoptics connection object. ''' conn = appoptics_metrics.connect( options.get('api_token'), sanitizer=appoptics_metrics.sanitize_metric_name, hostname=options.get('api_url')) log.info("Connected to appoptics.") return conn
def test_inherit_queue_level_tags(self): """test if queue level tags are ignored when passing measurement level tags""" conn = appoptics_metrics.connect('key_test') q = conn.new_queue(tags={"service": "api", "hi": "four"}) q.add_tagged('user_cpu', 100, tags={"hi": "five"}, inherit_tags=True) measurements = q.tagged_chunks[0]['measurements'] assert len(measurements) == 1 assert measurements[0].get('tags', {}) == {'service': 'api', 'hi': 'five'}
def _get_appoptics(options): """ Return an appoptics connection object. """ conn = appoptics_metrics.connect( options.get("api_token"), sanitizer=appoptics_metrics.sanitize_metric_name, hostname=options.get("api_url"), ) log.info("Connected to appoptics.") return conn
def test_inherit_connection_level_tags(self): """test if top level tags are ignored when passing measurement level tags""" conn = appoptics_metrics.connect('key_test', tags={'sky': 'blue'}) q = conn.new_queue() q.add_tagged('user_cpu', 10, tags={"hi": "five"}, inherit_tags=True) measurements = q.tagged_chunks[0]['measurements'] assert len(measurements) == 1 assert measurements[0].get('tags', {}) == {'sky': 'blue', 'hi': 'five'}
def init_analytics(): """Initialize the analytics agents with write credentials.""" segment_write_key = getattr(settings, 'SEGMENT_WRITE_KEY', None) appoptics_api_token = getattr(settings, "APPOPTICS_API_TOKEN", None) if segment_write_key: global _segment segment_analytics.write_key = segment_write_key _segment = True if appoptics_api_token: global appoptics_api appoptics_api = appoptics_metrics.connect( appoptics_api_token, sanitizer=sanitize_metric_name)
def test_ignore_connection_queue_level_tags(self): """test if queue level tags are ignored when passing measurement level tags""" conn = appoptics_metrics.connect('key_test', tags={'sky': 'blue'}) q = conn.new_queue(tags={"service": "api"}) q.add_tagged('user_cpu', 10, tags={"hi": "five"}) measurements = q.tagged_chunks[0]['measurements'] assert len(measurements) == 1 assert measurements[0].get('tags', {}) == {'hi': 'five'} q.submit() resp = self.conn.get_tagged('user_cpu', duration=60, tags_search="sky=blue") assert len(resp['series']) == 0
def test_inherited_tags(self): conn = appoptics_metrics.connect('key_test', tags={'sky': 'blue'}) assert conn.get_tags() == {'sky': 'blue'} q = conn.new_queue() q.add_tagged('user_cpu', 10) q.submit() # Measurement must inherit 'sky' tag from connection resp = self.conn.get_tagged('user_cpu', duration=60, tags_search="sky=blue") assert len(resp['series']) == 1 assert resp['series'][0].get('tags', {}) == conn.get_tags() measurements = resp['series'][0]['measurements'] assert len(measurements) == 1 assert measurements[0]['value'] == 10
def setUp(self): self.conn = appoptics_metrics.connect('key_test', tags={'sky': 'blue'}) server.clean()
# Setup global stuff: logger = logging.getLogger('freezer') logger.setLevel(logging.getLevelName(config.LOGLEVEL)) # create console handler and add a formatter: ch = logging.StreamHandler() formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') # add formatter to ch ch.setFormatter(formatter) # add ch to logger logger.addHandler(ch) ao = appoptics_metrics.connect(config.APPOPTICS_KEY, tags={'ENVIRONMENT': "prod"}) freezer = Freezer(config.GPIO_PINS["COMP_PIN"]) def send_metrics(freezer): if config.APPOPTICS_KEY: metrics.send_ao_metrics(freezer) if config.INFLUXDB["ENABLED"]: metrics.send_influx_metrics(freezer) def main(freezer): logger.debug("Starting Main function") freezer.get_temperature() logger.debug("Current temperature 1: %.2f" % freezer.TEMP1) logger.debug("Current temperature 2: %.2f" % freezer.TEMP2)
def setUp(self): self.conn = appoptics_metrics.connect('key_test') self.name = 'my_alert' server.clean()
print(str(E)) if ctx['args'].submit_data: exit(1) # # All data processing cycles have their own # exception handling fo non-fatal errors # to aviod whole process interrupt in case of # malformed data item, rate limit firing, etc. # try: # # Setup API service connection, and authenticate against it # oApiConnection = appoptics_metrics.connect(ctx['args'].api_token) # # If charts data loaded uccessfully, # and we have to setup charts - # get the space, and perform setup # if ctx['charts'] and ctx['args'].space_name and ctx['args'].setup_charts: oSpace = oApiConnection.find_space( ctx['args'].space_name) or oApiConnection.create_space( ctx['args'].space_name) lib.charts.setup_charts(oApiConnection, oSpace, ctx['charts']) # # Perform submission, if probes data loaded successfully, # and we have to submit it
def setUp(self): self.conn = appoptics_metrics.connect('key_test', tags={"region": "us-east-1"}) server.clean()
def setUp(self): self.conn = appoptics_metrics.connect('key_test')
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Simple app to feed clock with temperatures """ import time import redis import appoptics_metrics appoptics = appoptics_metrics.connect( 'EcsOPd_2vCayhMCZp9hcNpYyftiH5E9RlZyEyzZ56QpKhTtQ2acWhansMD3u8Pw8Zg_QIgw', sanitizer=appoptics_metrics.sanitize_metric_name) redis = redis.Redis(host='localhost', port=6379, db=0, decode_responses=True) while True: try: temp_outside_data = appoptics.get_measurements( "temperature", duration=900, resolution=1, tags={ 'building': 'terspelt', 'location': 'outside' }) temp_float = temp_outside_data.get('series')[0].get('measurements')[0].get('value') temp = int(round(temp_float, 0)) redis_temp = f'{temp:-2}' redis.set('temp_outside', redis_temp)
def setUp(self): self.conn = appoptics_metrics.connect('key_test') server.clean() self.agg = Aggregator(self.conn)
def setUp(self): self.conn = appoptics_metrics.connect('key_test') mock_connection.server.clean()
def setUp(self): self.conn = appoptics_metrics.connect('key_test') server.clean() self.q = self.conn.new_queue()