pip_clients_metrics 1.0.0
pip_clients_metrics: ^1.0.0

Dart native

This is the client for metrics microservice. It keeps list of metrics.

Pip.Services Logo #

Metrics Client SDK #

This is the client for metrics microservice. It keeps list of metrics.

This microservice is designed to manage various metrics characterizing the operation of a process. Each metric has the following characteristics:

  • metric name
  • up to 3 types of measurements (in string format)
  • date and time is a numerical value characterizing the metric

When adding or updating a metric, statistics on the metric are automatically calculated for different time horizons (you can specify the depth of the horizon) with the calculation of the average, maximum, minimum and accumulated values ​​within each of them.

Data access is provided through a set of API functions

The microservice currently supports the following deployment options:

  • Deployment platforms: Standalone Process
  • External APIs: HTTP/REST
  • Persistence: Memory, Flat Files, MongoDB

This microservice has no dependencies on other microservices. Quick Links:

Contract #

Logical contract of the microservice is presented below. For physical implementation (HTTP/REST, GRPC, Lambda, etc.), please, refer to documentation of the specific protocol.

// Create or update metric struct
class MetricUpdateV1 {
    String  name;
    int year;
    int  month;
    int day;
    int hour;
    int minute; 
    String dimension1; 
    String dimension2; 
    String dimension3; 
    double value;
}
// Metric definition struct
class MetricDefinitionV1 {
  String name;
  List<String> dimension1;
  List<String> dimension2;
  List<String> dimension3;
}
// Metric value struct
class MetricValueSetV1 {
    String name;
    int time_horizon;
    String dimension1;
    String dimension2;
    String dimension3;
    List<MetricValueV1> values;
}
// Values of metric
class MetricValueV1 {
    int year; 
    int month; 
    int day; 
    int hour; 
    int minute; 
    int count;
    double sum;
    double max;
    double min;
}
// Time horizons
class TimeHorizonV1 {
    static const Total = 0;
    static const Year = 1;
    static const Month = 2;
    static const Day = 3;
    static const Hour = 4;
    static const Minute = 5;
}

abstract class IMetricsController {
  Future<List<MetricDefinitionV1>> getMetricDefinitions(String correlationId);
  Future<MetricDefinitionV1> getMetricDefinitionByName(
      String correlationId, String name);
  Future<DataPage<MetricValueSetV1>> getMetricsByFilter(
      String correlationId, FilterParams filter, PagingParams paging);
  Future updateMetric(
      String correlationId, MetricUpdateV1 update, int maxTimeHorizon);
  Future updateMetrics(
      String correlationId, List<MetricUpdateV1> updates, int maxTimeHorizon);
}

Download #

Right now the only way to get the microservice is to check it out directly from github repository

git clone git@github.com:pip-services-infrastructure/pip-clients-metrics-dart.git

Pip.Service team is working to implement packaging and make stable releases available for your as zip downloadable archieves.

Use #

Inside your code get the reference to the client SDK

 import 'package:pip_clients_metrics';

Define client configuration parameters.

// Client configuration
var httpConfig = ConfigParams.fromTuples([
            'connection.protocol', 'http',
            'connection.port', 3000,
            'connection.host', 'localhost'
]);
client.configure(httpConfig);

Instantiate the client and open connection to the microservice

// Create the client instance
client = MetricssHttpClientV1();

// Connect to the microservice
try {
await client.open(null);
catch (err){
    print('Connection to the microservice failed');
    printr(err);
    return;
}
// Work with the microservice
...

Now the client is ready to perform operations:

Update if exist metric or create otherwise:

try{
    await client.updateMetric(
                    null,
                    MetricUpdateV1()
                        ..name = "metric1"
                        ..dimension1 = "A"
                        ..dimension2 = "B"
                        ..dimension3 = null
                        ..year = 2018
                        ..month = 8
                        ..day = 26
                        ..hour = 12
                        ..value = 123
                    ,
                    TimeHorizonV1.Hour);
} catch(err) {
    console.error('Update/create metric are failed');
    console.error(err);
}

Update if exist metrics or create otherwise::

try{ 
    await client.updateMetrics(
                    null,
                    [
                        MetricUpdateV1() 
                            ..name = "metric1",
                            ..dimension1 = "A",
                            ..dimension2 = "B",
                            ..dimension3 = null,
                            ..year = 2018,
                            ..month = 8,
                            ..day = 26,
                            ..hour = 13,
                            ..value = 321
                        ,
                        MetricUpdateV1() 
                            ..name = "metric2"
                            ..dimension1 = "A"
                            ..dimension2 = null
                            ..dimension3 = "C"
                            ..year = 2018
                            ..month = 8
                            ..day = 26
                            ..hour = 13
                            ..value = 321
                        }        
                    ],
                    TimeHorizonV1.Hour);
} catch(err){               
    console.error('Update/create metric are failed');
    console.error(err);                 
}    
                

Get metrics by filter:

try {    
    var page = await client.getMetricsByFilter(null,
                    FilterParams.fromTuples(["name", "metric1"]),
                    new PagingParams());
    console.log("Metrics:");
    console.log(page.data);

} catch(err) {
    console.error("Can\'t get metrics by filter");
    console.error(err);                      
}
    

Get all metrics definitions:

try {   
    var definitions = await client.getMetricDefinitions(null);
    console.log("All metrics definition:");
    console.log(definitions);
} catch (err){
                    
    console.error("Can\'t get metrics definitions");
    console.error(err);
}
    

Get metric definition by name:

try {   
    var definition = await client.getMetricDefinitionByName(
                    null, 
                    "metric2");
    console.log("Metric definition name %s:", definition.name);
    console.log(definition);
} catch(err) {
                        
    console.error("Can\'t get metrics definition by name");
    console.error(err);
}               
    

Acknowledgements #

This client SDK was created and currently maintained by Sergey Seroukhov and Levichev Dmitry.