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:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user