Developer Documentation Library > Web API > Web API application > Metrics for the Web API
 
Metrics for the Web API
The Web API collects and stores application performance metrics. Only authorized users can access any of the /Metrics endpoints. By default, only users in the DPM Admin role or the Prometheus OAuth2.0 client can access metrics.
JSON format
You can retrieve all Web API metrics in JSON format from the /Metrics endpoint. Metrics are grouped into “contexts”; you can get the names of the contexts from the /Metrics/Contexts endpoint. To get the metrics for a single context, use the /Metrics/Contexts/<contextName> endpoint.
Prometheus
Prometheus can scrape all of the metrics by using the /Metrics/Prometheus endpoint; it returns the same metric data, but in the format that is required by Prometheus.
To configure Prometheus for OAuth2.0 client credentials, use a scrape that is similar to the one that follows.
The following example handles multiple instances of the Web API that are on the same server (for example, \SPSSMR\WebApi and \SPSSMR\WebApi2), if multiple instances have been configured in IIS.
Change the /Site/Properties/Oidc/Clients/Prometheus/ClientSecrets value in DPM to a unique, secret value, because any client that knows that secret value can access the metrics if the Web API is publicly accessible.
In the token_url property, use the same hostname as the \Site\Properties\Oidc\PublicUrl property.
The targets property can use the internal hostname of the Web API, if needed.
- job_name: WebApi
scheme: http
oauth2:
client_id: Prometheus
client_secret: '<ClientSecrets value from DPM>'
scopes:
- intelligence_web_api
token_url: http://<public_hostname>/SPSSMR/Oidc/connect/token
static_configs:
- targets: ['<hostname>/SPSSMR/WebApi/Metrics/Prometheus']
relabel_configs:
- source_labels: [__address__]
regex: '([^/]+)/SPSSMR/([^/]*).*'
replacement: '${1}_${2}' # Format: <hostname>_WebApi
target_label: instance # change instance label
- source_labels: [__address__]
regex: '([^/]+).*'
target_label: server
- source_labels: [__address__]
regex: '[^/]+(/.*)' # capture '/...' part
target_label: __metrics_path__ # change metrics path label
- source_labels: [__address__]
regex: '([^/]+)/.*' # capture host:port
target_label: __address__ # change target label
All defined metrics
The /Metrics and /Metrics/Prometheus endpoints return only the metrics that have been captured. You can get a list of metrics that could be returned from the /Metrics/Defined endpoint. This uses the “Accept” header to return the response in either JSON format or HTML format. For example, if you go to https://<hostname>/SPSSMR/WebApi/Metrics/Defined?Api-Version=1.1 by using Chrome, it displays an HTML view of the defined metrics. (You must include the Api-Version=1.1 parameter in the URL, because the /Metrics/Defined endpoint was added in v1.1 of the Intelligence.WebApi.Core component.)
See
Web API application