MCPcopy Create free account
hub / github.com/Consensys/doc.linea / fetchData

Function fetchData

scripts/fetchNodeSize.js:55–168  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53}
54
55const fetchData = async () => {
56 console.log("Starting data fetch...");
57
58 const baseUrl =
59 "https://mimir.o11y.web3factory.consensys.net/prometheus/api/v1/query_range";
60
61 const results = [];
62
63 for (const { network, cluster, pvc } of NODE_SIZE_TARGETS) {
64 console.log(
65 `Fetching data for network: ${network}, cluster: ${cluster}, pvc: ${pvc}`,
66 );
67
68 // Subtracts available bytes from capacity bytes to get the used bytes
69 const query = `
70 sum without(instance, node) (topk(1, (kubelet_volume_stats_capacity_bytes{linea_network="${network}", cluster="${cluster}", persistentvolumeclaim="${pvc}", job="kubelet", metrics_path="/metrics"})))
71 -
72 sum without(instance, node) (topk(1, (kubelet_volume_stats_available_bytes{linea_network="${network}", cluster="${cluster}", persistentvolumeclaim="${pvc}", job="kubelet", metrics_path="/metrics"})))
73 `;
74
75 const endTime = Math.floor(Date.now() / 1000);
76 const startTime = endTime - 24 * 60 * 60; // 24 hours ago
77 const step = 120; // 2 minutes, matching Grafana's step size
78
79 const url = `${baseUrl}?query=${encodeURIComponent(query)}&start=${startTime}&end=${endTime}&step=${step}`;
80 console.log(`Constructed URL: ${url}`);
81
82 try {
83 const response = await axios.get(url, {
84 auth: {
85 username: process.env.LINEA_OBSERVABILITY_USER,
86 password: process.env.LINEA_OBSERVABILITY_PASS,
87 },
88 });
89
90 console.log(
91 `Response received for network: ${network}, cluster: ${cluster}, pvc: ${pvc}`,
92 );
93 const result = response.data.data.result[0];
94 let values = result.values;
95 console.log(`Number of data points received: ${values.length}`);
96 if (values.length >= 2) {
97 const startTime = new Date(values[0][0] * 1000);
98 const endTime = new Date(values[values.length - 1][0] * 1000);
99 const timeDiffHours = (endTime - startTime) / (1000 * 60 * 60);
100 console.log(
101 `Time range: ${startTime.toISOString()} to ${endTime.toISOString()}`,
102 );
103 console.log(`Time difference: ${timeDiffHours.toFixed(2)} hours`);
104 }
105
106 // Filter out invalid data points
107 values = values.filter((value) => !isNaN(parseFloat(value[1])));
108 if (values.length !== result.values.length) {
109 console.warn(
110 `Filtered out ${result.values.length - values.length} invalid data points for ${pvc}`,
111 );
112 }

Callers 1

fetchNodeSize.jsFile · 0.85

Calls 2

calculateDailyIncreaseFunction · 0.85
getWeekNumberFunction · 0.85

Tested by

no test coverage detected