-
Notifications
You must be signed in to change notification settings - Fork 1
/
avax-app.js
124 lines (112 loc) · 4.99 KB
/
avax-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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// 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 peerStatus = new prom.Gauge({
name: "peerstatus",
help: "Peer status",
registers: [registry],
labelNames: ["version", "status"]
});
const misc = new prom.Gauge({
name: "misc",
help: "Misc Feed",
registers: [registry],
labelNames: ["value"]
});
// add your IP here or use `localhost`
var ip = 'localhost';
const update = async () => {
try {
try {
// pull prices from coingecko
const dat = await fetch('https://api.coingecko.com/api/v3/simple/price?ids=avalanche-2%2Cbitcoin%2Cethereum&vs_currencies=usd');
const json = await dat.json();
btc_usd = json["bitcoin"].usd;
eth_usd = json["ethereum"].usd;
avax_usd = json['avalanche-2'].usd;
} catch (err) {
console.log(err);
}
try {
const dat = await fetch('https://avascan.info/api/v1/burned-fees');
const json = await dat.json();
burnSupplyX = json["X"];
} catch (err) {
console.log(err);
}
try {
const post = {jsonrpc:"2.0", id: 1, method :"avm.getBalance", params :{address:"X-avax1slt2dhfu6a6qezcn5sgtagumq8ag8we75f84sw",assetID: "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z"}} ;
// might need to use https:// or http:// depending on your set up
const dat = await fetch ('http://'+ip+':9650/ext/bc/X', { headers: { 'content-type': 'application/json' }, method: 'POST', body: JSON.stringify(post)});
const json = await dat.json();
binanceAVAX = json.result.balance * 10**-9;
} catch (err) {
console.log(err);
}
try {
const post = {jsonrpc: "2.0",method: "eth_blockNumber",params: [],id: 1} ;
const dat = await fetch ('http://'+ip+':9650/ext/bc/C/rpc', { headers: { 'content-type': 'application/json' }, method: 'POST', body: JSON.stringify(post)});
const json = await dat.json();
blockNumber = parseInt(json.result, 16);
} catch (err) {
console.log(err);
}
try {
const post = {jsonrpc:"2.0", id:1, method :"platform.getCurrentSupply", params: {}} ;
const dat = await fetch ('http://'+ip+':9650/ext/bc/P', { headers: { 'content-type': 'application/json' }, method: 'POST', body: JSON.stringify(post)});
const json = await dat.json();
AVAXsupply = json.result.supply * 10**-9;
} catch (err) {
console.log(err);
}
try {
const post = {jsonrpc: "2.0", method: "eth_getBalance",params: ["0x0100000000000000000000000000000000000000","latest"],"id": 1} ;
const dat = await fetch ('http://'+ip+':9650/ext/bc/C/rpc', { headers: { 'content-type': 'application/json' }, method: 'POST', body: JSON.stringify(post)});
const json = await dat.json();
burnSupply = json.result * 10**-18;
} catch (err) {
console.log(err);
}
try {
const post = { jsonrpc:"2.0", id: 1, method: "info.peers", params: { nodeIDs: [] } };
const dat = await fetch ('http://'+ip+':9650/ext/info', { headers: { 'content-type': 'application/json' }, method: 'POST', body: JSON.stringify(post)});
const json = await dat.json();
const nodeVersions = [];
for (const node of json.result.peers) {
if (!nodeVersions.includes(node.version)) {
peerStatus.labels(node.version, 'up').set(0);
peerStatus.labels(node.version, 'down').set(0);
nodeVersions.push(node.version);
}
peerStatus.labels(node.version, 'up').inc();
}
} catch (err) {
console.log(err);
}
supplyPostBurn = AVAXsupply-burnSupply-burnSupplyX;
prices.set({ pair: "btc_usd" }, btc_usd);
prices.set({ pair: "eth_usd" }, eth_usd);
prices.set({ pair: "avax_usd" }, avax_usd);
prices.set({ pair: "avax_btc" }, avax_usd / btc_usd);
prices.set({ pair: "avax_eth" }, avax_usd / eth_usd);
misc.set({value: "binanceAVAXsupply"}, binanceAVAX);
misc.set({value: "AVAXsupply"}, AVAXsupply);
misc.set({value: "burnSupply"}, burnSupply);
misc.set({value: "burnSupplyX"}, burnSupplyX);
misc.set({value: "supplyPostBurn"}, supplyPostBurn);
misc.set({value: "blockNumber"}, blockNumber);
} 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);