|
1 | 1 | # `@hyperledger/cactus-plugin-keychain-vault`
|
2 | 2 |
|
3 |
| -> TODO: description |
| 3 | +## Prometheus Exporter |
4 | 4 |
|
5 |
| -## Usage |
| 5 | +This class creates a prometheus exporter, which scrapes the transactions (total transaction count) for the use cases incorporating the use of Keychain vault plugin. |
6 | 6 |
|
| 7 | + |
| 8 | +### Usage |
| 9 | +The prometheus exporter object is initialized in the `PluginKeychainVault` class constructor itself, so instantiating the object of the `PluginKeychainVault` class, gives access to the exporter object. |
| 10 | +You can also initialize the prometheus exporter object seperately and then pass it to the `IPluginKeychainVaultOptions` interface for `PluginKeychainVault` constructor. |
| 11 | + |
| 12 | +`getPrometheusExporterMetricsV1` function returns the prometheus exporter metrics, currently displaying the total key count, which currently increments everytime the `set()` and `delete()` method of the `PluginKeychainVault` class is called. |
| 13 | + |
| 14 | +### Prometheus Integration |
| 15 | +To use Prometheus with this exporter make sure to install [Prometheus main component](https://prometheus.io/download/). |
| 16 | +Once Prometheus is setup, the corresponding scrape_config needs to be added to the prometheus.yml |
| 17 | + |
| 18 | +```(yaml) |
| 19 | +- job_name: 'keychain_vault_exporter' |
| 20 | + metrics_path: api/v1/plugins/@hyperledger/cactus-plugin-keychain-vault/get-prometheus-exporter-metrics |
| 21 | + scrape_interval: 5s |
| 22 | + static_configs: |
| 23 | + - targets: ['{host}:{port}'] |
7 | 24 | ```
|
8 |
| -// TODO: DEMONSTRATE API |
9 |
| -``` |
| 25 | + |
| 26 | +Here the `host:port` is where the prometheus exporter metrics are exposed. The test cases (For example, packages/cactus-plugin-keychain-vault/src/test/typescript/integration/plugin-keychain-vault.test.ts) exposes it over `0.0.0.0` and a random port(). The random port can be found in the running logs of the test case and looks like (42379 in the below mentioned URL) |
| 27 | +`Metrics URL: http://0.0.0.0:42379/api/v1/plugins/@hyperledger/cactus-plugin-keychain-plugin/get-prometheus-exporter-metrics` |
| 28 | + |
| 29 | +Once edited, you can start the prometheus service by referencing the above edited prometheus.yml file. |
| 30 | +On the prometheus graphical interface (defaulted to http://localhost:9090), choose **Graph** from the menu bar, then select the **Console** tab. From the **Insert metric at cursor** drop down, select **cactus_keychain_vault_total_key_count** and click **execute** |
| 31 | + |
| 32 | +### Helper code |
| 33 | + |
| 34 | +###### response.type.ts |
| 35 | +This file contains the various responses of the metrics. |
| 36 | + |
| 37 | +###### data-fetcher.ts |
| 38 | +This file contains functions encasing the logic to process the data points |
| 39 | + |
| 40 | +###### metrics.ts |
| 41 | +This file lists all the prometheus metrics and what they are used for. |
0 commit comments