fix: escape Prometheus label values (#2702)

fix: escape Prometheus label values (#2699)

Co-authored-by: potatosips <potatosips@users.noreply.github.com>
This commit is contained in:
potatosips
2026-07-21 09:38:53 +02:00
committed by GitHub
co-authored by potatosips
parent 52fb584bb0
commit 0b97cf6d23
3 changed files with 52 additions and 2 deletions
+9 -2
View File
@@ -3,6 +3,7 @@ import { setHeader } from 'h3';
import Database from '#server/utils/Database';
import WireGuard from '#server/utils/WireGuard';
import { defineMetricsHandler } from '#server/utils/handler';
import { formatPrometheusLabels } from '#server/utils/prometheus';
import { isPeerConnected } from '#shared/utils/time';
export default defineMetricsHandler('prometheus', async ({ event }) => {
@@ -27,7 +28,13 @@ async function getPrometheusResponse() {
wireguardConnectedPeersCount++;
}
const id = `interface="${wgInterface.name}",enabled="${client.enabled}",ipv4Address="${client.ipv4Address}",ipv6Address="${client.ipv6Address}",name="${client.name}"`;
const id = formatPrometheusLabels({
interface: wgInterface.name,
enabled: client.enabled,
ipv4Address: client.ipv4Address,
ipv6Address: client.ipv6Address,
name: client.name,
});
wireguardSentBytes.push(
`wireguard_sent_bytes{${id}} ${client.transferTx ?? 0}`
@@ -41,7 +48,7 @@ async function getPrometheusResponse() {
);
}
const id = `interface="${wgInterface.name}"`;
const id = formatPrometheusLabels({ interface: wgInterface.name });
const returnText = [
'# HELP wireguard_configured_peers',