---
updatedAt: 2025-09-21T00:05:11.000Z
agentTools:
  projectIndex: https://docs.liongard.com/llms.txt
---

# How to Write a Metric

> 👍 Liongard Academy
>
> Learn more about writing custom Metrics with Liongard Academy's "How to Write a Metric" Learning Path,  found at [**Liongard Academy.**](https://academy.liongard.com/)

# Overview

## Before creating a Metric, it is important to:

* [Understand Liongard's Metric Builder](https://docs.liongard.com/docs/how-to-write-a-metric#section-understanding-liongards-metric-builder)
* [Understand Liongard's Data Prints](https://docs.liongard.com/docs/how-to-write-a-metric#section-understanding-liongards-data-prints)
* Understand JMESPath Queries
  * [JMESPath Explained](https://docs.liongard.com/docs/how-to-write-a-metric#section-jmes-path-explained)
  * [How To: Write a Simple Query](https://docs.liongard.com/docs/how-to-write-a-metric#section-how-to-write-a-simple-query)
  * [How To: Use Functions](https://docs.liongard.com/docs/how-to-write-a-metric#section-how-to-use-functions)
  * [How To: Filter](https://docs.liongard.com/docs/how-to-write-a-metric#section-how-to-filter)

## There are three ways to create a Metric:

1. [Add a Metric from an Inspector's Data View](https://docs.liongard.com/docs/how-to-write-a-metric#section-add-a-metric-from-an-inspectors-data-view)
2. [Clone an Existing Metric](https://docs.liongard.com/docs/how-to-write-a-metric#section-clone-an-existing-metric)
3. [Create a Metric from Scratch](https://docs.liongard.com/docs/how-to-write-a-metric#section-create-a-metric-from-scratch)

# Understanding Metrics

## Understanding Liongard's Metric Builder

![](https://files.readme.io/e207e49-Screen_Shot_2021-03-03_at_7.50.55_PM.png "Screen Shot 2021-03-03 at 7.50.55 PM.png")

1. **Inspector:** Select the Inspector for which you are building the Metric
2. **Name:** Name of the Metric
3. **Metric Display:** Enabling the toggle will display the Metric in Liongard and will make the Metric available to third-party integrations
4. **Change Detection Enabled:** Enabling the toggle will turn on a Change Detection for the Metric
5. **Description:** Description of the Metric

### Query Builder

![](https://files.readme.io/a9cfcf4-MetricBuilder2.png "MetricBuilder2.png")

1. **Choose a System:** Select the Friendly Name of an Inspector whose Data Print you'd like to explore in the Data Print Explorer
2. **Choose a Recent Timeline Entry:** The desired timeline entry of the selected Inspector you would like to use as you build the Metric
3. **Data Print Query:** Use JMESPath to write a query into the Data Print

* **Data Print Explorer:** Dynamic Data Print of the Inspector and timeline entry chosen in the **Choose a System** and **Choose a Recent Timeline Entry** fields
* **Query Results:** As you write the query, the output results will display here
* **Preview Query:** Selecting Preview Query will allow you to see the output of the Metric as it will be displayed in Liongard

## Understanding Liongard's Data Prints

Liongard's Inspectors bring back data as a JSON object in a tree structure. This structure consists of objects and arrays.

* **Object** = A value; sometimes including subordinate values or lists of values
* **Array** =  A list of multiple objects. Anything that ends in "\[x]" (e.g. Users: Array \[11])

<Image title=";alskdj.png" alt={1370} align="center" src="https://files.readme.io/343f947-alskdj.png">
  Above you can see both **Objects** and an **Arrays**
</Image>

<Image title="actur.png" alt={398} align="center" src="https://files.readme.io/9c8b78c-actur.png">
  Above is an example of an **Object**
</Image>

<Image title="users.png" alt={254} align="center" src="https://files.readme.io/41a5098-users.png">
  Above is an example of an **Array**
</Image>

# JMESPath Explained

For more information about JMESPath, please see some examples linked below:

* [JMESPath tutorial](http://jmespath.org/tutorial.html)
* [JMESPath functions](http://jmespath.org/specification.html#built-in-functions)
* [JMESPath filters](http://jmespath.org/specification.html#filter-expressions)

JMESPath is a query language of JSON. It is made up of a path of commands.

![](https://files.readme.io/70eb514-mhm.png "mhm.png")

* **What this query is saying:** In the "Licensing: Array," where "skuPartNumber" equals "ENTERPRISEPREMIUM," tell me how many "consumedUnits" there are.

Notice the **Query Results** above match the number of "consumedUnits" in the Data Print below.

![](https://files.readme.io/61ef811-image.png "image.png")

## Example in Liongard

![](https://files.readme.io/fdc3ce0-Screen_Shot_2020-09-02_at_10.44.03_AM.png "Screen Shot 2020-09-02 at 10.44.03 AM.png")

For example, above you see the **Data Print Query**: "SystemInfo.Overview\.CompanyName"

* In the\**Data Print Explorer* you can see that the first command in the query is to start at the "SystemInfo" object
* The second command is "Overview." In the **Data Print Explorer** below, the "SystemInfo: Object" you can see another object titled "Overview"
* The Third command is "CompanyName." In the **Data Print Explorer** below, the "Overview: Object" you can see another object titled "CompanyName"

This path of commands leaves us at "CompanyName" which in the **Data Print Explorer** is "Contoso Nation." You can see in the **Query Results** "Contoso Nation" is returned.

## How To: Write a Simple Query

![](https://files.readme.io/33d1ca9-Screen_Shot_2020-09-02_at_10.48.28_AM.png "Screen Shot 2020-09-02 at 10.48.28 AM.png")

Above is a Microsoft 365 Inspector's Data Print. If you wanted to know about your users, you would start by directing the query towards the **Users** array (e.g. **Users: Array\[14]**).

![](https://files.readme.io/7239d58-Screen_Shot_2020-09-02_at_10.49.33_AM.png "Screen Shot 2020-09-02 at 10.49.33 AM.png")

In the **Query Results** above you'll find that this query returns all of the variables under each of the 14 objects in this Users array.

* **What this query is saying:** Tell me about the users

## How To: Use Functions

Now you might want to know how many users there are. To do this, you'll need to insert a function. For example, **length** is a JMESPath function that will return an aggregate from the array that it's directed towards.

* In JMESPath, functions can be applied to queries by starting the query with a function, and then surrounding the rest of the query in parenthesis (e.g. "length(Users)")

![](https://files.readme.io/7337790-Screen_Shot_2020-09-02_at_10.52.53_AM.png "Screen Shot 2020-09-02 at 10.52.53 AM.png")

In the **Query Results** above, you'll find that this query returns the number of 365 users - **14**. This can also be seen in the **Data Print Explorer** in the brackets following the **Users** array - **14**.\
**Note:** Each Microsoft 365 user is an object in the **Users** array

* **What this query is saying:** Tell me how many users there are

## How To: Filter

Now you might want to know how many users have not been active within the last 30 days. To do this, you'll need to insert a filter. You can filter a query into an array by:

* In JMESPath, filters can be applied to queries by following the command to an array with brackets, a question mark, and the criteria that you want to filter by (e.g. "UsersveLast30Days == `false`]")\
  ")\
  Notes:
  * "==" means "equals"
  * "!=" means "does not equal"
  * "<" means "less than"
  * ">" means "greater than"
  * the "**\`**"s around "false" in the example above are back ticks (not apostrophes)

![](https://files.readme.io/70d0622-Screen_Shot_2020-09-02_at_10.57.15_AM.png "Screen Shot 2020-09-02 at 10.57.15 AM.png")

In the **Query Results** above you'll find that this query returns the number of 365 users that have been not been active in the last 30 days.

* **What this query is saying:** Tell me how many users there are where "activeLast30Days" equals "false"

## Liongard JMESPath Extensions: RoarPath Commands

There are several Liongard JMESPath extensions and functions to make JMESPath more powerful and convenient. Review our [documentation](https://docs.liongard.com/docs/roarpath-commands) to learn more about Liongard RoarPath Commands.

# Add a Metric from an Inspector's Data View

* Navigate to an **Inspector’s Data View**
  * Click an "Add Metric" icon, located on the far left of “Key-Value” tables

![](https://files.readme.io/c7f8e10-Screen_Shot_2020-11-25_at_11.07.01_AM.png "Screen Shot 2020-11-25 at 11.07.01 AM.png")

## What to Edit

![](https://files.readme.io/f1d2f91-Screen_Shot_2020-09-02_at_11.03.48_AM.png "Screen Shot 2020-09-02 at 11.03.48 AM.png")

1. **Name:** Edit to Include a Summary of the the Metric
2. **Description:** (Optional) Edit to reflect a description of the Metric
3. **Data Print Query**: Edit to query what you would like

When you are satisfied with the information in the above fields, the select **Save**, or select **Edit in Metric Builder** for further customizing.

# Clone an Existing Metric

* Navigate to **Admin** > **Metrics**
  * Explore the library of Metrics - search for a Metric similar to the Metric you wish to create
  * Click on the blue "**Clone**" button on the left of the chosen Metric

## What to Edit

![](https://files.readme.io/6208f5b-MetricBuilder1.png "MetricBuilder1.png")

1. **Inspector:** Select the Inspector for which you are building the Metric
2. **Name:** Name of the Metric
3. **Metric Display:** Enabling the toggle will display the Metric in Liongard and will make the Metric available to third-party integrations
4. **Change Detection Enabled:** Enabling the toggle will turn on a Change Detection for the Metric
5. **Description:** Description of the Metric

### Query Builder

![](https://files.readme.io/e7c5cb3-MetricBuilder2.png "MetricBuilder2.png")

1. **Choose a System:** Select the Friendly Name of an Inspector whose Data Print you'd like to explore in the Data Print Explorer
2. **Choose a Recent Timeline Entry:** The desired timeline entry of the selected Inspector you would like to use as you build the Metric
3. **Data Print Query:** Use JMESPath to write a query into the Data Print

* **Data Print Explorer:** Dynamic Data Print of the Inspector and timeline entry chosen in the **Choose a System** and **Choose a Recent Timeline Entry** fields
* **Query Results:** As you write the query, the output results will display here
* **Preview Query:** Selecting Preview Query will allow you to see the output of the Metric as it will be displayed in Liongard

When you are satisfied with the information in the above fields, select **Save**.

# Create a Metric from Scratch

> 👍 Metric Character Limit
>
> The Metric character limit is currently 6000 characters.

> 🚧 Cisco Meraki Metrics
>
> If using a key with a period (i.e. "Switch.Count"), in the Data Query you must put the key in quotations for it to return an output. For example, "Switch.Count".

* Navigate to **Admin** > **Metrics**
  * In the top right corner, select **Add Metric**

## What to Edit

![](https://files.readme.io/7a897d1-MetricBuilder1.png "MetricBuilder1.png")

1. **Inspector:** Select the Inspector for which you are building the Metric
2. **Name:** Name of the Metric
3. **Metric Display:** Enabling the toggle will display the Metric in Liongard and will make the Metric available to third-party integrations
4. **Change Detection Enabled:** Enabling the toggle will turn on a Change Detection for the Metric
5. **Description:** Description of the Metric

### Query Builder

![](https://files.readme.io/bcf6675-MetricBuilder2.png "MetricBuilder2.png")

1. **Choose a System:** Select the Friendly Name of an Inspector whose Data Print you'd like to explore in the Data Print Explorer
2. **Choose a Recent Timeline Entry:** The desired timeline entry of the selected Inspector you would like to use as you build the Metric
3. **Data Print Query:** Use JMESPath to write a query into the Data Print

* **Data Print Explorer:** Dynamic Data Print of the Inspector and timeline entry chosen in the **Choose a System** and **Choose a Recent Timeline Entry** fields
* **Query Results:** As you write the query, the output results will display here
* **Preview Query:** Selecting Preview Query will allow you to see the output of the Metric as it will be displayed in Liongard

When you are satisfied with the information in the above fields, select **Save**.

<HTMLBlock>{`

`}</HTMLBlock>

# How to Write a Metric Learning Path

Looking for more Metric writing practice? Check out our *How to Write a Metric* Learning Path in [Liongard Academy](https://docs.liongard.com/docs/liongard-academy).