Skip to content

Commit

Permalink
Add metrics for uni-watcher (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh0 authored Feb 8, 2022
1 parent d5171c2 commit cfd05ea
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/uni-info-watcher/environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[metrics]
host = "127.0.0.1"
port = 8083
port = 8084

[database]
type = "postgres"
Expand Down
4 changes: 4 additions & 0 deletions packages/uni-watcher/environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
host = "127.0.0.1"
port = 3003

[metrics]
host = "127.0.0.1"
port = 8083

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

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

assert(config.server, 'Missing server config');

const { upstream, database: dbConfig, jobQueue: jobQueueConfig } = config;
const { upstream, database: dbConfig, jobQueue: jobQueueConfig, metrics } = config;

assert(dbConfig, 'Missing database config');

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

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

startMetricsServer(metrics.host, metrics.port);
};

main().then(() => {
Expand Down
3 changes: 3 additions & 0 deletions packages/util/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export const lastBlockNumEvents = new promClient.Gauge({
const app: Application = express();

export async function startMetricsServer (host: string, port: number): Promise<void> {
// Add default metrics
promClient.collectDefaultMetrics();

app.get('/metrics', async (req, res) => {
res.setHeader('Content-Type', register.contentType);

Expand Down

0 comments on commit cfd05ea

Please sign in to comment.