forked from jafar/uptime-kuma-metrics
first commit
This commit is contained in:
commit
e81654136f
2
.env
Normal file
2
.env
Normal file
@ -0,0 +1,2 @@
|
||||
URI=https://uptime.pandawa24jam.com/metrics
|
||||
PASS=uk1_YQR-yznKli6kDXA7D1dECrf_bg44GUQyN0CnMtEG
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
||||
75
index.js
Normal file
75
index.js
Normal file
@ -0,0 +1,75 @@
|
||||
import axios from "axios";
|
||||
import 'dotenv/config';
|
||||
|
||||
function parseKumaMetrics(metricsString) {
|
||||
const lines = metricsString.split("\n").map(line => line.trim()).filter(line => line);
|
||||
const result = {};
|
||||
let currentHelp = null;
|
||||
let currentType = null;
|
||||
|
||||
for (const line of lines) {
|
||||
if (line.startsWith("# HELP")) {
|
||||
const [, metricName, description] = line.match(/^# HELP (\S+) (.+)$/) || [];
|
||||
if (metricName) {
|
||||
currentHelp = description;
|
||||
result[metricName] = { help: currentHelp, type: currentType, metrics: [] };
|
||||
}
|
||||
} else if (line.startsWith("# TYPE")) {
|
||||
const [, metricName, type] = line.match(/^# TYPE (\S+) (\S+)$/) || [];
|
||||
if (metricName) {
|
||||
currentType = type;
|
||||
if (!result[metricName]) {
|
||||
result[metricName] = { help: currentHelp, type: currentType, metrics: [] };
|
||||
} else {
|
||||
result[metricName].type = type;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const metricRegex = /^(\w+)(?:\{([^}]*)\})?\s+([\d.e+-]+)$/;
|
||||
const match = line.match(metricRegex);
|
||||
|
||||
if (match) {
|
||||
const [, metricName, labels, value] = match;
|
||||
const labelObject = {};
|
||||
|
||||
if (labels) {
|
||||
labels.split(",").forEach(pair => {
|
||||
const [key, val] = pair.split("=");
|
||||
labelObject[key.trim()] = val.trim().replace(/^"|"$/g, '');
|
||||
});
|
||||
}
|
||||
|
||||
if (!result[metricName]) {
|
||||
result[metricName] = { help: currentHelp, type: currentType, metrics: [] };
|
||||
}
|
||||
|
||||
result[metricName].metrics.push({ labels: labelObject, value: parseFloat(value) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async function fetchAndParsePrometheusData() {
|
||||
const URI = process.env.URI
|
||||
const PASS = process.env.PASS
|
||||
try {
|
||||
const response = await axios.get(URI, {
|
||||
auth: {
|
||||
username: "", // Empty username
|
||||
password: PASS
|
||||
}
|
||||
});
|
||||
|
||||
const prometheusData = response.data;
|
||||
// console.log("Metrics Data:", prometheusData);
|
||||
|
||||
const jsonData = parseKumaMetrics(prometheusData);
|
||||
console.log(JSON.stringify(jsonData, null, 2));
|
||||
} catch (error) {
|
||||
console.error("Error fetching metrics:", error.message);
|
||||
}
|
||||
}
|
||||
|
||||
fetchAndParsePrometheusData();
|
||||
119
package-lock.json
generated
Normal file
119
package-lock.json
generated
Normal file
@ -0,0 +1,119 @@
|
||||
{
|
||||
"name": "uptime-kuma",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "uptime-kuma",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.9",
|
||||
"dotenv": "^16.4.7"
|
||||
},
|
||||
"devDependencies": {}
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.7.9",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz",
|
||||
"integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.4.7",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz",
|
||||
"integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://dotenvx.com"
|
||||
}
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.9",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
|
||||
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"debug": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz",
|
||||
"integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"dependencies": {
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||
}
|
||||
}
|
||||
}
|
||||
19
package.json
Normal file
19
package.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"axios": "^1.7.9",
|
||||
"dotenv": "^16.4.7"
|
||||
},
|
||||
"type": "module",
|
||||
"name": "uptime-kuma",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev": "nodemon app.js",
|
||||
"prod": "node app.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": ""
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user