Skip to content

Commit

Permalink
feat: Write latest post block height to Grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Jun 28, 2023
1 parent 3ab0a84 commit 37a4a26
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions indexer-js-queue-handler/latest-post-metrics-writer.js
Original file line number Diff line number Diff line change
@@ -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);
};
4 changes: 4 additions & 0 deletions indexer-js-queue-handler/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37a4a26

Please sign in to comment.