Compare commits

..

6 Commits

Author SHA1 Message Date
Lucas Bergman
94b05b1437 maint: NixOS module writes config to the Nix store
Instead of writing the config attrset to a YAML file to a fixed path in /etc,
this makes the NixOS module write to a (content-addressed) config file in the
Nix store. We just use builtins.toJSON since YAML is a superset of JSON.
2024-02-20 07:58:03 -06:00
Lucas Bergman
668015ed17 maint: Some Nix flake cleanups
Specifically:

  1. Switch from the nixosModule flake output (which is deprecated) to
     nixosModules.default
  2. Remove "with lib;" it's convenient, but I've gotten feedback when
     upstreaming module changes that that shouldn't be a thing in
     nixpkgs anymore
  3. Add a little type checking to the NixOS module options
  4. Switch the default config to empty (but leave the example)
  5. Use the convention "let cfg = config.services.heracles," a thing
     that's super common in NixOS
2024-02-20 07:53:13 -06:00
Lucas Bergman
63b4f810c2 maint: Set formatter Nix flake output so nix fmt works
I've idly thought about making the formatter a derivation that runs alejandra
over Nix code, then rustfmt over Rust code, etc--so that just running `nix
fmt` in the root cleans up everything--but I haven't made that work yet.
2024-02-19 20:32:19 -06:00
Lucas Bergman
fe162968e5 maint: Run nix stuff through the formatter
There are several choices for formatting Nix code, but IMHO alejandra is the
right kind of opinionated: <https://github.com/kamadorueda/alejandra>.
2024-02-19 20:31:47 -06:00
847413f4f5 fix: bug in scalar graph types 2024-02-19 19:25:36 -05:00
18eb50fbbd feat: use a js template literal for trace name 2024-02-19 19:15:34 -05:00
4 changed files with 31 additions and 38 deletions

View File

@ -8,10 +8,8 @@
- source: http://heimdall:9001 # Prometheus source uri for this plot
query: 'sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m]))' # The PromQL query for this plot
meta: # metadata for this plot
name_label: instance # Grab a trace name from the query tags
name_format: "`${labels.instance}`" # javascript template literal to format the trace name
#d3_tick_format: "~%" # d3 tick format override for this plot's yaxis
#name_prefix: "Prefix" # A prefix for this sublots trace names
#name_suffix: "Suffix" # A suffix for this subplots trace names
#named_axis: "y" # yaxis name to use for this subplots traces
span: # The span for this range query
end: now # Where the span ends. RFC3339 format with special handling for the now keyword
@ -32,16 +30,14 @@
sum by (instance)(irate(node_cpu_seconds_total{mode="system",job="nodestats"}[5m])) / sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m]))
meta:
d3_tick_format: "~%"
name_label: instance
name_prefix: "System"
name_format: "`${labels.instance} system`"
named_axis: "y"
- source: http://heimdall:9001
query: |
sum by (instance)(irate(node_cpu_seconds_total{mode="user",job="nodestats"}[5m])) / sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m]))
meta:
d3_tick_format: "~%"
name_label: instance
name_suffix: "User"
name_format: "`${labels.instance} user`"
named_axis: "y"
- title: Node memory
query_type: Scalar
@ -49,4 +45,4 @@
- source: http://heimdall:9001
query: 'node_memory_MemFree_bytes{job="nodestats"}'
meta:
name_label: instance
name_format: "`${labels.instance}`"

View File

@ -83,9 +83,7 @@
sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m]))
\'\';
meta = {
name_label = "instance";
name_prefix = "trace name prefix";
name_suffix = "trace name suffix";
name_function = "''${labels.instance}";
named_axis = "y";
# yaxis formatting for this subplot
d3_tick_format = "~s";
@ -114,11 +112,9 @@
config = let
cfg = config.services.heracles;
cfgFile = pkgs.writeText "heracles.yaml" (builtins.toJSON cfg.settings);
in
lib.mkIf cfg.enable {
environment.etc."heracles.yaml" = {
text = lib.generators.toYAML {} cfg.settings;
};
systemd.services.heracles = {
wantedBy = ["multi-user.target" "default.target"];
wants = ["network.target"];
@ -126,7 +122,7 @@
serviceConfig = {
Restart = "on-failure";
RestartSec = "30s";
ExecStart = "${pkgs.heracles}/bin/heracles --listen ${cfg.listen} --config=${config.environment.etc."heracles.yaml".target}";
ExecStart = "${pkgs.heracles}/bin/heracles --listen ${cfg.listen} --config=${cfgFile}";
};
};
};

View File

@ -117,9 +117,7 @@ pub struct DataPoint {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PlotMeta {
name_prefix: Option<String>,
name_suffix: Option<String>,
name_label: Option<String>,
name_format: Option<String>,
named_axis: Option<String>,
d3_tick_format: Option<String>,
}

View File

@ -160,19 +160,17 @@ class TimeseriesGraph extends HTMLElement {
yaxis: yaxis,
yhoverformat: meta["d3_tick_format"],
};
const namePrefix = meta["name_prefix"];
const nameSuffix = meta["name_suffix"];
const nameLabel = meta["name_label"];
var name = "";
if (namePrefix) {
name = namePrefix + "-";
};
if (nameLabel && labels[nameLabel]) {
name = name + labels[nameLabel];
};
if (nameSuffix) {
name = name + " - " + nameSuffix;
};
const formatter = meta.name_format
if (formatter) {
name = eval(formatter);
} else {
var names = [];
for (const value of labels) {
names.push(value);
}
name = names.join(" ");
}
if (name) { trace.name = name; }
for (const point of series) {
trace.x.push(new Date(point.timestamp * 1000));
@ -190,17 +188,22 @@ class TimeseriesGraph extends HTMLElement {
type: "bar",
x: [],
y: [],
yaxis: yaxis,
yhoverformat: meta["d3_tick_format"],
};
let nameLabel = meta["name_label"];
if (nameLabel && labels[nameLabel]) {
trace.name = labels[nameLabel];
};
if (nameLabel && labels[nameLabel]) {
trace.x.push(labels[nameLabel]);
};
const formatter = meta.name_format;
var name = "";
if (formatter) {
name = eval(formatter);
} else {
var names = [];
for (const value of labels) {
names.push(value);
}
name = names.join(" ");
}
if (name) { trace.name = name; }
trace.y.push(series.value);
trace.x.push(trace.name);
traces.push(trace);
}
}