forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(quorum): add prometheus exporter
Primary Change -------------- 1. The quorum ledger connector plugin now includes the prometheus metrics exporter integration 2. OpenAPI spec now has api endpoint for the getting the prometheus metrics Refactorings that were also necessary to accomodate 1) and 2) ------------------------------------------------------------ 3. GetPrometheusMetricsV1 class is created to handle the corresponding api endpoint 4. IPluginLedgerConnectorQuorumOptions interface in PluginLedgerConnectorQuorum class now has a prometheusExporter optional field 5. The PluginLedgerConnectorQuorum class has relevant functions and codes to incorporate prometheus exporter 6. deploy-contract-from-json.test.ts is changed to incorporate the prometheus exporter 7. Added Readme.md on the prometheus exporter usage Fixes hyperledger-cacti#534 Signed-off-by: Jagpreet Singh Sasan <jagpreet.singh.sasan@accenture.com>
- Loading branch information
1 parent
aa070ad
commit 8be6aab
Showing
12 changed files
with
394 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/cactus-plugin-ledger-connector-quorum/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...us-plugin-ledger-connector-quorum/src/main/typescript/prometheus-exporter/data.fetcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Transactions } from "./response.type"; | ||
|
||
import { totalTxCount } from "./metrics"; | ||
|
||
export async function collectMetrics(transactions: Transactions) { | ||
totalTxCount.labels("cactus_quorum_total_tx_count").set(transactions.counter); | ||
} |
7 changes: 7 additions & 0 deletions
7
.../cactus-plugin-ledger-connector-quorum/src/main/typescript/prometheus-exporter/metrics.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Gauge } from "prom-client"; | ||
|
||
export const totalTxCount = new Gauge({ | ||
name: "cactus_quorum_total_tx_count", | ||
help: "Total transactions executed", | ||
labelNames: ["type"], | ||
}); |
41 changes: 41 additions & 0 deletions
41
...in-ledger-connector-quorum/src/main/typescript/prometheus-exporter/prometheus-exporter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import promClient from "prom-client"; | ||
import { Transactions } from "./response.type"; | ||
import { totalTxCount } from "./metrics"; | ||
|
||
export const K_CACTUS_QUORUM_TOTAL_TX_COUNT = "cactus_quorum_total_tx_count"; | ||
|
||
export interface IPrometheusExporterOptions { | ||
pollingIntervalInMin?: number; | ||
} | ||
|
||
export class PrometheusExporter { | ||
public readonly metricsPollingIntervalInMin: number; | ||
public readonly transactions: Transactions = { counter: 0 }; | ||
|
||
constructor( | ||
public readonly prometheusExporterOptions: IPrometheusExporterOptions, | ||
) { | ||
this.metricsPollingIntervalInMin = | ||
prometheusExporterOptions.pollingIntervalInMin || 1; | ||
} | ||
|
||
public addCurrentTransaction(): void { | ||
this.transactions.counter++; | ||
totalTxCount | ||
.labels(K_CACTUS_QUORUM_TOTAL_TX_COUNT) | ||
.set(this.transactions.counter); | ||
} | ||
|
||
public async getPrometheusMetrics(): Promise<string> { | ||
const result = await promClient.register.getSingleMetricAsString( | ||
K_CACTUS_QUORUM_TOTAL_TX_COUNT, | ||
); | ||
return result; | ||
} | ||
|
||
public startMetricsCollection(): void { | ||
const Registry = promClient.Registry; | ||
const register = new Registry(); | ||
promClient.collectDefaultMetrics({ register }); | ||
} | ||
} |
Oops, something went wrong.