Skip to content

Commit

Permalink
Merge pull request #86 from pinax-network/feature/substreams-specific…
Browse files Browse the repository at this point in the history
…-metrics

Substreams specific metrics
  • Loading branch information
JulienR1 authored Nov 23, 2023
2 parents 8e9f939 + d95516b commit a19ae45
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Binary file modified bun.lockb
Binary file not shown.
10 changes: 8 additions & 2 deletions src/clickhouse/handleSinkRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export async function handleSinkRequest({ data, ...metadata }: PayloadBody) {
sqlite.triggerTransaction();
}

prometheus.sink_requests.inc();
prometheus.sink_requests.inc({
chain: metadata.manifest.chain,
module_hash: metadata.manifest.moduleHash,
});
bufferedItems++;

// EntityChanges
Expand Down Expand Up @@ -196,7 +199,10 @@ function insertEntityChange(
)
);

prometheus.entity_changes_inserted.inc();
prometheus.entity_changes_inserted.inc({
chain: metadata.manifest.chain,
module_hash: metadata.manifest.moduleHash,
});
}

// TODO: implement function
Expand Down
15 changes: 7 additions & 8 deletions src/prometheus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export async function metrics() {
return new Response(await registry.metrics(), { status: 200, headers });
}

export function registerCounter(name: string, help: string) {
export function registerCounter<T extends string = string>(name: string, help: string, labels?: T[]) {
try {
registry.registerMetric(new client.Counter({ name, help }));
return registry.getSingleMetric(name) as Counter;
registry.registerMetric(new client.Counter({ name, help, labelNames: labels ?? [] }));
return registry.getSingleMetric(name) as Counter<T>;
} catch (error) {}
}

Expand All @@ -22,12 +22,11 @@ export function registerGauge(name: string, help: string) {
} catch (error) {}
}

export const requests = registerCounter("requests", "Total requests")!
export const requests = registerCounter("requests", "Total requests")!;
export const request_errors = registerCounter("request_errors", "Total failed requests")!;
export const sink_requests = registerCounter("sink_requests", "Total sink requests")!;
export const queue_size = registerGauge("queue_size", "Amount of promises being processed")!;
export const sink_requests = registerCounter("sink_requests", "Total sink requests", ["chain", "module_hash"])!;

export const entity_changes_inserted = registerCounter("entity_changes_inserted", "Total inserted entity changes")!;
export const entity_changes_inserted = registerCounter("entity_changes_inserted", "Total inserted entity changes", ["chain", "module_hash"])!;
export const entity_changes_updated = registerCounter("entity_changes_updated", "Total updated entity changes")!;
export const entity_changes_deleted = registerCounter("entity_changes_deleted", "Total deleted entity changes")!;
export const entity_changes_unsupported = registerCounter("entity_changes_unsupported", "Total unsupported entity changes")!
export const entity_changes_unsupported = registerCounter("entity_changes_unsupported", "Total unsupported entity changes")!;

0 comments on commit a19ae45

Please sign in to comment.