add synapse metrics
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Vivian 2022-07-29 13:02:03 +02:00
parent b108d02f59
commit bf21b3b7c8
6 changed files with 95 additions and 32 deletions

View file

@ -1,7 +1,10 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
with lib; with lib;
let cfg = config.services.vmagent; let
in { cfg = config.services.vmagent;
settingsFormat = pkgs.formats.json { };
in
{
options.services.vmagent = { options.services.vmagent = {
enable = mkEnableOption "vmagent"; enable = mkEnableOption "vmagent";
@ -22,8 +25,8 @@ in {
}; };
package = mkOption { package = mkOption {
default = pkgs.v.vmagent; default = pkgs.vmagent;
defaultText = "pkgs.v.vmagent"; defaultText = "pkgs.vmagent";
type = types.package; type = types.package;
description = '' description = ''
vmagent package to use. vmagent package to use.
@ -47,16 +50,17 @@ in {
}; };
prometheusConfig = mkOption { prometheusConfig = mkOption {
default = ""; type = lib.types.submodule {
type = types.str; freeformType = settingsFormat.type;
example = '' };
global: # example = ''
scrape_interval: 5s # global:
scrape_configs: # scrape_interval: 5s
- job_name: 'apache' # scrape_configs:
static_configs: # - job_name: 'apache'
- targets: ['apache-exporter:9117'] # static_configs:
''; # - targets: ['apache-exporter:9117']
# '';
description = '' description = ''
Config for prometheus style metrics Config for prometheus style metrics
''; '';
@ -90,21 +94,22 @@ in {
networking.firewall.allowedTCPPorts = mkIf (cfg.openFirewall) [ 8429 ]; networking.firewall.allowedTCPPorts = mkIf (cfg.openFirewall) [ 8429 ];
# The actual service # The actual service
systemd.services.vmagent = let prometheusConfig = pkgs.writeText "prometheus.yml" cfg.prometheusConfig; systemd.services.vmagent =
in { let prometheusConfig = settingsFormat.generate "prometheusConfig.yaml" cfg.prometheusConfig;
wantedBy = [ "multi-user.target" ]; in {
after = [ "network.target" ]; wantedBy = [ "multi-user.target" ];
description = "vmagent system service"; after = [ "network.target" ];
serviceConfig = { description = "vmagent system service";
User = cfg.user; serviceConfig = {
Group = cfg.group; User = cfg.user;
Type = "simple"; Group = cfg.group;
Restart = "on-failure"; Type = "simple";
WorkingDirectory = cfg.dataDir; Restart = "on-failure";
ExecStart = WorkingDirectory = cfg.dataDir;
"${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig}"; ExecStart =
"${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig}";
};
}; };
};
systemd.tmpfiles.rules = [ "d '${cfg.dataDir}' 0755 ${cfg.user} ${cfg.group} -" ]; systemd.tmpfiles.rules = [ "d '${cfg.dataDir}' 0755 ${cfg.user} ${cfg.group} -" ];
}; };

View file

@ -62,7 +62,7 @@ in
forceSSL = true; forceSSL = true;
locations."/".extraConfig = '' locations."/".extraConfig = ''
add_header Content-Type 'text/html; charset=UTF-8'; add_header Content-Type 'text/html; charset=UTF-8';
return 200 meow; return 200 '<h1>meow</h1>';
''; '';
locations."= /.well-known/matrix/client".extraConfig = mkWellKnown clientConfig; locations."= /.well-known/matrix/client".extraConfig = mkWellKnown clientConfig;
locations."= /.well-known/matrix/server".extraConfig = mkWellKnown serverConfig; locations."= /.well-known/matrix/server".extraConfig = mkWellKnown serverConfig;

View file

@ -6,6 +6,7 @@
let let
vs = config.vault-secrets.secrets; vs = config.vault-secrets.secrets;
port = 8008; port = 8008;
metricsPort = 9000;
in in
{ {
imports = [ ]; imports = [ ];
@ -23,7 +24,7 @@ in
# Additional packages # Additional packages
environment.systemPackages = with pkgs; [ ]; environment.systemPackages = with pkgs; [ ];
networking.firewall.allowedTCPPorts = [ port ]; networking.firewall.allowedTCPPorts = [ port metricsPort ];
vault-secrets.secrets.synapse = { vault-secrets.secrets.synapse = {
user = "matrix-synapse"; user = "matrix-synapse";
@ -65,6 +66,7 @@ in
server_name = "meowy.tech"; server_name = "meowy.tech";
enable_registration = true; enable_registration = true;
public_baseurl = "https://chat.meowy.tech"; public_baseurl = "https://chat.meowy.tech";
enable_metrics = true;
listeners = [ listeners = [
{ {
inherit port; inherit port;
@ -79,6 +81,18 @@ in
} }
]; ];
} }
{
port = metricsPort;
bind_addresses = [ "0.0.0.0" ];
type = "metrics";
tls = false;
resources = [
{
names = [ "metrics" ];
compress = false;
}
];
}
]; ];
}; };
}; };

View file

@ -6,7 +6,8 @@
let let
vmPort = 8428; vmPort = 8428;
vs = config.vault-secrets.secrets; vs = config.vault-secrets.secrets;
in { in
{
imports = [ ]; imports = [ ];
networking.hostName = "victoriametrics"; networking.hostName = "victoriametrics";
@ -32,7 +33,25 @@ in {
retentionPeriod = 12; 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"; user = "grafana";
group = "grafana"; group = "grafana";
}; };

View file

@ -6,6 +6,8 @@ final: prev: {
''; '';
}); });
vmagent = prev.callPackage ./vmagent { };
v = { v = {
unbound = prev.unbound.override { unbound = prev.unbound.override {
withSystemd = true; withSystemd = true;

View file

@ -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;
};
}