项目作者: alexey-lapin

项目描述 :
Extension library for using micrometer in Pega PRPC
高级语言: Java
项目地址: git://github.com/alexey-lapin/micrometer-prpc.git
创建时间: 2018-11-25T18:50:02Z
项目社区:https://github.com/alexey-lapin/micrometer-prpc

开源协议:MIT License

下载


micrometer-prpc

Latest release
Build Status
codecov

Pega PRPC + Micrometer = :heart:

Expose your business and technical metrics from Pega to any monitoring system.

This small library aims to simplify usage of Micrometer for collecting metrics in
Pega PRPC environment. Developers can use familiar concept of ‘rules’
to implement metric value sources.

dashboard

PRPC version tested
7.3.0 :heavy_check_mark:
8.2.1 :heavy_check_mark:

Java 8+ required.

Build

Prerequisites

In order to build the project locally, you have to satisfy dependency prerequisites.

This project does not include any dependencies or any proprietary code.
It is intended to be used by authorized Pegasystems Inc clients in their Pega PRPC environments.

This library relies on some internal PRPC jars which usually could be found in
<pega-distributive>.zip/archives/pegadbinstall-classes.zip/lib:

  • prbootstrap
  • prbootstrap-api
  • prenginext
  • pricu2jdk
  • prprivate
  • prpublic

The following command will help to install the required jars to a local maven repository:

  1. ./mvnw install:install-file -Dfile=<path-to-prpc-libs>/<lib>.jar -DgroupId=com.pega.prpc -DartifactId=<lib> -Dversion=<version.prpc> -Dpackaging=jar -Dversion.prpc=<version.prpc>

Package

After the required jars are installed you may use the following command to build project:

  1. ./mvnw package -Dversion.prpc=<version.prpc>

Install

Deploy the following jars to the PRPC instance as usual (from UI or service):

  • micrometer-core-\.jar
  • micrometer-registry-\-\.jar - one or multiple registry libs and its dependencies
  • micrometer-prpc-\.jar

Use

Create sources:

  1. // Sql source
  2. PrpcSource source = SqlSource.builder()
  3. .queryString("select FirstProperty as \"Tag(first)\", " +
  4. "SecondProperty as \"Tag(second)\", " +
  5. "ThirdProperty as \"Value(count)\" " +
  6. "from {CLASS:Some-Data-Class}")
  7. .groupPropName("pxPages")
  8. .expirationDuration(2)
  9. .expirationTimeUnit(TimeUnit.MINUTES)
  10. .build();
  11. // Data Page source
  12. PrpcSource source = DataPageSource.builder()
  13. .ruleName("D_SomeDataPage")
  14. .accessGroupName("Some:AccessGroup")
  15. .resultsPropName("pxResults")
  16. .groupPropName("pxPages")
  17. .expirationDuration(5)
  18. .expirationTimeUnit(TimeUnit.MINUTES)
  19. .build();
  20. // Activity source
  21. PrpcSource source = ActivitySource.builder()
  22. .ruleName("SomeActivity")
  23. .ruleClass("Some-Class")
  24. .accessGroupName("Some:AccessGroup")
  25. .resultsPropName("pxResults")
  26. .groupPropName("pxPages")
  27. .expirationDuration(10)
  28. .expirationTimeUnit(TimeUnit.MINUTES)
  29. .build();

A source should construct the following clipboard structure:

  1. TopLevelPage [Page]
  2. pxResults(1) [Page List]
  3. Tag(tag_name_1) tagValue1 [Value Group]
  4. Tag(tag_name_2) tagValue2
  5. Value(count_1) 10 [Value Group]
  6. Value(count_2) 15
  7. pxResults(2)
  8. Tag(tag_name_1) tagValue3
  9. Tag(tag_name_2) tagValue4
  10. Value(count_1) 7
  11. Value(count_2) 13
  12. ...

Register metrics:

  1. // Create registry
  2. MeterRegistry registry = ...
  3. // Gauge - register single metric
  4. registry.gauge("metric.gauge.single", source, PrpcCallback.strong(source, "PropertyReference"));
  5. // MultiGauge - register multiple metrics with unique tags
  6. PrpcMultiGauge mg = PrpcMultiGauge.builder("metric.gauge.multi")
  7. .registry(registry)
  8. .source(source)
  9. .valuePropName("PropertyReference")
  10. .build();
  11. // Counter
  12. registry.more().counter("metric.counter.single", Tags.empty(), source, PrpcCallback.strong(source, "PropertyReference"));

For more information about micrometer features visit micrometer docs page.

Prometheus + Grafana example

  1. Deploy libs:
  1. Implement startup agent:
    ```java
    // Initialize registry and store it
    MeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
    Metrics.getInstance().registries().put(“prometheus”, registry);

// Create source from out-of-the-box data page - D_pzNodeInformation
PrpcSource source = DataPageSource.builder()
.ruleName(“D_pzNodeInformation”)
.expirationDuration(2)
.expirationTimeUnit(TimeUnit.MINUTES)
.build();

// Register meters which have constant tags cardinality during app lifetime
registry.gauge(“prpc.node.requestors”, source, PrpcCallback.strong(source, “pxNumberRequestors”));
registry.gauge(“prpc.node.agents”, source, PrpcCallback.strong(source, “pxNumberAgents”));
registry.gauge(“prpc.node.listeners”, source, PrpcCallback.strong(source, “pxNumberListeners”));

registry.more().counter(“prpc.node.requestors.initiated”, Tags.of(“type”, “browser”), source, PrpcCallback.strong(source, “pxNumberBrowserInitiatedRequestorStarts”));
registry.more().counter(“prpc.node.requestors.initiated”, Tags.of(“type”, “batch”), source, PrpcCallback.strong(source, “pxNumberBatchInitiatedRequestorStarts”));
registry.more().counter(“prpc.node.requestors.initiated”, Tags.of(“type”, “service”), source, PrpcCallback.strong(source, “pxNumberServiceInitiatedRequestorStarts”));
registry.more().counter(“prpc.node.requestors.initiated”, Tags.of(“type”, “portlet”), source, PrpcCallback.strong(source, “pxNumberPortletInitiatedRequestorStarts”));

// Create custom activity source
PrpcSource source = ActivitySource.builder()
.ruleName(“MetricRequestorPools”)
.ruleClass(“Code-Pega-List”)
.accessGroupName(“Metrics”)
.resultsPropName(“pxResults”)
.groupPropName(“pxPages”)
.expirationDuration(2)
.expirationTimeUnit(TimeUnit.Minutes)
.build();

// Register meters which have various tags cardinality during app lifetime
PrpcMultiGauge mg = PrpcMultiGauge.builder(“prpc.requestor.pools.active”)
.registry(registry)
.source(source)
.valuePropName(“Value(active)”)
.build();

// Store to cache
Metrics.getInstance().meters().add(mg);

mg.register();

  1. 3. Implement recurring agent (eg. every 10 minutes)
  2. ```java
  3. // Get stored multi meters and re-register
  4. Metrics.getInstance().meters().register();
  1. Implement rest service:
    1. // Obtain registry and get textual representation of metrics
    2. PrometheusMeterRegistry registry = (PrometheusMeterRegistry) Metrics.getInstance().registries().get("prometheus");
    3. if (registry != null) {
    4. response = registry.scrape();
    5. }

The following setup results to a response which looks like:

  1. # HELP prpc_node_listeners
  2. # TYPE prpc_node_listeners gauge
  3. prpc_node_listeners 0.0
  4. # HELP prpc_node_agents
  5. # TYPE prpc_node_agents gauge
  6. prpc_node_agents 56.0
  7. # HELP prpc_node_active_threads
  8. # TYPE prpc_node_active_threads gauge
  9. prpc_node_active_threads 30.0
  10. # HELP prpc_node_requestors_initiated_total
  11. # TYPE prpc_node_requestors_initiated_total counter
  12. prpc_node_requestors_initiated_total{type="service",} 4.0
  13. prpc_node_requestors_initiated_total{type="browser",} 1.0
  14. prpc_node_requestors_initiated_total{type="portlet",} 0.0
  15. prpc_node_requestors_initiated_total{type="batch",} 576.0
  16. # HELP prpc_node_requestors
  17. # TYPE prpc_node_requestors gauge
  18. prpc_node_requestors 14.0
  19. # HELP prpc_node_production_level
  20. # TYPE prpc_node_production_level gauge
  21. prpc_node_production_level 2.0
  1. Configure Prometheus to scrape created rest service URL.
  2. Configure Prometheus data source in Grafana.
  3. Create dashboard in Grafana which could look like image above.