How to use put_dashboard method in localstack

Best Python code snippet using localstack_python

add_xqueue_to_dashboard.py

Source:add_xqueue_to_dashboard.py Github

copy

Full Screen

...18 return self.client.list_metrics(*args, **kwargs)19 @backoff.on_exception(backoff.expo,20 (botocore.exceptions.ClientError),21 max_tries=MAX_TRIES)22 def put_dashboard(self, *args, **kwargs):23 return self.client.put_dashboard(*args, **kwargs)24def generate_dashboard_widget_metrics(25 cloudwatch,26 namespace,27 metric_name,28 dimension_name,29 properties={},30 right_axis_items=[]31):32 pp = pprint.PrettyPrinter(indent=4)33 metrics = cloudwatch.list_metrics(34 Namespace=namespace, MetricName=metric_name, Dimensions=[{"Name": dimension_name}]35 )36 values = []37 for metric in metrics['Metrics']:38 for dimension in metric['Dimensions']:39 if dimension['Name'] == dimension_name:40 values.append(dimension['Value'])41 values.sort()42 new_widget_metrics = []43 for value in values:44 value_properties = properties.copy()45 value_properties['label'] = value46 if value in right_axis_items:47 value_properties["yAxis"] = "right"48 new_widget_metrics.append([namespace, metric_name, dimension_name, value, value_properties])49 return new_widget_metrics50# * means that all arguments after cloudwatch are keyword arguments only and are not positional51def generate_dashboard_widget(52 cloudwatch,53 *,54 x=0,55 y,56 title,57 namespace,58 metric_name,59 dimension_name,60 metrics_properties={},61 height,62 width=24,63 stacked=False,64 region='us-east-1',65 period=60,66 right_axis_items=[]67):68 return {'type': 'metric', 'height': height, 'width': width, 'x': x, 'y': y,69 'properties': {70 'period': period, 'view': 'timeSeries', 'stacked': stacked, 'region': region,71 'title': "{} (auto-generated)".format(title),72 'metrics': generate_dashboard_widget_metrics(cloudwatch, namespace, metric_name, dimension_name,73 metrics_properties, right_axis_items=right_axis_items)74 }75 }76@click.command()77@click.option('--environment', '-e', required=True)78@click.option('--deploy', '-d', required=True,79 help="Deployment (i.e. edx or stage)")80def generate_dashboard(environment, deploy):81 pp = pprint.PrettyPrinter(indent=4)82 cloudwatch = CwBotoWrapper()83 dashboard_name = "{}-{}-xqueues".format(environment, deploy)84 xqueue_namespace = "xqueue/{}-{}".format(environment, deploy)85 widgets = []86 y_cord = 087 height = 988 if deploy == 'edx' and environment == 'prod':89 y_cord += height90 height = 991 widgets.append(generate_dashboard_widget(cloudwatch, y=y_cord, height=height,92 title="{}-{} Xqueue Queues".format(environment, deploy),93 namespace=xqueue_namespace, metric_name="queue_length",94 dimension_name="queue",95 )96 )97 dashboard_body = {'widgets': widgets}98 print("Dashboard Body")99 pp.pprint(dashboard_body)100 cloudwatch.put_dashboard(DashboardName=dashboard_name,101 DashboardBody=json.dumps(dashboard_body))102if __name__ == '__main__':...

Full Screen

Full Screen

test_dashboard_generator_cloudwatch_put_dashboard.py

Source:test_dashboard_generator_cloudwatch_put_dashboard.py Github

copy

Full Screen

...70 }71 }72 ]73 }74 DashboardGenerator().cloudwatch_put_dashboard()75 assert mock_boto.client.return_value.put_dashboard.called76 mock_boto.client.return_value.put_dashboard.assert_called_with(77 DashboardName=dashboard_name,78 DashboardBody=json.dumps(dashboard_body)79 )80@mock.patch('dashboard_generator.boto3')81def test_cloudwatch_put_dashboard_ensure_exception_is_handled(mock_boto, env_variables):82 mock_boto.client.return_value.put_dashboard.side_effect = botocore.exceptions.ClientError({}, 'foo')83 with pytest.raises(botocore.exceptions.ClientError):84 DashboardGenerator().cloudwatch_put_dashboard()85@mock.patch('dashboard_generator.boto3')86@mock.patch('dashboard_generator.DashboardGenerator._get_pipelines')87@mock.patch('dashboard_generator.DashboardGenerator._generate_widget')88@mock.patch('dashboard_generator.DashboardGenerator._generate_widget_descriptions')89def test_cloudwatch_put_dashboard_ensure_methods_are_called(90 mock_generate_widget_descriptions,91 mock_generate_widget,92 mock_get_pipelines,93 mock_boto,94 env_variables95):96 mock_generate_widget_descriptions.return_value = {}97 mock_generate_widget.return_value = {}98 mock_get_pipelines.return_value = ['foobar']99 DashboardGenerator().cloudwatch_put_dashboard()100 assert mock_boto.client.return_value.put_dashboard.called101 assert mock_get_pipelines.called102 assert mock_generate_widget.called...

Full Screen

Full Screen

dashboard.py

Source:dashboard.py Github

copy

Full Screen

...32 # create a dashboard for high level monitoring of aqts-capture etl33 cloudwatch_client = boto3.client("cloudwatch", region_name=region)34 main_dashboard_body = {'widgets': main_dashboard_widgets}35 main_dashboard_body_json = json.dumps(main_dashboard_body)36 cloudwatch_client.put_dashboard(DashboardName="aqts-capture-etl-" + deploy_stage,37 DashboardBody=main_dashboard_body_json)38 # create a dashboard for monitoring lambda memory usage39 memory_usage_dashboard_body = {'widgets': memory_usage_widgets}40 memory_usage_dashboard_body_json = json.dumps(memory_usage_dashboard_body)41 cloudwatch_client.put_dashboard(DashboardName="aqts-capture-lambda-memory-usage-" + deploy_stage,42 DashboardBody=memory_usage_dashboard_body_json)43 # create a dashboard for monitoring ecosystem switch lambdas44 ecosystem_switch_dashboard_body = {'widgets': ecosystem_switch_widgets}45 ecosystem_switch_dashboard_body_json = json.dumps(ecosystem_switch_dashboard_body)46 cloudwatch_client.put_dashboard(DashboardName="aqts-capture-ecosystem-switch-lambdas-" + deploy_stage,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful