diff --git a/nixos/common/services/vmagent.nix b/nixos/common/services/vmagent.nix
index 5ca3e4c..31c2723 100644
--- a/nixos/common/services/vmagent.nix
+++ b/nixos/common/services/vmagent.nix
@@ -1,7 +1,10 @@
{ config, pkgs, lib, ... }:
with lib;
-let cfg = config.services.vmagent;
-in {
+let
+ cfg = config.services.vmagent;
+ settingsFormat = pkgs.formats.json { };
+in
+{
options.services.vmagent = {
enable = mkEnableOption "vmagent";
@@ -22,8 +25,8 @@ in {
};
package = mkOption {
- default = pkgs.v.vmagent;
- defaultText = "pkgs.v.vmagent";
+ default = pkgs.vmagent;
+ defaultText = "pkgs.vmagent";
type = types.package;
description = ''
vmagent package to use.
@@ -47,16 +50,17 @@ in {
};
prometheusConfig = mkOption {
- default = "";
- type = types.str;
- example = ''
- global:
- scrape_interval: 5s
- scrape_configs:
- - job_name: 'apache'
- static_configs:
- - targets: ['apache-exporter:9117']
- '';
+ type = lib.types.submodule {
+ freeformType = settingsFormat.type;
+ };
+ # example = ''
+ # global:
+ # scrape_interval: 5s
+ # scrape_configs:
+ # - job_name: 'apache'
+ # static_configs:
+ # - targets: ['apache-exporter:9117']
+ # '';
description = ''
Config for prometheus style metrics
'';
@@ -90,21 +94,22 @@ in {
networking.firewall.allowedTCPPorts = mkIf (cfg.openFirewall) [ 8429 ];
# The actual service
- systemd.services.vmagent = let prometheusConfig = pkgs.writeText "prometheus.yml" cfg.prometheusConfig;
- in {
- wantedBy = [ "multi-user.target" ];
- after = [ "network.target" ];
- description = "vmagent system service";
- serviceConfig = {
- User = cfg.user;
- Group = cfg.group;
- Type = "simple";
- Restart = "on-failure";
- WorkingDirectory = cfg.dataDir;
- ExecStart =
- "${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig}";
+ systemd.services.vmagent =
+ let prometheusConfig = settingsFormat.generate "prometheusConfig.yaml" cfg.prometheusConfig;
+ in {
+ wantedBy = [ "multi-user.target" ];
+ after = [ "network.target" ];
+ description = "vmagent system service";
+ serviceConfig = {
+ User = cfg.user;
+ Group = cfg.group;
+ Type = "simple";
+ Restart = "on-failure";
+ WorkingDirectory = cfg.dataDir;
+ ExecStart =
+ "${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig}";
+ };
};
- };
systemd.tmpfiles.rules = [ "d '${cfg.dataDir}' 0755 ${cfg.user} ${cfg.group} -" ];
};
diff --git a/nixos/hosts/nginx/configuration.nix b/nixos/hosts/nginx/configuration.nix
index 170a2ce..c11fa6a 100644
--- a/nixos/hosts/nginx/configuration.nix
+++ b/nixos/hosts/nginx/configuration.nix
@@ -62,7 +62,7 @@ in
forceSSL = true;
locations."/".extraConfig = ''
add_header Content-Type 'text/html; charset=UTF-8';
- return 200 meow;
+ return 200 '
meow
';
'';
locations."= /.well-known/matrix/client".extraConfig = mkWellKnown clientConfig;
locations."= /.well-known/matrix/server".extraConfig = mkWellKnown serverConfig;
diff --git a/nixos/hosts/synapse/configuration.nix b/nixos/hosts/synapse/configuration.nix
index 677003f..84d2e72 100644
--- a/nixos/hosts/synapse/configuration.nix
+++ b/nixos/hosts/synapse/configuration.nix
@@ -6,6 +6,7 @@
let
vs = config.vault-secrets.secrets;
port = 8008;
+ metricsPort = 9000;
in
{
imports = [ ];
@@ -23,7 +24,7 @@ in
# Additional packages
environment.systemPackages = with pkgs; [ ];
- networking.firewall.allowedTCPPorts = [ port ];
+ networking.firewall.allowedTCPPorts = [ port metricsPort ];
vault-secrets.secrets.synapse = {
user = "matrix-synapse";
@@ -65,6 +66,7 @@ in
server_name = "meowy.tech";
enable_registration = true;
public_baseurl = "https://chat.meowy.tech";
+ enable_metrics = true;
listeners = [
{
inherit port;
@@ -79,6 +81,18 @@ in
}
];
}
+ {
+ port = metricsPort;
+ bind_addresses = [ "0.0.0.0" ];
+ type = "metrics";
+ tls = false;
+ resources = [
+ {
+ names = [ "metrics" ];
+ compress = false;
+ }
+ ];
+ }
];
};
};
diff --git a/nixos/hosts/victoriametrics/configuration.nix b/nixos/hosts/victoriametrics/configuration.nix
index 6d4b4d2..5fd0532 100644
--- a/nixos/hosts/victoriametrics/configuration.nix
+++ b/nixos/hosts/victoriametrics/configuration.nix
@@ -6,7 +6,8 @@
let
vmPort = 8428;
vs = config.vault-secrets.secrets;
-in {
+in
+{
imports = [ ];
networking.hostName = "victoriametrics";
@@ -32,7 +33,25 @@ in {
retentionPeriod = 12;
};
- vault-secrets.secrets.grafana = {
+ services.vmagent = {
+ enable = true;
+ openFirewall = true;
+ prometheusConfig = {
+ global.scrape_interval = "5s";
+ scrape_configs = [
+ {
+ job_name = "synapse";
+ metrics_path = "/_synapse/metrics";
+ static_configs = [{
+ targets = [ "synapse.olympus:9000" ];
+ labels.app = "synapse";
+ }];
+ }
+ ];
+ };
+ };
+
+ vault-secrets.secrets.grafana = {
user = "grafana";
group = "grafana";
};
diff --git a/nixos/pkgs/default.nix b/nixos/pkgs/default.nix
index feb82c2..f933374 100644
--- a/nixos/pkgs/default.nix
+++ b/nixos/pkgs/default.nix
@@ -6,6 +6,8 @@ final: prev: {
'';
});
+ vmagent = prev.callPackage ./vmagent { };
+
v = {
unbound = prev.unbound.override {
withSystemd = true;
diff --git a/nixos/pkgs/vmagent/default.nix b/nixos/pkgs/vmagent/default.nix
new file mode 100644
index 0000000..2a1984d
--- /dev/null
+++ b/nixos/pkgs/vmagent/default.nix
@@ -0,0 +1,23 @@
+{ lib, fetchFromGitHub, buildGoModule }:
+buildGoModule rec {
+ pname = "vmagent";
+ version = "1.79.0";
+
+ src = fetchFromGitHub {
+ owner = "VictoriaMetrics";
+ repo = "VictoriaMetrics";
+ rev = "v${version}";
+ sha256 = "sha256-+LirbGbKeazXMtgVh5kZP+KEk/fDbSxceZ26OlE0hbY=";
+ };
+
+ vendorSha256 = null;
+
+ subPackages = [ "app/vmagent" ];
+
+ meta = with lib; {
+ description = "VictoriaMetrics metrics scraper";
+ homepage = "https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/app/vmagent";
+ license = licenses.asl20;
+ platforms = platforms.linux;
+ };
+}