From 37a4a26e6548597a735c690b026713dff8a40031 Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Wed, 28 Jun 2023 14:32:58 +1200 Subject: [PATCH] feat: Write latest post block height to Grafana --- .../latest-post-metrics-writer.js | 24 +++++++++++++++++++ indexer-js-queue-handler/serverless.yml | 4 ++++ 2 files changed, 28 insertions(+) create mode 100644 indexer-js-queue-handler/latest-post-metrics-writer.js diff --git a/indexer-js-queue-handler/latest-post-metrics-writer.js b/indexer-js-queue-handler/latest-post-metrics-writer.js new file mode 100644 index 000000000..0bece2657 --- /dev/null +++ b/indexer-js-queue-handler/latest-post-metrics-writer.js @@ -0,0 +1,24 @@ +import fetch from "node-fetch"; +import AWS from "aws-sdk"; + +import Metrics from "./metrics"; + +export const handler = async () => { + const metrics = new Metrics("QueryAPI"); + + const response = await fetch("https://api.near.social/index", { + method: "POST", + body: JSON.stringify({ + action: "post", + key: "main", + options: { + limit: 1, + order: "desc", + }, + }), + }); + + const [{ blockHeight }] = await response.json(); + + await metrics.putBlockHeight("social.near", "posts", blockHeight); +}; diff --git a/indexer-js-queue-handler/serverless.yml b/indexer-js-queue-handler/serverless.yml index 62f09cede..c89b29d5c 100644 --- a/indexer-js-queue-handler/serverless.yml +++ b/indexer-js-queue-handler/serverless.yml @@ -39,6 +39,10 @@ constructs: timeout: 15 # 1.5 minutes as lift multiplies this value by 6 (https://github.com/getlift/lift/blob/master/docs/queue.md#retry-delay) functions: + latestPostMetricsWriter: + handler: latest-post-metrics-writer.handler + events: + - schedule: rate(1 minute) plugins: - serverless-lift