Metrics module

Metrics collected from devices.

Client Module

class Client(auth_token, project=None)

Client class provides access to device, package, volume and deployment classes.

__init__(auth_token, project=None)

Get new client object

Parameters
  • auth_token (string) – Authentication token

  • project (string) – project_guid of the user

list_metrics(list_metrics_request)

List metrics for a particular entity

Parameters

list_metrics_request (ListMetricsRequest) – ListMetricsRequest instance

Return type

list(Metric)

Following example demonstrates how to list metrics

>>> from rapyuta_io import Client
>>> from rapyuta_io.clients.metrics import ListMetricsRequest, Entity
>>> from datetime import datetime, timedelta
>>> project_guid = 'project_guid'
>>> client = Client(auth_token='auth_token', project=project_guid)
>>> now = datetime.utcnow()
>>> request = ListMetricsRequest(Entity.PROJECT, project_guid,
...                              start_date=now-timedelta(days=30), end_date=now)
>>> for metric in client.list_metrics(request):
...    print(metric.metric_group, metric.metric_names)
list_tag_keys(list_tag_keys_request)

List Tag Keys for a particular entity

Parameters

list_tag_keys_request (ListTagKeysRequest) – ListTagKeysRequest

Return type

list(Tags)

Following example demonstrates how to list tag keys

>>> from rapyuta_io import Client
>>> from rapyuta_io.clients.metrics import ListTagKeysRequest, Entity
>>> from datetime import datetime, timedelta
>>> project_guid = 'project_guid'
>>> client = Client(auth_token='auth_token', project=project_guid)
>>> now = datetime.utcnow()
>>> request = ListTagKeysRequest(Entity.PROJECT, project_guid,
...                              start_date=now-timedelta(days=30), end_date=now)
>>> for tag in client.list_tag_keys(request):
...     print(tag.metric_group, tag.tags)
list_tag_values(list_tag_values_request)

List Tag Values for a particular entity

Parameters

list_tag_values_request (ListTagValuesRequest) – ListTagValuesRequest

Return type

list(str)

Following example demonstrates how to list tag values

>>> from rapyuta_io import Client
>>> from rapyuta_io.clients.metrics import ListTagValuesRequest, Entity
>>> from datetime import datetime, timedelta
>>> project_guid = 'project_guid'
>>> client = Client(auth_token='auth_token', project=project_guid)
>>> now = datetime.utcnow()
>>> request = ListTagValuesRequest(Entity.PROJECT, project_guid, 'cpu',
...                                start_date=now-timedelta(days=30), end_date=now)
>>> for tag_value in client.list_tag_values(request):
...     print(tag_value)
query_metrics(query_metrics_request)

Query and fetch metrics

Parameters

query_metrics_request (QueryMetricsRequest) – QueryMetricsRequest instance

Return type

QueryMetricsResponse

Following example demonstrates how to query metrics

>>> from rapyuta_io import Client
>>> from rapyuta_io.clients.metrics import QueryMetricsRequest, StepInterval, SortOrder,
>>> MetricOperation, MetricFunction
>>> from datetime import datetime, timedelta
>>> client = Client(auth_token='auth_token', project='project_guid')
>>> now = datetime.utcnow()
>>> metrics = [MetricOperation(MetricFunction.AVG, 'mem.total'),
>>>            MetricOperation(MetricFunction.AVG, 'mem.used')]
>>> request = QueryMetricsRequest(from_datetime=now-timedelta(days=10), to_datetime=now,
>>>                               step_interval=StepInterval.FIFTEEN_MINUTES, metrics=metrics)
>>> response = client.query_metrics(request)
>>> print([str(col) for col in response.columns])
>>>
>>> import pandas as pd  # pip install pandas
>>> rows, columns = response.to_row_column_format()
>>> df = pd.DataFrame(data=rows, columns=columns)
>>> df['timestamp'] = pd.to_datetime(df['timestamp'])
>>> print(df.head())

Metrics Module

class Column

Column class

Variables
  • name (str) – name of metric

  • function (MetricFunction) – applied metric function

  • metric_group (str) – metric group

  • tag_names (str) – list of tag names

  • tag_values (str) – list of tag values

class Entity(value)

Entity may be one of:

Entity.DEVICE (device)

Entity.DEPLOYMENT (deployment)

Entity.PROJECT (project)

Entity.ORGANIZATION (organization)

class ListMetricsRequest(entity, entity_id, start_date, end_date)

List Metrics Request

Variables
  • entity (Entity) – one of Entity enum

  • entity_id (str) – value of entity

  • start_date (datetime) – filter from start_date

  • end_date (datetime) – filter to end_date

Parameters
  • entity (Entity) – one of Entity enum

  • entity_id (str) – value of entity

  • start_date (datetime) – filter from start_date

  • end_date (datetime) – filter to end_date

class ListTagKeysRequest(entity, entity_id, start_date, end_date)

List Tag Keys Request

Variables
  • entity (Entity) – one of Entity enum

  • entity_id (str) – value of entity

  • start_date (datetime) – filter from start_date

  • end_date (datetime) – filter to end_date

Parameters
  • entity (Entity) – one of Entity enum

  • entity_id (str) – value of entity

  • start_date (datetime) – filter from start_date

  • end_date (datetime) – filter to end_date

class ListTagValuesRequest(entity, entity_id, tag, start_date, end_date)

List Tag Values Request

Variables
  • entity (Entity) – one of Entity enum

  • entity_id (str) – value of entity

  • tag (str) – value of the tag key

  • start_date (datetime) – filter from start_date

  • end_date (datetime) – filter to end_date

Parameters
  • entity (Entity) – one of Entity enum

  • entity_id (str) – value of entity

  • tag (str) – value of the tag key

  • start_date (datetime) – filter from start_date

  • end_date (datetime) – filter to end_date

class Metric

Metric class, has metric_group and list of metric names

Variables
  • metric_group (str) – name of the metric

  • metric_names (list(str)) – list of metrics

class MetricFunction(value)

MetricFunction may be one of:

MetricFunction.COUNT (count)

MetricFunction.DISTINCT (distinct)

MetricFunction.MEAN (mean)

MetricFunction.MEDIAN (median)

MetricFunction.MODE (mode)

MetricFunction.AVG (avg)

MetricFunction.STDDEV (stddev)

MetricFunction.DERIVATIVE (derivative)

MetricFunction.MAX (max)

MetricFunction.MIN (min)

MetricFunction.FIRST (first)

MetricFunction.LAST (last)

MetricFunction.PERCENTILE_95 (percentile_95)

MetricFunction.PERCENTILE_99 (percentile_99)

class MetricOperation(function, metric_name)

MetricsOperation class that defines a function over a metric

Variables
  • function (MetricFunction) – function to applied on metric

  • metric_name (str) – name of the metric

Parameters
  • function (MetricFunction) – function to applied on metric

  • metric_name (str) – name of the metric

class QueryMetricsRequest(from_datetime, to_datetime, step_interval, metrics, tags=None, sort=None, groupby=None)

QueryMetricsRequest class

Variables
  • from_datetime (datetime) – start time of querying metrics

  • to_datetime (datetime) – end time of querying metrics

  • step_interval (StepInterval) – time interval to group data

  • metrics (list(MetricOperation)) – list of metrics

  • tags (dict) – key pair of tags (must include tenant_id and organization_id)

  • sort (SortOrder) – ordering to sort the metrics

  • groupby (list(str)) – list of tags to group data

Parameters
  • from_datetime (datetime) – start time of querying metrics

  • to_datetime (datetime) – end time of querying metrics

  • step_interval (StepInterval) – time interval to group data

  • metrics (list(MetricOperation)) – list of metrics

  • tags (dict) – key pair of tags (must include tenant_id and organization_id)

  • sort (SortOrder) – ordering to sort the metrics

  • groupby (list(str)) – list of tags to group data

class QueryMetricsResponse

QueryMetricsResponse class

Variables
  • columns (Column) – list of columns object

  • rows (list(list(float))) – list of metrics values

to_row_column_format()

Returns rows and columns in a format that can be passed to pandas.DataFrame().

Return type

tuple(generator, list)

class SortOrder(value)

SortOrder may be one of:

SortOrder.ASC (asc)

SortOrder.DESC (desc)

class StepInterval(value)

StepInterval may be one of:

StepInterval.ONE_SECOND (1s)

StepInterval.TEN_SECONDS (10s)

StepInterval.THIRTY_SECONDS (30s)

StepInterval.ONE_MINUTE (1m)

StepInterval.FIVE_MINUTES (5m)

StepInterval.FIFTEEN_MINUTES (15m)

class Tags

Tags class, has metric_group and list of tags

Variables
  • metric_group (str) – name of the metric

  • tags (list(str)) – list of tags