Skip to content

Commit

Permalink
Add prometheus metrics support for watchers (#152)
Browse files Browse the repository at this point in the history
* Add prometheus metrics endpoint in watcher

* Add event, sync status and DB size metrics

* Fix subgraph watchers DB entities directory path

* Make watcher metrics optional using config
  • Loading branch information
nikugogoi authored Aug 3, 2022
1 parent 1bcabd6 commit a153054
Show file tree
Hide file tree
Showing 46 changed files with 331 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const main = async (): Promise<void> => {
await db.init();
{{#if (subgraphPath)}}

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
4 changes: 4 additions & 0 deletions packages/codegen/src/templates/config-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
# Use -1 for skipping check on block range.
maxEventsBlockRange = 1000

[metrics]
host = "127.0.0.1"
port = 9000

[database]
type = "postgres"
host = "localhost"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const main = async (): Promise<void> => {
await db.init();
{{#if (subgraphPath)}}

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const main = async (): Promise<any> => {
await db.init();
{{#if (subgraphPath)}}

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const main = async (): Promise<void> => {
await db.init();
{{#if (subgraphPath)}}

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const main = async (): Promise<void> => {
await db.init();
{{#if (subgraphPath)}}

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
JOB_KIND_PRUNE,
JobQueueConfig,
DEFAULT_CONFIG_PATH,
initClients
initClients,
startMetricsServer
} from '@vulcanize/util';
{{#if (subgraphPath)}}
import { GraphWatcher, Database as GraphDatabase } from '@vulcanize/graph-node';
Expand Down Expand Up @@ -286,6 +287,8 @@ export const main = async (): Promise<any> => {

const jobRunner = new JobRunner(jobQueueConfig, indexer, jobQueue);
await jobRunner.start();

startMetricsServer(config, indexer);
};

main().then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const handler = async (argv: any): Promise<void> => {
await db.init();
{{#if (subgraphPath)}}

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const main = async (): Promise<void> => {
await db.init();
{{#if (subgraphPath)}}

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
4 changes: 4 additions & 0 deletions packages/eden-watcher/environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
# Use -1 for skipping check on block range.
maxEventsBlockRange = 1000

[metrics]
host = "127.0.0.1"
port = 9000

[database]
type = "postgres"
host = "localhost"
Expand Down
2 changes: 1 addition & 1 deletion packages/eden-watcher/src/cli/checkpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const main = async (): Promise<void> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
2 changes: 1 addition & 1 deletion packages/eden-watcher/src/cli/export-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const main = async (): Promise<void> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
2 changes: 1 addition & 1 deletion packages/eden-watcher/src/cli/import-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const main = async (): Promise<any> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
2 changes: 1 addition & 1 deletion packages/eden-watcher/src/cli/index-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const main = async (): Promise<void> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
2 changes: 1 addition & 1 deletion packages/eden-watcher/src/cli/inspect-cid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const main = async (): Promise<void> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
2 changes: 1 addition & 1 deletion packages/eden-watcher/src/cli/reset-cmds/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const handler = async (argv: any): Promise<void> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
2 changes: 1 addition & 1 deletion packages/eden-watcher/src/cli/watch-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const main = async (): Promise<void> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
5 changes: 4 additions & 1 deletion packages/eden-watcher/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
JOB_KIND_PRUNE,
JobQueueConfig,
DEFAULT_CONFIG_PATH,
initClients
initClients,
startMetricsServer
} from '@vulcanize/util';
import { GraphWatcher, Database as GraphDatabase } from '@vulcanize/graph-node';

Expand Down Expand Up @@ -278,6 +279,8 @@ export const main = async (): Promise<any> => {

const jobRunner = new JobRunner(jobQueueConfig, indexer, jobQueue);
await jobRunner.start();

startMetricsServer(config, indexer);
};

main().then(() => {
Expand Down
4 changes: 4 additions & 0 deletions packages/erc20-watcher/environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
mode = "eth_call"
kind = "lazy"

[metrics]
host = "127.0.0.1"
port = 9000

[database]
type = "postgres"
host = "localhost"
Expand Down
5 changes: 4 additions & 1 deletion packages/erc20-watcher/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
QUEUE_EVENT_PROCESSING,
JobQueueConfig,
DEFAULT_CONFIG_PATH,
initClients
initClients,
startMetricsServer
} from '@vulcanize/util';

import { Indexer } from './indexer';
Expand Down Expand Up @@ -87,6 +88,8 @@ export const main = async (): Promise<any> => {

const jobRunner = new JobRunner(jobQueueConfig, indexer, jobQueue);
await jobRunner.start();

startMetricsServer(config, indexer);
};

main().then(() => {
Expand Down
4 changes: 4 additions & 0 deletions packages/erc721-watcher/environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
# Use -1 for skipping check on block range.
maxEventsBlockRange = 1000

[metrics]
host = "127.0.0.1"
port = 9000

[database]
type = "postgres"
host = "localhost"
Expand Down
5 changes: 4 additions & 1 deletion packages/erc721-watcher/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
JOB_KIND_PRUNE,
JobQueueConfig,
DEFAULT_CONFIG_PATH,
initClients
initClients,
startMetricsServer
} from '@vulcanize/util';

import { Indexer } from './indexer';
Expand Down Expand Up @@ -265,6 +266,8 @@ export const main = async (): Promise<any> => {

const jobRunner = new JobRunner(jobQueueConfig, indexer, jobQueue);
await jobRunner.start();

startMetricsServer(config, indexer);
};

main().then(() => {
Expand Down
4 changes: 4 additions & 0 deletions packages/graph-test-watcher/environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
# Use -1 for skipping check on block range.
maxEventsBlockRange = 1000

[metrics]
host = "127.0.0.1"
port = 9000

[database]
type = "postgres"
host = "localhost"
Expand Down
2 changes: 1 addition & 1 deletion packages/graph-test-watcher/src/cli/checkpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const main = async (): Promise<void> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
2 changes: 1 addition & 1 deletion packages/graph-test-watcher/src/cli/export-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const main = async (): Promise<void> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
2 changes: 1 addition & 1 deletion packages/graph-test-watcher/src/cli/import-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const main = async (): Promise<any> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
2 changes: 1 addition & 1 deletion packages/graph-test-watcher/src/cli/index-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const main = async (): Promise<void> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
2 changes: 1 addition & 1 deletion packages/graph-test-watcher/src/cli/inspect-cid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const main = async (): Promise<void> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
2 changes: 1 addition & 1 deletion packages/graph-test-watcher/src/cli/reset-cmds/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const handler = async (argv: any): Promise<void> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
2 changes: 1 addition & 1 deletion packages/graph-test-watcher/src/cli/watch-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const main = async (): Promise<void> => {
const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, '../entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
Expand Down
5 changes: 4 additions & 1 deletion packages/graph-test-watcher/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
JOB_KIND_PRUNE,
JobQueueConfig,
DEFAULT_CONFIG_PATH,
initClients
initClients,
startMetricsServer
} from '@vulcanize/util';
import { GraphWatcher, Database as GraphDatabase } from '@vulcanize/graph-node';

Expand Down Expand Up @@ -278,6 +279,8 @@ export const main = async (): Promise<any> => {

const jobRunner = new JobRunner(jobQueueConfig, indexer, jobQueue);
await jobRunner.start();

startMetricsServer(config, indexer);
};

main().then(() => {
Expand Down
4 changes: 4 additions & 0 deletions packages/mobymask-watcher/environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
# Use -1 for skipping check on block range.
maxEventsBlockRange = -1

[metrics]
host = "127.0.0.1"
port = 9000

[database]
type = "postgres"
host = "localhost"
Expand Down
5 changes: 4 additions & 1 deletion packages/mobymask-watcher/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
JOB_KIND_PRUNE,
JobQueueConfig,
DEFAULT_CONFIG_PATH,
initClients
initClients,
startMetricsServer
} from '@vulcanize/util';

import { Indexer } from './indexer';
Expand Down Expand Up @@ -265,6 +266,8 @@ export const main = async (): Promise<any> => {

const jobRunner = new JobRunner(jobQueueConfig, indexer, jobQueue);
await jobRunner.start();

startMetricsServer(config, indexer);
};

main().then(() => {
Expand Down
4 changes: 4 additions & 0 deletions packages/uni-info-watcher/environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# Mode demo whitelists all tokens so that entity values get updated.
mode = "demo"

[metrics]
host = "127.0.0.1"
port = 9000

[database]
type = "postgres"
host = "localhost"
Expand Down
5 changes: 4 additions & 1 deletion packages/uni-info-watcher/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
JobRunner as BaseJobRunner,
JobQueueConfig,
DEFAULT_CONFIG_PATH,
initClients
initClients,
startMetricsServer
} from '@vulcanize/util';

import { Indexer } from './indexer';
Expand Down Expand Up @@ -99,6 +100,8 @@ export const main = async (): Promise<any> => {

const jobRunner = new JobRunner(jobQueueConfig, indexer, jobQueue);
await jobRunner.start();

startMetricsServer(config, indexer);
};

main().then(() => {
Expand Down
Loading

0 comments on commit a153054

Please sign in to comment.