nixos-module/collectd: add starlink-stats
This commit is contained in:
parent
e6ba05d34c
commit
ef371b32c4
|
@ -92,14 +92,20 @@ in
|
|||
services.dnscache.enable = true;
|
||||
};
|
||||
|
||||
upstream1.interfaces.up1.upstream.noNat.subnets6 = [
|
||||
"2a02:8106:208:5200::/56"
|
||||
];
|
||||
upstream2.interfaces.up2.upstream.noNat.subnets6 = [
|
||||
"2a02:8106:208:e900::/56"
|
||||
];
|
||||
upstream3.interfaces.up3.upstream = {};
|
||||
upstream4.interfaces.up4.upstream = {};
|
||||
upstream1.interfaces.up1.upstream = {
|
||||
provider = "vodafone";
|
||||
noNat.subnets6 = [
|
||||
"2a02:8106:208:5200::/56"
|
||||
];
|
||||
};
|
||||
upstream2.interfaces.up2.upstream = {
|
||||
provider = "vodafone";
|
||||
noNat.subnets6 = [
|
||||
"2a02:8106:208:e900::/56"
|
||||
];
|
||||
};
|
||||
upstream3.interfaces.up3.upstream.provider = "starlink";
|
||||
upstream4.interfaces.up4.upstream.provider = "dsi";
|
||||
upstream1.ospf.upstreamInstance = 3;
|
||||
upstream2.ospf.upstreamInstance = 4;
|
||||
anon1.ospf.upstreamInstance = 5;
|
||||
|
|
|
@ -103,6 +103,9 @@ let
|
|||
};
|
||||
};
|
||||
upstreamOpts = {
|
||||
provider = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
upBandwidth = mkOption {
|
||||
type = with types; nullOr int;
|
||||
default = null;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{ hostName, config, lib, pkgs, ... }:
|
||||
{ hostName, self, config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
inherit (pkgs.targetPlatform) system;
|
||||
hostRole = config.site.hosts.${hostName}.role;
|
||||
networkPort = 25826;
|
||||
upstreamTypesDb = pkgs.stdenv.mkDerivation {
|
||||
|
@ -12,6 +13,12 @@ let
|
|||
customTypesDb = builtins.toFile "types.db" ''
|
||||
stations value:GAUGE:0:U
|
||||
'';
|
||||
hasStarlink =
|
||||
builtins.any ({ upstream, ... }:
|
||||
if upstream == null
|
||||
then false
|
||||
else upstream.provider == "starlink"
|
||||
) (builtins.attrValues config.site.hosts.${hostName}.interfaces);
|
||||
in
|
||||
{
|
||||
services.collectd = {
|
||||
|
@ -70,6 +77,10 @@ in
|
|||
exec = ''
|
||||
Exec "collectd" "${pkgs.ruby}/bin/ruby" "${./unbound.rb}"
|
||||
'';
|
||||
}) (lib.optionalAttrs hasStarlink {
|
||||
exec = ''
|
||||
Exec "collectd" "${self.packages.${system}.starlink-stats}/bin/starlink-stats" "192.168.100.1:9200"
|
||||
'';
|
||||
}) ];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -59,7 +59,10 @@ let
|
|||
inherit self nixpkgs system;
|
||||
};
|
||||
|
||||
starlink = import ./starlink {
|
||||
inherit pkgs;
|
||||
};
|
||||
in
|
||||
salt-pillars // rootfs-packages // vm-packages // device-templates // {
|
||||
salt-pillars // rootfs-packages // vm-packages // device-templates // starlink // {
|
||||
inherit export-config dns-slaves;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# Converts Starlink status JSON to a format that is suitable for collectd exec
|
||||
|
||||
require 'json'
|
||||
|
||||
HOSTNAME = IO::readlines("/proc/sys/kernel/hostname").join.strip
|
||||
|
||||
def out path, x
|
||||
puts "PUTVAL \"#{HOSTNAME}/exec-starlink/current-#{path.join '.'}\" #{x}"
|
||||
end
|
||||
|
||||
def recurse path, x
|
||||
if x.kind_of? Hash
|
||||
x.each { |k, v|
|
||||
recurse path + [k], v
|
||||
}
|
||||
elsif x.kind_of? Array
|
||||
x.each_with_index { |v, i|
|
||||
recurse path + [i], v
|
||||
}
|
||||
|
||||
elsif x.kind_of? Float
|
||||
out path, x
|
||||
elsif x.kind_of? Fixnum
|
||||
out path, x.to_f
|
||||
elsif x.kind_of? String and x =~ /^\-?\d*\.?\d+$/
|
||||
out path, x.to_f
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
recurse [], JSON.load(STDIN)
|
|
@ -0,0 +1,8 @@
|
|||
{ pkgs ? import <nixpkgs> {} }:
|
||||
|
||||
rec {
|
||||
starlink-grpc = pkgs.callPackage ./grpc.nix {};
|
||||
starlink-stats = pkgs.callPackage ./stats.nix {
|
||||
inherit starlink-grpc;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{ writeScriptBin, runtimeShell, grpcurl }:
|
||||
|
||||
writeScriptBin "grpc" ''
|
||||
#! ${runtimeShell} -e
|
||||
|
||||
DEST=$1
|
||||
COMMAND=$2
|
||||
|
||||
exec ${grpcurl}/bin/grpcurl -plaintext -d "{\"$COMMAND\":{}}" $DEST SpaceX.API.Device.Device/Handle
|
||||
''
|
|
@ -0,0 +1,14 @@
|
|||
{ writeScriptBin, runtimeShell, starlink-grpc, ruby }:
|
||||
|
||||
writeScriptBin "starlink-stats" ''
|
||||
#! ${runtimeShell} -e
|
||||
|
||||
DEST=$1
|
||||
COMMAND=get_status
|
||||
|
||||
while true; do
|
||||
${starlink-grpc}/bin/grpc $DEST $COMMAND | ${ruby}/bin/ruby ${./convert.rb}
|
||||
|
||||
sleep 60
|
||||
done
|
||||
''
|
Loading…
Reference in New Issue