aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters
diff options
context:
space:
mode:
Diffstat (limited to 'infra/libkookie/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters')
-rw-r--r--infra/libkookie/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/rtl_433.nix78
-rw-r--r--infra/libkookie/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/sql.nix104
2 files changed, 182 insertions, 0 deletions
diff --git a/infra/libkookie/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/rtl_433.nix b/infra/libkookie/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/rtl_433.nix
new file mode 100644
index 000000000000..01e420db3897
--- /dev/null
+++ b/infra/libkookie/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/rtl_433.nix
@@ -0,0 +1,78 @@
+{ config, lib, pkgs, options }:
+
+let
+ cfg = config.services.prometheus.exporters.rtl_433;
+in
+{
+ port = 9550;
+
+ extraOpts = let
+ mkMatcherOptionType = field: description: with lib.types;
+ listOf (submodule {
+ options = {
+ name = lib.mkOption {
+ type = str;
+ description = "Name to match.";
+ };
+ "${field}" = lib.mkOption {
+ type = int;
+ inherit description;
+ };
+ location = lib.mkOption {
+ type = str;
+ description = "Location to match.";
+ };
+ };
+ });
+ in
+ {
+ rtl433Flags = lib.mkOption {
+ type = lib.types.str;
+ default = "-C si";
+ example = "-C si -R 19";
+ description = ''
+ Flags passed verbatim to rtl_433 binary.
+ Having <literal>-C si</literal> (the default) is recommended since only Celsius temperatures are parsed.
+ '';
+ };
+ channels = lib.mkOption {
+ type = mkMatcherOptionType "channel" "Channel to match.";
+ default = [];
+ example = [
+ { name = "Acurite"; channel = 6543; location = "Kitchen"; }
+ ];
+ description = ''
+ List of channel matchers to export.
+ '';
+ };
+ ids = lib.mkOption {
+ type = mkMatcherOptionType "id" "ID to match.";
+ default = [];
+ example = [
+ { name = "Nexus"; id = 1; location = "Bedroom"; }
+ ];
+ description = ''
+ List of ID matchers to export.
+ '';
+ };
+ };
+
+ serviceOpts = {
+ serviceConfig = {
+ # rtl-sdr udev rules make supported USB devices +rw by plugdev.
+ SupplementaryGroups = "plugdev";
+ ExecStart = let
+ matchers = (map (m:
+ "--channel_matcher '${m.name},${toString m.channel},${m.location}'"
+ ) cfg.channels) ++ (map (m:
+ "--id_matcher '${m.name},${toString m.id},${m.location}'"
+ ) cfg.ids); in ''
+ ${pkgs.prometheus-rtl_433-exporter}/bin/rtl_433_prometheus \
+ -listen ${cfg.listenAddress}:${toString cfg.port} \
+ -subprocess "${pkgs.rtl_433}/bin/rtl_433 -F json ${cfg.rtl433Flags}" \
+ ${lib.concatStringsSep " \\\n " matchers} \
+ ${lib.concatStringsSep " \\\n " cfg.extraFlags}
+ '';
+ };
+ };
+}
diff --git a/infra/libkookie/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/sql.nix b/infra/libkookie/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/sql.nix
new file mode 100644
index 000000000000..d9be724ebc03
--- /dev/null
+++ b/infra/libkookie/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/sql.nix
@@ -0,0 +1,104 @@
+{ config, lib, pkgs, options }:
+with lib;
+let
+ cfg = config.services.prometheus.exporters.sql;
+ cfgOptions = {
+ options = with types; {
+ jobs = mkOption {
+ type = attrsOf (submodule jobOptions);
+ default = { };
+ description = "An attrset of metrics scraping jobs to run.";
+ };
+ };
+ };
+ jobOptions = {
+ options = with types; {
+ interval = mkOption {
+ type = str;
+ description = ''
+ How often to run this job, specified in
+ <link xlink:href="https://golang.org/pkg/time/#ParseDuration">Go duration</link> format.
+ '';
+ };
+ connections = mkOption {
+ type = listOf str;
+ description = "A list of connection strings of the SQL servers to scrape metrics from";
+ };
+ startupSql = mkOption {
+ type = listOf str;
+ default = [];
+ description = "A list of SQL statements to execute once after making a connection.";
+ };
+ queries = mkOption {
+ type = attrsOf (submodule queryOptions);
+ description = "SQL queries to run.";
+ };
+ };
+ };
+ queryOptions = {
+ options = with types; {
+ help = mkOption {
+ type = nullOr str;
+ default = null;
+ description = "A human-readable description of this metric.";
+ };
+ labels = mkOption {
+ type = listOf str;
+ default = [ ];
+ description = "A set of columns that will be used as Prometheus labels.";
+ };
+ query = mkOption {
+ type = str;
+ description = "The SQL query to run.";
+ };
+ values = mkOption {
+ type = listOf str;
+ description = "A set of columns that will be used as values of this metric.";
+ };
+ };
+ };
+
+ configFile =
+ if cfg.configFile != null
+ then cfg.configFile
+ else
+ let
+ nameInline = mapAttrsToList (k: v: v // { name = k; });
+ renameStartupSql = j: removeAttrs (j // { startup_sql = j.startupSql; }) [ "startupSql" ];
+ configuration = {
+ jobs = map renameStartupSql
+ (nameInline (mapAttrs (k: v: (v // { queries = nameInline v.queries; })) cfg.configuration.jobs));
+ };
+ in
+ builtins.toFile "config.yaml" (builtins.toJSON configuration);
+in
+{
+ extraOpts = {
+ configFile = mkOption {
+ type = with types; nullOr path;
+ default = null;
+ description = ''
+ Path to configuration file.
+ '';
+ };
+ configuration = mkOption {
+ type = with types; nullOr (submodule cfgOptions);
+ default = null;
+ description = ''
+ Exporter configuration as nix attribute set. Mutually exclusive with 'configFile' option.
+ '';
+ };
+ };
+
+ port = 9237;
+ serviceOpts = {
+ serviceConfig = {
+ ExecStart = ''
+ ${pkgs.prometheus-sql-exporter}/bin/sql_exporter \
+ -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
+ -config.file ${configFile} \
+ ${concatStringsSep " \\\n " cfg.extraFlags}
+ '';
+ };
+ };
+}