From a6ed51b7a7b22a273ae7a6c9231659ca0fa49281 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Fri, 12 Jul 2019 01:39:40 -0400 Subject: [PATCH] websocket admin connection to get query metric data --- dart/packages/lbry/bin/main.dart | 3 +- dart/packages/lbry/lib/lbry.dart | 1 + .../packages/lbry/lib/src/load_generator.dart | 2 +- dart/packages/lbry/pubspec.lock | 44 +++++++------- dart/packages/lbry/pubspec.yaml | 1 + dart/packages/ver/lib/time_series_chart.dart | 59 +++++++++++++++++-- .../ver/linux/flutter_embedder_example.cc | 2 +- dart/packages/ver/pubspec.lock | 21 +++++++ 8 files changed, 104 insertions(+), 29 deletions(-) diff --git a/dart/packages/lbry/bin/main.dart b/dart/packages/lbry/bin/main.dart index 4ebbe060d..00aeec9e7 100644 --- a/dart/packages/lbry/bin/main.dart +++ b/dart/packages/lbry/bin/main.dart @@ -1,4 +1,5 @@ -import 'package:lbry/src/load_generator.dart' as load; +//import 'package:lbry/src/load_generator.dart' as load; +import 'package:lbry/src/client.dart' as load; main(List arguments) { load.cli(); diff --git a/dart/packages/lbry/lib/lbry.dart b/dart/packages/lbry/lib/lbry.dart index ac03f010c..19e8b3ba3 100644 --- a/dart/packages/lbry/lib/lbry.dart +++ b/dart/packages/lbry/lib/lbry.dart @@ -1 +1,2 @@ export 'src/load_generator.dart' show LoadGenerator, LoadDataPoint; +export 'src/client.dart' show Client, MetricDataPoint; diff --git a/dart/packages/lbry/lib/src/load_generator.dart b/dart/packages/lbry/lib/src/load_generator.dart index 1f5d2e8c0..a48a8f3af 100644 --- a/dart/packages/lbry/lib/src/load_generator.dart +++ b/dart/packages/lbry/lib/src/load_generator.dart @@ -98,7 +98,7 @@ class LoadGenerator { } class LoadDataPoint { - final DateTime time = new DateTime.now(); + final DateTime time = DateTime.now(); int success = 0; int errored = 0; int backlog = 0; diff --git a/dart/packages/lbry/pubspec.lock b/dart/packages/lbry/pubspec.lock index db604de88..67f861e9a 100644 --- a/dart/packages/lbry/pubspec.lock +++ b/dart/packages/lbry/pubspec.lock @@ -7,7 +7,7 @@ packages: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.36.4" + version: "0.37.0" args: dependency: transitive description: @@ -63,14 +63,14 @@ packages: name: csslib url: "https://pub.dartlang.org" source: hosted - version: "0.16.0" + version: "0.16.1" dart_style: dependency: transitive description: name: dart_style url: "https://pub.dartlang.org" source: hosted - version: "1.2.8" + version: "1.2.9" fixnum: dependency: transitive description: @@ -84,7 +84,7 @@ packages: name: front_end url: "https://pub.dartlang.org" source: hosted - version: "0.1.19" + version: "0.1.20" glob: dependency: transitive description: @@ -134,20 +134,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.1+1" - json_rpc_2: - dependency: transitive - description: - name: json_rpc_2 - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" kernel: dependency: transitive description: name: kernel url: "https://pub.dartlang.org" source: hosted - version: "0.3.19" + version: "0.3.20" matcher: dependency: transitive description: @@ -210,7 +203,7 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0+1" pool: dependency: transitive description: @@ -224,14 +217,14 @@ packages: name: protobuf url: "https://pub.dartlang.org" source: hosted - version: "0.13.12" + version: "0.13.15" protoc_plugin: dependency: "direct dev" description: name: protoc_plugin url: "https://pub.dartlang.org" source: hosted - version: "17.0.2" + version: "17.0.4" pub_semver: dependency: transitive description: @@ -302,6 +295,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" + stream_transform: + dependency: transitive + description: + name: stream_transform + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.19" string_scanner: dependency: transitive description: @@ -322,7 +322,7 @@ packages: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.6.5" test_api: dependency: transitive description: @@ -336,7 +336,7 @@ packages: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.2.6" + version: "0.2.7" typed_data: dependency: transitive description: @@ -344,13 +344,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.6" - vm_service_client: + vm_service_lib: dependency: transitive description: - name: vm_service_client + name: vm_service_lib url: "https://pub.dartlang.org" source: hosted - version: "0.2.6+2" + version: "3.22.0" watcher: dependency: transitive description: @@ -359,12 +359,12 @@ packages: source: hosted version: "0.9.7+10" web_socket_channel: - dependency: transitive + dependency: "direct main" description: name: web_socket_channel url: "https://pub.dartlang.org" source: hosted - version: "1.0.13" + version: "1.0.14" yaml: dependency: transitive description: diff --git a/dart/packages/lbry/pubspec.yaml b/dart/packages/lbry/pubspec.yaml index 4c2789274..ab57e45c0 100644 --- a/dart/packages/lbry/pubspec.yaml +++ b/dart/packages/lbry/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: http: ^0.12.0+2 path: ^1.4.1 protobuf: ^0.13.12 + web_socket_channel: ^1.0.4 dev_dependencies: pedantic: ^1.0.0 diff --git a/dart/packages/ver/lib/time_series_chart.dart b/dart/packages/ver/lib/time_series_chart.dart index c184efc9b..25c64455f 100644 --- a/dart/packages/ver/lib/time_series_chart.dart +++ b/dart/packages/ver/lib/time_series_chart.dart @@ -14,15 +14,55 @@ class SimpleTimeSeriesChart extends StatefulWidget { class _SimpleTimeSeriesChartState extends State { + final List metricData = []; final List loadData = []; final List> loadSeries = []; final List> timeSeries = []; + final List> metricSeries = []; + final List> metricTimeSeries = []; final Random rand = Random(); LoadGenerator loadGenerator; + Client client; @override void initState() { super.initState(); + metricSeries.add( + charts.Series( + id: 'Searches', + colorFn: (_, __) => charts.MaterialPalette.black.darker, + domainFn: (MetricDataPoint load, _) => load.time, + measureFn: (MetricDataPoint load, _) => load.search, + data: metricData, + ) + ); + metricSeries.add( + charts.Series( + id: 'Resolves', + colorFn: (_, __) => charts.MaterialPalette.black.darker, + domainFn: (MetricDataPoint load, _) => load.time, + measureFn: (MetricDataPoint load, _) => load.resolve, + data: metricData, + ) + ); + metricTimeSeries.add( + charts.Series( + id: 'Avg. Resolve Time', + colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault, + domainFn: (MetricDataPoint load, _) => load.time, + measureFn: (MetricDataPoint load, _) => load.avg_resolve, + data: metricData, + ) + ); + metricTimeSeries.add( + charts.Series( + id: 'Avg. Search Time', + colorFn: (_, __) => charts.MaterialPalette.yellow.shadeDefault, + domainFn: (MetricDataPoint load, _) => load.time, + measureFn: (MetricDataPoint load, _) => load.avg_search, + data: metricData, + ) + ); loadSeries.add( charts.Series( id: 'Load', @@ -79,7 +119,7 @@ class _SimpleTimeSeriesChartState extends State { ); var increase = 1; loadData.add(LoadDataPoint()); - loadGenerator = LoadGenerator('spv2.lbry.com', 50001, { + loadGenerator = LoadGenerator('localhost', 50001, { 'id': 1, 'method': 'blockchain.claimtrie.search', 'params': { @@ -99,17 +139,26 @@ class _SimpleTimeSeriesChartState extends State { //if (loadData.length > 60) loadData.removeAt(0); loadData.add(stats); }); - //increase = max(1, min(30, (increase*1.1).ceil())-stats.backlog); - increase += 1; + increase = max(1, min(30, (increase*1.1).ceil())-stats.backlog); + //increase += 1; //t.query['params']['offset'] = (increase/2).ceil()*t.query['params']['limit']; t.load = increase;//rand.nextInt(10)+5; return true; })..start(); + metricData.add(MetricDataPoint()); + client = Client('ws://localhost:8181/')..open()..metrics.listen((m) { + setState(() { + metricData.add(m); + }); + print(m.avg_resolve); + print(m.avg_search); + }); } @override void dispose() { - loadGenerator.stop(); + if (client != null) client.close(); + if (loadGenerator != null) loadGenerator.stop(); super.dispose(); } @@ -118,6 +167,8 @@ class _SimpleTimeSeriesChartState extends State { return Column(children: [ SizedBox(height: 250.0, child: BetterTimeSeriesChart(loadSeries)), SizedBox(height: 250.0, child: BetterTimeSeriesChart(timeSeries)), + SizedBox(height: 250.0, child: BetterTimeSeriesChart(metricSeries)), + SizedBox(height: 250.0, child: BetterTimeSeriesChart(metricTimeSeries)), ]); } diff --git a/dart/packages/ver/linux/flutter_embedder_example.cc b/dart/packages/ver/linux/flutter_embedder_example.cc index e924a52ce..8954781ce 100644 --- a/dart/packages/ver/linux/flutter_embedder_example.cc +++ b/dart/packages/ver/linux/flutter_embedder_example.cc @@ -60,7 +60,7 @@ int main(int argc, char **argv) { flutter::FlutterWindowController flutter_controller(icu_data_path); // Start the engine. - if (!flutter_controller.CreateWindow(800, 600, "ver - lbry workbench", + if (!flutter_controller.CreateWindow(800, 1200, "ver - lbry workbench", assets_path, arguments)) { return EXIT_FAILURE; } diff --git a/dart/packages/ver/pubspec.lock b/dart/packages/ver/pubspec.lock index 3749d7d58..0b4b4fc7a 100644 --- a/dart/packages/ver/pubspec.lock +++ b/dart/packages/ver/pubspec.lock @@ -43,6 +43,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.14.11" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.6" cupertino_icons: dependency: "direct main" description: @@ -205,5 +219,12 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.14" sdks: dart: ">=2.2.2 <3.0.0"