Expose Prometheus metrics

  • Updated

What is Prometheus?

Prometheus is an open-source monitoring system with a queryable time series database. Starting in 4.5.2, Configured Commerce exposes a Prometheus exporter that contains timing data for pipes, pipelines, handlers, and handler chains. By collecting this data, slow code can be identified without the need for a profiler.

Enable Collection of Timing Data

Starting in 4.6.0, Prometheus exporters are enabled by default in the Unity config. For other versions, or to edit the settings for those metrics, edit the Unity interception rules in .\B2B Commerce.Web\App_Config\unity.config. The example below shows an interception policy that collects timing data for all classes that implement the IPipe interface:

<policy  name="InterceptPipes">    <matchingRule name="PipeMatch" type="TypeMatchingRule">      <constructor>        <param name="typeName" value="IPipe`2"/>      </constructor>    </matchingRule>    <callHandler name="PipeDurationHandler" type="Insite.IocContainer.Unity.AOP.PrometheusDurationHandler, Insite.IocContainer.Unity"/>  </policy>    

The default unity.config file contains interception policies for pipes, pipelines, handlers, and handler chains, which can be enabled by uncommenting those policies.

Configure Username and Password for Prometheus Exporter

The metrics are exposed at /api/v1/admin/metrics and require basic authentication. The MetricsUsername and MetricsPassword can be configured in .\B2B Commerce.Web\config\appSettings.config. If the username and password are not set, the metrics will not be available.

<addkey="MetricsUsername"value="[MetricsUsername]" /><addkey="MetricsPassword"value="[MetricsPassword]" />

Visualize Metrics

In the insite-commerce-cloud repo under the tools directory, go to the Prometheus-Grafana-Stack. This folder contains tools and instructions that help visualize and query the metrics.