-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeneralized-app.js
47 lines (44 loc) · 1.59 KB
/
generalized-app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Specialized custom feed for avalanche nodes
const http = require("http"); process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; const prom = require("prom-client"); const fetch = require("node-fetch"); const _ = require("underscore"); const registry = new prom.Registry(); const
prices = new prom.Gauge({
name: "prices",
help: "Token prices",
registers: [registry],
labelNames: ["pair"]
});
const misc = new prom.Gauge({
name: "misc",
help: "Misc Feed",
registers: [registry],
labelNames: ["value"]
});
// add your IP here
var ip = '127.0.0.1';
const update = async () => {
try {
try {
// pull prices from coingecko
// add the coin you want to pull here
const dat = await fetch('https://api.coingecko.com/api/v3/simple/price?ids=kira-network%2Cbitcoin%2Cethereum&vs_currencies=usd');
const json = await dat.json();
btc_usd = json["bitcoin"].usd;
eth_usd = json["ethereum"].usd;
kex_usd = json['kira-network'].usd;
} catch (err) {
console.log(err);
}
prices.set({ pair: "btc_usd" }, btc_usd);
prices.set({ pair: "eth_usd" }, eth_usd);
prices.set({ pair: "kex_usd" }, kex_usd);
prices.set({ pair: "kex_btc" }, kex_usd / btc_usd);
prices.set({ pair: "kex_eth" }, kex_usd / eth_usd);
} catch (err) {
console.log(err);
}
};
setInterval(update, 15000); update(); http.createServer(async (req,res) => {
console.log(req.url);
res.write(await registry.metrics());
res.end();
//using port 9800 for prometheus
}).listen(9800);