modules/monitoring: add sing-box monitoring

This commit is contained in:
xinyangli 2024-12-10 12:04:54 +08:00
parent e4fd9e8b23
commit dacd22b7d2
Signed by: xin
SSH key fingerprint: SHA256:UU5pRTl7NiLFJbWJZa+snLylZSXIz5rgHmwjzv8v4oE
6 changed files with 69 additions and 0 deletions

View file

@ -26,6 +26,7 @@
enable = true; enable = true;
node.enable = true; node.enable = true;
blackbox.enable = true; blackbox.enable = true;
v2ray.enable = true;
}; };
custom.monitoring = { custom.monitoring = {

View file

@ -165,6 +165,11 @@ in
hostAddress = "fra-00.coho-tet.ts.net"; hostAddress = "fra-00.coho-tet.ts.net";
targetAddresses = chinaTargets; targetAddresses = chinaTargets;
} }
])
++ (mkV2rayScrapes [
{ address = "la-00.coho-tet.ts.net"; }
{ address = "hk-00.coho-tet.ts.net"; }
{ address = "fra-00.coho-tet.ts.net"; }
]); ]);
}; };

View file

@ -1,5 +1,6 @@
{ {
config, config,
pkgs,
lib, lib,
... ...
}: }:
@ -114,7 +115,24 @@ let
} }
]); ]);
}; };
experimental = {
v2ray_api = {
listen = "127.0.0.1:15175";
stats = {
users = map (u: u.name) users;
enabled = true;
inbounds = map (p: "sg" + toString p) (lib.range 0 4);
}; };
};
};
};
sing-box = pkgs.sing-box.overrideAttrs (
finalAttrs: previousAttrs: {
tags = previousAttrs.tags ++ [
"with_v2ray_api"
];
}
);
in in
{ {
options.commonSettings.proxyServer = { options.commonSettings.proxyServer = {
@ -166,6 +184,7 @@ in
services.sing-box = { services.sing-box = {
enable = true; enable = true;
package = sing-box;
settings = ( settings = (
mkSingConfig ( mkSingConfig (
map (n: { map (n: {

View file

@ -57,6 +57,13 @@ in
default = "${config.networking.hostName}.coho-tet.ts.net"; default = "${config.networking.hostName}.coho-tet.ts.net";
}; };
}; };
v2ray = {
enable = mkEnableOption "blackbox exporter";
listenAddress = mkOption {
type = types.str;
default = "${config.networking.hostName}.coho-tet.ts.net";
};
};
}; };
}; };
}; };

View file

@ -47,6 +47,13 @@ in
); );
}; };
services.prometheus.exporters.v2ray = mkIf cfg.v2ray.enable {
enable = true;
listenAddress = cfg.v2ray.listenAddress;
port = 9516;
v2rayEndpoint = config.services.sing-box.settings.experimental.v2ray_api.listen;
};
# gotosocial # gotosocial
sops.templates."gotosocial_metrics.env" = { sops.templates."gotosocial_metrics.env" = {
content = '' content = ''

View file

@ -28,6 +28,36 @@ in
) )
); );
mkV2rayScrapes = targets: [
{
job_name = "v2ray-exporter";
scheme = "http";
static_configs = map (
{
address,
port ? 9516,
}:
{
targets = [ "${address}${mkPort port}" ];
}
) targets;
}
{
job_name = "singbox_stat";
scheme = "http";
metrics_path = "/scrape";
static_configs = map (
{
address,
port ? 9516,
}:
{
targets = [ "${address}${mkPort port}" ];
}
) targets;
}
];
mkCaddyScrapes = targets: [ mkCaddyScrapes = targets: [
{ {
job_name = "caddy"; job_name = "caddy";