Logging Metrics#

This how-to explains how to log metrics in Dioptra.

Prerequisites#

Metric Logging Workflow#

Metrics can be logged as part of a plugin, during the execution of a job, by using the python client, and can be retrieved via the API or viewed through the Job details page.

Note

This guide only explains how to log metrics through the client, and not how to incorporate metric logging into your custom plugin tasks.

Log a Metric to a Job#

Log a metric as part of a job using the Python client.

Client Method:

Use the client to create a metric.

Note that from a job, you can use os.environ["__JOB_ID"] to get the current job’s ID.

JobsCollectionClient.append_metric_by_id(job_id: str | int, metric_name: str, metric_value: float, metric_step: int | None = None, timestamp: datetime.datetime | str | None = None) dioptra.client.jobs.T[source]#

Posts a new metric to a job.

Parameters
  • job_id – The job id, an integer.

  • metric_name – The name of the metric.

  • metric_value – The value of the metric. Can be a float, NaN, Infinity, or -Infinity. NaN values will be converted to the string “nan” and infinite values will be converted to the strings “inf” and “-inf” before sending to the API.

  • metric_step – The step value for the metric, optional. Sequentially increasing step values are used to track how a metric changes over time. Indexed from 0. If not provided, defaults to 0.

  • timestamp – A timestamp value to associate with the metric. If not provided, defaults to the server time when the metric is received.

Returns

The response from the Dioptra API.

Retrieving Metrics for Jobs#

Retrieve metrics from a job or view them in the GUI.

In the Dioptra GUI, navigate to the Jobs tab. Click the row for a job. Click the Metrics tab on the Job Dashboard page. A list of logged metrics will be displayed here.

See Also#