def test_cli_create_force_success(): program = Data('cpu.utilization').publish() chart = TimeSeriesChart().with_name('lol').with_program(program) with global_recorder.use_cassette('cli_create_force_success', serialize_with='prettyjson'): dashboard = Dashboard(session=global_session)\ .with_name('testy mctesterson')\ .with_charts(chart) cli = CliBuilder().with_resources(dashboard).build() runner = CliRunner() result = runner.invoke(cli, args=['--api-key', 'foo', 'create', '-f']) assert result.exit_code == 0
def test_cli_create_interactive_failure(sfx_recorder, session): program = Data('cpu.utilization').publish() chart = TimeSeriesChart().with_name('lol').with_program(program) with sfx_recorder.use_cassette('cli_create_interactive_failure', serialize_with='prettyjson'): dashboard = Dashboard(session=session)\ .with_name('testy mctesterson')\ .with_charts(chart) cli = CliBuilder().with_resources(dashboard).build() runner = CliRunner() result = runner.invoke(cli, args=['--api-key', 'foo', 'create', '-i'], input='n') click.echo(result.exception) assert result.exception
app_filter = DashboardFilters() \ .with_time(time) dashboard_with_time_as_integer_filter = Dashboard()\ .with_name('Dashboard With Time as Integer Filter')\ .with_charts(chart)\ .with_filters(app_filter) """ Example 6: Update an existing Dashboard by removing one of the filters """ app_filter = DashboardFilters().with_variables(app_var) dashboard_remove_filter = Dashboard()\ .with_name('Dashboard With Multiple Filters')\ .with_charts(chart)\ .with_filters(app_filter) if __name__ == '__main__': from signal_analog.cli import CliBuilder cli = CliBuilder().with_resources(dashboard_with_single_filter_variable, dashboard_with_multiple_filter_variables, dashboard_with_source_filter, dashboard_with_time_as_string_filter, dashboard_with_time_as_integer_filter, dashboard_remove_filter)\ .build() cli()
Example 2: make a re-usable chart (or template) This is useful when you want your chart to be broadly applicable/used by others """ class UserCpuUsedPercentChart(TimeSeriesChart): def __init__(self, app, env='prod'): super(UserCpuUsedPercentChart, self).__init__() self.with_name('CPU Used % from template class') self.with_description( '% CPU used by type (user, system, i/o, stolen, etc)') self.stack_chart(True) self.with_default_plot_type(PlotType.area_chart) self.with_program(self.__program__(app, env)) self.with_publish_label_options( PublishLabelOptions('A', 0, PaletteColor.hot_pink, PlotType.area_chart, 'User CPU %')) def __program__(self, app, env): app_filter = And(Filter('app', 'my-app'), Filter('env', 'prod')) return Program(Data('cpu.user', filter=app_filter).mean().publish('A')) chart_from_templ = UserCpuUsedPercentChart('my-app') if __name__ == '__main__': from signal_analog.cli import CliBuilder cli = CliBuilder().with_resources(chart, chart_from_templ).build() cli()
dashboard_with_multiple_charts = Dashboard()\ .with_name('Dashboard With Multiple Charts')\ .with_charts(chart, chart1, chart2) """ Example 3: Update existing dashboard by removing one of the charts """ dashboard_remove_chart = Dashboard()\ .with_name('Dashboard Name')\ .with_charts(chart, chart1) """ Example 3: Rename and existing chart """ chart1 = TimeSeriesChart()\ .with_name('Chart_Name_Renamed')\ .with_program(program) dashboard_rename_chart = Dashboard()\ .with_name('Dashboard Name')\ .with_charts(chart, chart1) if __name__ == '__main__': from signal_analog.cli import CliBuilder cli = CliBuilder().with_resources(dashboard_with_single_chart, dashboard_with_multiple_charts, dashboard_remove_chart, dashboard_rename_chart)\ .build() cli()
.with_rules(info_rule) """ Example 2: from an existing chart This is useful when you want to alert on behavior seen in a chart that was created using the signal_analog library. """ test_program = Program(data) chart = TimeSeriesChart()\ .with_name('TEST: example chart for detector')\ .with_program(test_program) # Defined above def detector_helper(prog): d = prog.find_label('A') return Program(Detect(LT(d, 1)).publish(alert_label)) c_detector = Detector()\ .with_name('TEST: example detector from chart')\ .from_chart(chart, detector_helper)\ .with_rules(info_rule) if __name__ == '__main__': from signal_analog.cli import CliBuilder cli = CliBuilder().with_resources(detector, c_detector).build() cli()
from signal_analog.charts import TimeSeriesChart from signal_analog.dashboards import Dashboard, DashboardGroup from signal_analog.combinators import And """ Creating a new Dashboard Group with Dashboards """ filters = And(Filter('host', 'learn-signalfx')) program = Data('cpu.utilization', filter=filters).publish() cpu_chart = TimeSeriesChart().with_name('CPU').with_program(program) program = Data('postgres_query_time', rollup='rate', filter=filters).publish() query_time = TimeSeriesChart().with_name('Query Time').with_program(program) program = Data('memory.utilization', filter=filters).publish() memory_chart = TimeSeriesChart().with_name('Memory').with_program(program) dashboard1 = Dashboard().with_name('Dashboard 1').with_charts( query_time, cpu_chart, memory_chart) dashboard_group = DashboardGroup() \ .with_name('Learn Signal Analog') \ .with_dashboards(dashboard1) if __name__ == '__main__': from signal_analog.cli import CliBuilder cli = CliBuilder().with_resources(dashboard_group)\ .build() cli()
.with_time(FilterTime().with_start("-7d").with_end("Now")) ) if __name__ == '__main__': dashboards = [] dashboards.append( create_pipeline_dashboard("My Data Pipeline Dashboard", [ AwsResouce(AwsResourceType.SqsQueue, 'some-queue', 'This queue is triggered by a SNS topic'), AwsResouce(AwsResourceType.Lambda, 'some-lambda', 'Lambda listens to Queue and writes to DynamoDB'), AwsResouce(AwsResourceType.DynamoDbWithStream, 'my-table', 'Updated by lambda'), AwsResouce( AwsResourceType.Lambda, 'another-lambda', 'Lambda listens to DynamoDB stream and writes to Kinesis stream' ), AwsResouce(AwsResourceType.KinesisStream, 'some-kinesis-stream', 'Some stream with consumers') ])) # TODO: by simply calling the `create_pipeline_dashboard()` function we can add additional Dashboards in a config style group = DashboardGroup() \ .with_name("My Data Pipeline Dashboard Group") \ .with_dashboards(*dashboards) cli = CliBuilder().with_resources(group).build() cli()
from signal_analog.eventoverlays import EventSignals, EventOverlays, SelectedEventOverlays """ Example 1: Creating a new Dashboard with event overlay markers set to show by default This creates a new dashboard which will show event markers marked with "deploy" by default. """ program = Data('cpu.utilization').publish() chart = TimeSeriesChart().with_name('TacoChart').with_program(program).show_event_lines(True) events = EventSignals().with_event_search_text("deploy")\ .with_event_type("eventTimeSeries") eventoverlay = EventOverlays().with_event_signals(events)\ .with_event_color_index(1)\ .with_event_line(True) selectedeventoverlay = SelectedEventOverlays()\ .with_event_signals(events) dashboard_with_event_overlays = Dashboard().with_name('Dashboard Named Snek')\ .with_charts(chart)\ .with_event_overlay(eventoverlay)\ .with_selected_event_overlay(selectedeventoverlay) if __name__ == '__main__': from signal_analog.cli import CliBuilder cli = CliBuilder().with_resources(dashboard_with_event_overlays)\ .build() cli()
dashboard_group_with_dashboards = DashboardGroup() \ .with_name('Dashboard Group Name') \ .with_dashboards(dashboard1, dashboard2, dashboard3) """ Example 3: Update existing dashboard group by removing one of the dashboards """ dashboard_group_remove_dashboard = DashboardGroup()\ .with_name('Dashboard Group Name')\ .with_dashboards(dashboard1, dashboard2) """ Example 4: Rename an existing Dashboard """ dashboard2 = Dashboard().with_name('Dashboard2_Renamed')\ .with_charts(chart, chart1) dashboard_group_rename_dashboard = DashboardGroup()\ .with_name('Dashboard Group Name')\ .with_dashboards(dashboard1, dashboard2) if __name__ == '__main__': from signal_analog.cli import CliBuilder cli = CliBuilder().with_resources(dashboard_group, dashboard_group_with_dashboards, dashboard_group_remove_dashboard, dashboard_group_rename_dashboard)\ .build() cli()