Using Peak Metrics

Publish metrics

The metrics can be published either by passing artifact and namespace, or by passing collection ID and namespace. If both artifact and collection ID are provided, artifact takes priority. If the namespace is not provided, the default namespace is used.

NOTE: Authentication will be performed using only personal access tokens and system access tokens. API keys will not be permitted for this functionality.

# publish.yaml

body:
  namespace: dev
artifact:
  path: metrics

We can use the following command to publish metrics:

peak metrics publish path/to/publish.yaml -v path/to/params.yaml

We can publish metrics directly from the command line by specifying all the required parameters:

peak metrics publish --artifact-path path/to/metrics --namespace dev

We can also combine the YAML template and command line arguments, where the command line arguments will take precedence over the YAML file. Create the YAML template file with the following content:

Publish metrics using artifact and namespace

# metrics.yaml

body:
    namespace: dev
artifact:
    path: metrics

Publish metrics using collection id and namespace

# metrics.yaml

body:
    namespace: dev
collectionId: "bc8b6ef5-d2f6-4b7f-9365-0261b43997c9"
peak metrics publish path/to/metrics.yaml --namespace test

In this case, the final publish metrics body will look like:

{
    "namespace": "test"
}

Querying the published metrics

We can query the published metrics by providing the parameters like namespace, measures, dimensions, filters, time_dimensions, order, limit and offset.

generate_sql parameter is optional. If it is set to true, the API will return the SQL query that will be executed to fetch the data.

namespace: default
generateSql: false
measures:
  - product.price
dimensions:
  - product.name
filters:
  - dimension: product.category
    operator: equals
    values:
      - "electronics"
timeDimensions:
  - dimension: product.created_at
    dateRange:
      - "2020-01-26T00:00:00Z"
      - "2020-02-06T00:00:00Z"
    granularity: day
segments:
  - product.category
  - product.price
order:
  product.created_at: desc
  product.price: asc
limit: 100
ofset: 0

We can use the following command to query the published metrics:

peak metrics query path/to/query.yaml -v path/to/query.yaml

We can query the published metrics directly from the command line by specifying all the required parameters:

peak metrics query --measures "<cube_name>.<resource_name_1>" --measures "<cube_name>.<resource_name_2>" --dimensions "<cube_name>.<resource_name>" --time-dimensions "{\"dimension\":\"<cube_name>.<resource_name>\",\"dateRange\":[\"2024-01-26T00:00:00Z\",\"2024-06-06T00:00:00Z\"],\"granularity\":\"day\"}" --limit 5 --offset 0

We can also combine the YAML template and command line arguments, where the command line arguments will take precedence over the YAML file. Create the YAML template file with the following content:

# query.yaml

namespace: "product"
measures:
    - "product.total_sales"
dimensions:
    - "product.region"
filters:
    - dimension: "product.region"
      operator: "="
      value: "US"
time_dimensions:
    - dimension: "product.created_at"
      granularity: "day"
      date_range:
          - "2021-01-01T00:00:00Z"
          - "2021-01-31T23:59:59Z"
order:
    region: "asc"
limit: 10
offset: 0
generate_sql: true
peak metrics query path/to/query.yaml --limit 5

In this case, the final query body will look like:

{
    "namespace": "product",
    "measures": ["product.total_sales"],
    "dimensions": ["product.region"],
    "filters": ["product.region = 'US'"],
    "time_dimensions": ["product.created_at"],
    "order": { "region": "asc" },
    "limit": 5,
    "offset": 0,
    "generate_sql": true
}

Create the metrics collection

We can create the collection of the metrics artifact by providing payload containing its configuration.
NOTE: Authentication will be performed using only personal access tokens and system access tokens. API keys will not be permitted for this functionality.

# create_collection.yaml

body:
  name: test
  scope: public
  description: "This collection is used for product metrics"
artifact:
  path: metrics

We can use the following command to create the metrics collection:

peak metrics create-collection path/to/create_collection.yaml -v path/to/params.yaml

We can create the metrics collection directly from the command line by specifying all the required parameters:

peak metrics create-collection --artifact-path path/to/metrics --name test --scope PUBLIC --description "This collection is used for pricing metrics"

We can also combine the YAML template and command line arguments, where the command line arguments will take precedence over the YAML file. Create the YAML template file with the following content:

# metrics.yaml

body:
    name: test
    scope: public
    description: This collection is used for product metrics
artifact:
    path: metrics
peak metrics create-collection path/to/publish.yaml --scope private

In this case, the final create metrics collection body will look like:

{
    "name": "test",
    "scope": "private",
    "description": "This collection is used for product metrics"
}