|
| 1 | +""" |
| 2 | +Create a new dashboard with timeseries widget with custom_unit |
| 3 | +""" |
| 4 | + |
| 5 | +from datadog_api_client import ApiClient, Configuration |
| 6 | +from datadog_api_client.v1.api.dashboards_api import DashboardsApi |
| 7 | +from datadog_api_client.v1.model.dashboard import Dashboard |
| 8 | +from datadog_api_client.v1.model.dashboard_layout_type import DashboardLayoutType |
| 9 | +from datadog_api_client.v1.model.dashboard_reflow_type import DashboardReflowType |
| 10 | +from datadog_api_client.v1.model.formula_and_function_metric_data_source import FormulaAndFunctionMetricDataSource |
| 11 | +from datadog_api_client.v1.model.formula_and_function_metric_query_definition import ( |
| 12 | + FormulaAndFunctionMetricQueryDefinition, |
| 13 | +) |
| 14 | +from datadog_api_client.v1.model.formula_and_function_response_format import FormulaAndFunctionResponseFormat |
| 15 | +from datadog_api_client.v1.model.number_format_unit_canonical import NumberFormatUnitCanonical |
| 16 | +from datadog_api_client.v1.model.number_format_unit_scale import NumberFormatUnitScale |
| 17 | +from datadog_api_client.v1.model.number_format_unit_scale_type import NumberFormatUnitScaleType |
| 18 | +from datadog_api_client.v1.model.timeseries_widget_definition import TimeseriesWidgetDefinition |
| 19 | +from datadog_api_client.v1.model.timeseries_widget_definition_type import TimeseriesWidgetDefinitionType |
| 20 | +from datadog_api_client.v1.model.timeseries_widget_legend_layout import TimeseriesWidgetLegendLayout |
| 21 | +from datadog_api_client.v1.model.timeseries_widget_request import TimeseriesWidgetRequest |
| 22 | +from datadog_api_client.v1.model.widget import Widget |
| 23 | +from datadog_api_client.v1.model.widget_display_type import WidgetDisplayType |
| 24 | +from datadog_api_client.v1.model.widget_formula import WidgetFormula |
| 25 | +from datadog_api_client.v1.model.widget_layout import WidgetLayout |
| 26 | +from datadog_api_client.v1.model.widget_legacy_live_span import WidgetLegacyLiveSpan |
| 27 | +from datadog_api_client.v1.model.widget_number_format import WidgetNumberFormat |
| 28 | +from datadog_api_client.v1.model.widget_text_align import WidgetTextAlign |
| 29 | + |
| 30 | +body = Dashboard( |
| 31 | + title="Example-Dashboard", |
| 32 | + description="", |
| 33 | + widgets=[ |
| 34 | + Widget( |
| 35 | + definition=TimeseriesWidgetDefinition( |
| 36 | + title="", |
| 37 | + title_size="16", |
| 38 | + title_align=WidgetTextAlign.LEFT, |
| 39 | + show_legend=True, |
| 40 | + legend_layout=TimeseriesWidgetLegendLayout.AUTO, |
| 41 | + time=WidgetLegacyLiveSpan(), |
| 42 | + type=TimeseriesWidgetDefinitionType.TIMESERIES, |
| 43 | + requests=[ |
| 44 | + TimeseriesWidgetRequest( |
| 45 | + formulas=[ |
| 46 | + WidgetFormula( |
| 47 | + formula="query1", |
| 48 | + number_format=WidgetNumberFormat( |
| 49 | + unit_scale=NumberFormatUnitScale( |
| 50 | + type=NumberFormatUnitScaleType.CANONICAL_UNIT, |
| 51 | + unit_name="apdex", |
| 52 | + ), |
| 53 | + unit=NumberFormatUnitCanonical( |
| 54 | + type=NumberFormatUnitScaleType.CANONICAL_UNIT, |
| 55 | + unit_name="fraction", |
| 56 | + ), |
| 57 | + ), |
| 58 | + ), |
| 59 | + ], |
| 60 | + queries=[ |
| 61 | + FormulaAndFunctionMetricQueryDefinition( |
| 62 | + data_source=FormulaAndFunctionMetricDataSource.METRICS, |
| 63 | + name="query1", |
| 64 | + query="avg:system.cpu.user{*}", |
| 65 | + ), |
| 66 | + ], |
| 67 | + response_format=FormulaAndFunctionResponseFormat.TIMESERIES, |
| 68 | + display_type=WidgetDisplayType.LINE, |
| 69 | + ), |
| 70 | + ], |
| 71 | + ), |
| 72 | + layout=WidgetLayout( |
| 73 | + x=0, |
| 74 | + y=0, |
| 75 | + width=12, |
| 76 | + height=5, |
| 77 | + ), |
| 78 | + ), |
| 79 | + ], |
| 80 | + template_variables=[], |
| 81 | + layout_type=DashboardLayoutType.ORDERED, |
| 82 | + notify_list=[], |
| 83 | + reflow_type=DashboardReflowType.FIXED, |
| 84 | +) |
| 85 | + |
| 86 | +configuration = Configuration() |
| 87 | +with ApiClient(configuration) as api_client: |
| 88 | + api_instance = DashboardsApi(api_client) |
| 89 | + response = api_instance.create_dashboard(body=body) |
| 90 | + |
| 91 | + print(response) |
0 commit comments