feat(monitoring): add pyroscope to the infrastructure

Vendored for the time being.
See https://cl.forkos.org/c/nixpkgs/+/181 for upstreaming properly.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
raito 2024-08-23 19:42:17 +02:00
parent c380f29937
commit db46b01ae9
6 changed files with 101 additions and 1 deletions

View file

@ -23,6 +23,7 @@
bagel.services.loki.enable = true; bagel.services.loki.enable = true;
bagel.services.grafana.enable = true; bagel.services.grafana.enable = true;
bagel.services.grapevine.enable = true; bagel.services.grapevine.enable = true;
bagel.services.pyroscope.enable = true;
bagel.services.hookshot = { bagel.services.hookshot = {
enable = true; enable = true;
admins = [ admins = [

View file

@ -2,5 +2,6 @@
(final: prev: { (final: prev: {
iusb-spoof = final.callPackage ./iusb-spoof.nix {}; iusb-spoof = final.callPackage ./iusb-spoof.nix {};
u-root = final.callPackage ./u-root {}; u-root = final.callPackage ./u-root {};
pyroscope = final.callPackage ./pyroscope {};
}) })
] ]

View file

@ -0,0 +1,42 @@
{ lib
, buildGoModule
, fetchFromGitHub
}:
buildGoModule rec {
pname = "pyroscope";
version = "1.7.1";
src = fetchFromGitHub {
owner = "grafana";
repo = "pyroscope";
rev = "v${version}";
hash = "sha256-iMP67J0Q8Cgo52iImMzAM3PEkk6uLF7r6v9TyXZVaIE=";
};
env.GOWORK = "off";
vendorHash = "sha256-ggntpnU9s2rpkv6S0LnZNexrdkBsdsUrGPc93SVrK4M=";
subPackages = [ "cmd/profilecli" "cmd/pyroscope" ];
ldflags = [
"-extldflags"
"-static"
"-s"
"-w"
"-X=github.com/grafana/pyroscope/pkg/util/build.Branch=${src.rev}"
"-X=github.com/grafana/pyroscope/pkg/util/build.Version=${version}"
"-X=github.com/grafana/pyroscope/pkg/util/build.Revision=${src.rev}"
"-X=github.com/grafana/pyroscope/pkg/util/build.BuildDate=1970-01-01T00:00:00Z"
];
meta = with lib; {
description = "Continuous profiling platform";
homepage = "https://github.com/grafana/pyroscope";
changelog = "https://github.com/grafana/pyroscope/blob/${src.rev}/CHANGELOG.md";
license = licenses.agpl3Only;
maintainers = with maintainers; [ raitobezarius ];
mainProgram = "pyroscope";
};
}

View file

@ -4,5 +4,6 @@
./lgtm ./lgtm
./agent.nix ./agent.nix
./hookshot-adapter ./hookshot-adapter
./pyroscope
]; ];
} }

View file

@ -0,0 +1,19 @@
{ lib, config, ... }:
let
inherit (lib) mkEnableOption mkIf;
cfg = config.bagel.services.pyroscope;
in
{
options.bagel.services.pyroscope = {
enable = mkEnableOption "pyroscope server";
};
# TODO: send me to nixpkgs
imports = [
./module.nix
];
config = mkIf cfg.enable {
services.pyroscope.enable = true;
};
}

View file

@ -0,0 +1,36 @@
{ pkgs, lib, config, ... }:
let
inherit (lib) mkEnableOption mkPackageOption mkOption types mkIf;
settingsFormatYaml = pkgs.formats.yaml { };
cfg = config.services.pyroscope;
configFile = settingsFormatYaml.generate "settings.yaml" cfg.settings;
in
{
options.services.pyroscope = {
enable = mkEnableOption "pyroscope, a continuous profiling platform";
package = mkPackageOption pkgs "pyroscope" { };
settings = mkOption {
description = "Pyroscope settings. See <>";
type = types.submodule {
freeformType = settingsFormatYaml.type;
};
};
};
config = mkIf cfg.enable {
systemd.services.pyroscope = {
description = "Pyroscope server - a continuous profiling platform";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${cfg.package}/bin/pyroscope -config.file ${configFile}";
WorkingDirectory = "/var/lib/pyroscope";
User = "pyroscope";
DynamicUser = true;
Restart = "on-failure";
RuntimeDirectory = "pyroscope";
StateDirectory = "pyroscope";
};
};
};
}