mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-01-28 15:27:03 -05:00
add 4 uptime metrics in prometheus
This commit is contained in:
parent
be2faf64ce
commit
bbc6e3383c
@ -980,7 +980,15 @@ class Monitor extends BeanModel {
|
|||||||
await R.store(bean);
|
await R.store(bean);
|
||||||
|
|
||||||
log.debug("monitor", `[${this.name}] prometheus.update`);
|
log.debug("monitor", `[${this.name}] prometheus.update`);
|
||||||
this.prometheus?.update(bean, tlsInfo);
|
let uptimeMetrics = {};
|
||||||
|
let data24h = await uptimeCalculator.get24Hour();
|
||||||
|
let data30d = await uptimeCalculator.get30Day();
|
||||||
|
let data1y = await uptimeCalculator.get1Year();
|
||||||
|
uptimeMetrics.avgPing = data24h.avgPing ? Number(data24h.avgPing.toFixed(2)) : null;
|
||||||
|
uptimeMetrics.data24h = data24h.uptime;
|
||||||
|
uptimeMetrics.data30d = data30d.uptime;
|
||||||
|
uptimeMetrics.data1y = data1y.uptime;
|
||||||
|
this.prometheus?.update(bean, tlsInfo, uptimeMetrics);
|
||||||
|
|
||||||
previousBeat = bean;
|
previousBeat = bean;
|
||||||
|
|
||||||
@ -1730,7 +1738,7 @@ class Monitor extends BeanModel {
|
|||||||
*/
|
*/
|
||||||
async handleTlsInfo(tlsInfo) {
|
async handleTlsInfo(tlsInfo) {
|
||||||
await this.updateTlsInfo(tlsInfo);
|
await this.updateTlsInfo(tlsInfo);
|
||||||
this.prometheus?.update(null, tlsInfo);
|
this.prometheus?.update(null, tlsInfo, null);
|
||||||
|
|
||||||
if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) {
|
if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) {
|
||||||
log.debug("monitor", `[${this.name}] call checkCertExpiryNotifications`);
|
log.debug("monitor", `[${this.name}] call checkCertExpiryNotifications`);
|
||||||
|
@ -20,6 +20,31 @@ const monitorCertIsValid = new PrometheusClient.Gauge({
|
|||||||
help: "Is the certificate still valid? (1 = Yes, 0= No)",
|
help: "Is the certificate still valid? (1 = Yes, 0= No)",
|
||||||
labelNames: commonLabels
|
labelNames: commonLabels
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const monitorUptime1y = new PrometheusClient.Gauge({
|
||||||
|
name: "monitor_uptime_1y",
|
||||||
|
help: "Monitor Uptime 1y (%)",
|
||||||
|
labelNames: commonLabels,
|
||||||
|
});
|
||||||
|
|
||||||
|
const monitorUptime30d = new PrometheusClient.Gauge({
|
||||||
|
name: "monitor_uptime_30d",
|
||||||
|
help: "Monitor Uptime 30d (%)",
|
||||||
|
labelNames: commonLabels,
|
||||||
|
});
|
||||||
|
|
||||||
|
const monitorUptime24h = new PrometheusClient.Gauge({
|
||||||
|
name: "monitor_uptime_24h",
|
||||||
|
help: "Monitor Uptime 24h (%)",
|
||||||
|
labelNames: commonLabels,
|
||||||
|
});
|
||||||
|
|
||||||
|
const monitorAverageResponseTime = new PrometheusClient.Gauge({
|
||||||
|
name: "monitor_average_response_time",
|
||||||
|
help: "Monitor Average Response Time (ms)",
|
||||||
|
labelNames: commonLabels,
|
||||||
|
});
|
||||||
|
|
||||||
const monitorResponseTime = new PrometheusClient.Gauge({
|
const monitorResponseTime = new PrometheusClient.Gauge({
|
||||||
name: "monitor_response_time",
|
name: "monitor_response_time",
|
||||||
help: "Monitor Response Time (ms)",
|
help: "Monitor Response Time (ms)",
|
||||||
@ -54,7 +79,7 @@ class Prometheus {
|
|||||||
* @param {object} tlsInfo TLS details
|
* @param {object} tlsInfo TLS details
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
update(heartbeat, tlsInfo) {
|
update(heartbeat, tlsInfo, uptime) {
|
||||||
|
|
||||||
if (typeof tlsInfo !== "undefined") {
|
if (typeof tlsInfo !== "undefined") {
|
||||||
try {
|
try {
|
||||||
@ -80,6 +105,76 @@ class Prometheus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (uptime) {
|
||||||
|
if (typeof uptime.avgPing !== "undefined") {
|
||||||
|
try {
|
||||||
|
if (typeof uptime.avgPing === "number") {
|
||||||
|
monitorAverageResponseTime.set(
|
||||||
|
this.monitorLabelValues,
|
||||||
|
uptime.avgPing
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Is it good?
|
||||||
|
monitorAverageResponseTime.set(
|
||||||
|
this.monitorLabelValues,
|
||||||
|
-1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.error("prometheus", "Caught error");
|
||||||
|
log.error("prometheus", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof uptime.data24h !== "undefined") {
|
||||||
|
try {
|
||||||
|
if (typeof uptime.data24h === "number") {
|
||||||
|
monitorUptime24h.set(
|
||||||
|
this.monitorLabelValues,
|
||||||
|
uptime.data24h
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Is it good?
|
||||||
|
monitorUptime24h.set(this.monitorLabelValues, -1);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.error("prometheus", "Caught error");
|
||||||
|
log.error("prometheus", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof uptime.data30d !== "undefined") {
|
||||||
|
try {
|
||||||
|
if (typeof uptime.data30d === "number") {
|
||||||
|
monitorUptime30d.set(
|
||||||
|
this.monitorLabelValues,
|
||||||
|
uptime.data30d
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Is it good?
|
||||||
|
monitorUptime30d.set(this.monitorLabelValues, -1);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.error("prometheus", "Caught error");
|
||||||
|
log.error("prometheus", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof uptime.data1y !== "undefined") {
|
||||||
|
try {
|
||||||
|
if (typeof uptime.data1y === "number") {
|
||||||
|
monitorUptime1y.set(
|
||||||
|
this.monitorLabelValues,
|
||||||
|
uptime.data1y
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Is it good?
|
||||||
|
monitorUptime1y.set(this.monitorLabelValues, -1);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.error("prometheus", "Caught error");
|
||||||
|
log.error("prometheus", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (heartbeat) {
|
if (heartbeat) {
|
||||||
try {
|
try {
|
||||||
monitorStatus.set(this.monitorLabelValues, heartbeat.status);
|
monitorStatus.set(this.monitorLabelValues, heartbeat.status);
|
||||||
@ -110,6 +205,10 @@ class Prometheus {
|
|||||||
try {
|
try {
|
||||||
monitorCertDaysRemaining.remove(this.monitorLabelValues);
|
monitorCertDaysRemaining.remove(this.monitorLabelValues);
|
||||||
monitorCertIsValid.remove(this.monitorLabelValues);
|
monitorCertIsValid.remove(this.monitorLabelValues);
|
||||||
|
monitorUptime1y.remove(this.monitorLabelValues);
|
||||||
|
monitorUptime30d.remove(this.monitorLabelValues);
|
||||||
|
monitorUptime24h.remove(this.monitorLabelValues);
|
||||||
|
monitorAverageResponseTime.remove(this.monitorLabelValues);
|
||||||
monitorResponseTime.remove(this.monitorLabelValues);
|
monitorResponseTime.remove(this.monitorLabelValues);
|
||||||
monitorStatus.remove(this.monitorLabelValues);
|
monitorStatus.remove(this.monitorLabelValues);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user