7.2.1.11. Metrics API¶
The Dashboard Metrics API can be used in order to query all kinds of Metric Values
previously stored during the continuous integration analysis.
Metric Values are stored in the project database and associated with the Metric
they are calculated for and an Entity on which they were calculated or aggregated.
A notable Entity is the so-called System Entity which exists once for every
project. It subsumes all of a project’s entities and metrics associated with it
typically are metrics like the total lines of code, the total number of methods
or the ratio of cloned code vs. non-cloned code.
The Dashboard’s Trend Page exclusively shows Metric Plots of metrics associated
with the System Entity.
Examples¶
The following are some scripted examples done using the
Python API wrapper
that we recommend to use if possible. The python API is mostly a thin wrapper around
the HTTP entry points so it should be easy to transfer the examples to HTTP Requests in
your language of choice if you cannot make use of the Python API.
List available Entities¶
# Copyright (C) 2025 Axivion GmbH
# Copyright (C) 2025 The Qt Company GmbH, a subsidiary of The Qt Group
# https://www.qt.io
from axivion.dashboard import Dashboard
with Dashboard(
"http://localhost:9090/axivion/", auth=("username", "password")
) as dashboard:
project = dashboard.project("my_project")
if not project:
raise Exception("Project not found")
result = project.get_entities()
for entity in result['entities']:
print(
'ID: %s Name: %s Type: %s\n'
% (entity['id'], entity['name'], entity['type'])
)
List available System Metrics¶
# Copyright (C) 2025 Axivion GmbH
# Copyright (C) 2025 The Qt Company GmbH, a subsidiary of The Qt Group
# https://www.qt.io
from axivion.dashboard import Dashboard
with Dashboard(
"http://localhost:9090/axivion/", auth=("username", "password")
) as dashboard:
project = dashboard.project("my_project")
if not project:
raise Exception("Project not found")
system_entity = project.get_system_entity()['entities'][0]['id']
# Not specifying any argument here would return *all* metrics
result = project.get_metrics(entity=system_entity)
for metric in result['metrics']:
print('%s (%s)\n' % (metric['name'], metric['displayName']))
Getting Style Violations per Lines of Code¶
# Copyright (C) 2025 Axivion GmbH
# Copyright (C) 2025 The Qt Company GmbH, a subsidiary of The Qt Group
# https://www.qt.io
from axivion.dashboard import Dashboard
with Dashboard(
"http://localhost:9090/axivion/", auth=("username", "password")
) as dashboard:
project = dashboard.project("my_project")
if not project:
raise Exception("Project not found")
system_entity = project.get_system_entity()['entities'][0]['id']
loc_result = project.fetch_metric_value_range(
start='1', end='latest', entity=system_entity, metric='Metric.Lines.LOC.sum'
)
loc_values = loc_result['values']
sv_result = project.fetch_metric_value_range(
start='1', end='latest', entity=system_entity, metric='Metric.Violations.Style'
)
sv_values = sv_result['values']
versions = project.versions()[1:] # strip the EMPTY version
print('Style Violations per Lines of Code:\n')
for i in range(len(versions)):
version = versions[i]
sv = sv_values[i]
loc = loc_values[i]
if sv is None or loc is None:
value = 'N/A'
else:
value = sv / loc
print(
'Version %s with index %s SV/LOC: %s\n'
% (version['name'], version['index'], value)
)
Identify Large Routines¶
# Copyright (C) 2025 Axivion GmbH
# Copyright (C) 2025 The Qt Company GmbH, a subsidiary of The Qt Group
# https://www.qt.io
from operator import itemgetter
from axivion.dashboard import Dashboard
with Dashboard(
"http://localhost:9090/axivion/", auth=("username", "password")
) as dashboard:
project = dashboard.project("my_project")
if not project:
raise Exception("Project not found")
rows = project.fetch_entity_metric_values()['rows']
rows = [
x
for x in rows
if x['metric'] == 'Metric.Lines.LOC' and x['entityType'] == 'Routine'
]
# Sort descending by the Metric Value
rows = sorted(rows, key=itemgetter('value'), reverse=True)
for row in rows:
print(
'Routine %s at %s:%s has %s Lines of Code.'
% (row['entity'], row['path'], row['line'], row['value'])
)
Endpoints¶
GET |
Get the System Entity |
|
GET |
Get Available Entities |
|
GET |
Get Available Metrics |
|
GET |
Query Metric Values |
|
GET |
Query Tabular Metric Values |
|
GET |
DEPRECATED Use /api/projects/{projectName}/queryMetricValueRange instead |
- GET /api/projects/{projectName}/getSystemEntity¶
Get the System Entity.
Use this to get the project’s System Entity.
The version as well as versioned
Entityproperties will only be returned, if a version is specified. The versioned attributes arepathandline.In the Python API this functionality is provided by
axivion.dashboard.Project.get_system_entity().- Parameters:
projectName – path
The project name
version – query
The optional version query string for the entity properties. If not specified, versioned entity attributes will not be included in the result. If it is specified, entities not available in that version will not be included in the result.
- Status Codes:
200 OK –
Body Type:
EntityListAn Entity List containing only the System Entity.
- GET /api/projects/{projectName}/getEntities¶
Get Available Entities.
Returns a list of Entities available in the Project. Note, that this list is not necessarily complete. By default only entities associated with Issues are stored in the database. Storing all Metrics (and their associated Entities) has to be enabled explicitly in your project configuration.
The version as well as versioned
Entityproperties will only be returned, if a version is specified. The versioned attributes arepathandline.In the Python API this functionality is provided by
axivion.dashboard.Project.get_entities().- Parameters:
projectName – path
The project name
version – query
The optional version query string for the entity properties. If not specified, versioned entity attributes will not be included in the result. If it is specified, entities not available in that version will not be included in the result.
metric – query
If a Metric ID is given, only Entities having associated the given Metric will be returned.
- Status Codes:
200 OK –
Body Type:
EntityListList of Entities available in the given version.
- GET /api/projects/{projectName}/getMetrics¶
Get Available Metrics.
Returns a list of Metrics available for the database that can be used to create nice charts over time.
The Version and versioned
Metricproperties will only be returned, if a version is specified. The versioned properties areminValueandmaxValue.In the Python API this functionality is provided by
axivion.dashboard.Project.get_metrics().- Parameters:
projectName – path
The project name
version – query
The optional version query string for the metric properties. If not specified, versioned metric attributes will not be included in the result. If it is specified metrics not available in that version will not be included in the result.
entity – query
If an Entity ID is given, only Metrics associated with the given Entity will be returned.
- Status Codes:
200 OK –
Body Type:
MetricListThe metrics available in the given version.
- GET /api/projects/{projectName}/queryMetricValueRange¶
Query Metric Values.
Note that previously a similar API entry point was available as
/projects/{projectName}/querySystemMetricswhich has been deprecated with 6.9.2. The old entry point has a similar return type schema, except that everything insidevalueswere direct properties of the result object. It also behaves a little different and you should not use it any more.In the Python API this functionality is provided by
axivion.dashboard.Project.fetch_metric_value_range().- Parameters:
- Status Codes:
200 OK –
Body Type:
MetricValueRangeThe query result.
- GET /api/projects/{projectName}/queryMetricValueTable¶
Query Tabular Metric Values.
This allows querying metric values of a specific version with properties flattened out in a tabular format similar to the Issue List API. In contrast to the issue list entry point, this entry point does not support sorting or filtering.
In the Python API this functionality is provided by
axivion.dashboard.Project.fetch_entity_metric_values().- Parameters:
projectName – path
The project name
version – query
The optional analysis version specified as version query string.
Defaults to latest.
forceStrings – query
Restores pre-6.9.2 behaviour, i.e. return all entity-fields as strings. This switch will be removed in a future version.
- Status Codes:
200 OK –
Body Type:
MetricValueTableThe metric value table data.
- GET /projects/{projectName}/querySystemMetrics¶
Use /api/projects/{projectName}/queryMetricValueRange instead.
Deprecated since 6.9.2
- Parameters:
projectName – path
The project name
- Status Codes:
200 OK – An object mapping metric names to arrays each containing the corresponding metric values of the queried range
Types¶
A Project Entity such as a Class, a Method, a File or a Module or the System Entity |
|
Contains a list of entities and the version of their versioned aspects |
|
Describes a Metric as configured for a project in a version |
|
Contains a list of metric descriptions |
|
The result of a metric values query |
|
The result of a metric value table query |
|
An entity table row |
- Entity¶
A Project Entity such as a Class, a Method, a File or a Module or the System Entity.
- Properties:
id (string) The project-wide ID used to refer to this entity.
name (string) a non-unique name of the entity
type (string) The type of the entity
path (string) The file path of an entity if it can be associated with a file
line (integer) The line number of an entity if it can be associated with a file location
- EntityList¶
Contains a list of entities and the version of their versioned aspects.
- Properties:
version (
AnalysisVersion) The version this entity list was queried with.entities (array) Element Type:
Entity.
- Metric¶
Describes a Metric as configured for a project in a version.
- Properties:
name (string) The ID of the metric
displayName (string) a more descriptive name of the metric
minValue (object) The configured minimum threshold for the metric.
Can have two possible string values
-InfinityandInfinityotherwise it is a number. If not configured, this field will not be available.maxValue (object) The configured maximum threshold for the metric.
Can have two possible string values
-InfinityandInfinityotherwise it is a number. If not configured, this field will not be available.
- MetricList¶
Contains a list of metric descriptions.
- Properties:
version (
AnalysisVersion) The version this metric list was queried with.metrics (array) Element Type:
Metric.
- MetricValueRange¶
The result of a metric values query.
- Properties:
startVersion (
AnalysisVersion) The start version of the metric value range.endVersion (
AnalysisVersion) The end version of the metric value range.entity (string) The id of the entity
metric (string) The id of the metric
values (array) Element Type: number. An array with the metric values.
The array size is
endVersion.index - startVersion.index + 1. Its values are numbers ornullif no value is available. They correspond to the range defined bystartVersionandendVersion.
- MetricValueTable¶
The result of a metric value table query.
- Properties:
columns (array) Element Type:
ColumnInfo. The column descriptions of the entity columns.Only contains the two fields
keyandheader.rows (array) Element Type:
MetricValueTableRow. The entity data.
- MetricValueTableRow¶
An entity table row.
Note, that if you specify
forceStrings=truewhen querying the table, the field types will all bestringand the empty string will indicate an absent value.- Properties:
metric (string) The Metric Id
path (string) The source file of the entity definition
line (integer) The source file line number of the entity definition
value (number) The measured or aggregated metric value
entity (string) The non-unique entity name
entityType (string) The entity type
entityId (string) The project-wide entity ID