Metrics

Resource

Methods

Metric.__init__(manager, data)

Resource initializer.

Parameters
  • manager – The manager this resource belongs to

  • data – The raw json data

Metric.get(name) → Any

Safely obtain any attribute name for the resource

Parameters

name (str) – Key name in json response

Returns

Value from the raw json response. If the key doesn’t exist None is returned.

Metric.delete() → None

Deletes the resource from the server.

Raises

HTTPException if the resource don't exist.

Metric.update()

Posts the values in the resource to the server.

Example:

# Change an attribute and save the resource
>> resource.value = something
>> updated_resource = resource.update()
Returns

The updated resource from the server

Return type

Resource

Attributes

Metric.attrs

The raw json response from the server

Type

dict

Metric.id
Metric.name
Metric.description
Metric.default_value
Metric.display_chart
Metric.places
Metric.points = <function Metric.points>
Metric.threshold
Metric.visible
Metric.order
Metric.suffix
Metric.calc_type
Metric.default_view
Metric.created_at

When the issue was created

Type

datetime

Metric.updated_at

Last time the issue was updated

Type

datetime

Manager

Methods

MetricsManager.__init__(http_client: cachetclient.httpclient.HttpClient, metric_update_manager: cachetclient.v1.metric_points.MetricPointsManager)

Manager initializer.

Parameters

http_client – The httpclient

MetricsManager.create(*, name: str, description: str, suffix: str, default_value: int = 0, display_chart: int = 0) → cachetclient.v1.metrics.Metric

Create a metric.

Keyword Arguments
  • name (str) – Name/title of the metric

  • description (str) – Description of what the metric is measuring

  • suffix (str) – Measurments in

  • default_value (int) – The default value to use when a point is added

  • display_chart (int) – Whether to display the chart on the status page

Returns

Metric instance

MetricsManager.get(metric_id: int) → cachetclient.v1.metrics.Metric

Get a signle metric

Parameters

metric_id (int) – The metric id to get

Returns

Metric instance

Raises

requests.exception.HttpError – if metric do not exist

MetricsManager.list(page: int = 1, per_page: int = 1) → Generator[cachetclient.v1.metrics.Metric, None, None]

List all metrics paginated

Keyword Arguments
  • page (int) – Page to start on

  • per_page (int) – entries per page

Returns

Generator of :py:data:`Metric`s

MetricsManager.count() → int

Count the number of metrics

Returns

Total number of metrics

Return type

int

MetricsManager.delete(metric_id: int) → None

Delete an metric

Parameters

metric_id (int) – The metric id

MetricsManager.instance_from_dict(data: dict) → cachetclient.base.Resource

Creates a resource instance from a dictionary.

This doesn’t hit any endpoints in cachet, but rather enables us to create a resource class instance from dictionary data. This can be useful when caching data from cachet in memcache or databases.

Parameters

data (dict) – dictionary containing the instance data

Returns

The resource class instance

Return type

Resource

MetricsManager.instance_from_json(data: str) → cachetclient.base.Resource

Creates a resource instance from a json string.

This doesn’t hit any endpoints in cachet, but rather enables us to create a resource class instance from json data. This can be useful when caching data from cachet in memcache or databases.

Parameters

data (str) – json string containing the instance data

Returns

The resource class instance

Return type

Resource

MetricsManager.instance_list_from_json(data: str) → List[cachetclient.base.Resource]

Creates a resource instance list from a json string.

This doesn’t hit any endpoints in cachet, but rather enables us to create a resource class instances from json data. This can be useful when caching data from cachet in memcache or databases.

Parameters

data (str) – json string containing the instance data

Returns

The resource class instance

Return type

Resource

Raises

ValueError – if json data do not deserialize into a list

Attributes

MetricsManager.path = 'metrics'
MetricsManager.resource_class = <class 'cachetclient.v1.metrics.Metric'>