summary refs log tree commit diff
path: root/nixos/tests/elk.nix
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2021-03-19 17:16:10 +0100
committerRobert Hensing <robert@roberthensing.nl>2021-05-31 10:42:08 +0200
commit5699d027eccea705b25bf84da147708f2021eb01 (patch)
tree8bfccac1c929b8de1226e1473fe1caacae78e84a /nixos/tests/elk.nix
parent774fe1878b045411e6bdd0dd90d8581e82b10993 (diff)
downloadnixpkgs-5699d027eccea705b25bf84da147708f2021eb01.tar
nixpkgs-5699d027eccea705b25bf84da147708f2021eb01.tar.gz
nixpkgs-5699d027eccea705b25bf84da147708f2021eb01.tar.bz2
nixpkgs-5699d027eccea705b25bf84da147708f2021eb01.tar.lz
nixpkgs-5699d027eccea705b25bf84da147708f2021eb01.tar.xz
nixpkgs-5699d027eccea705b25bf84da147708f2021eb01.tar.zst
nixpkgs-5699d027eccea705b25bf84da147708f2021eb01.zip
nixos/metricbeat: init
Diffstat (limited to 'nixos/tests/elk.nix')
-rw-r--r--nixos/tests/elk.nix38
1 files changed, 38 insertions, 0 deletions
diff --git a/nixos/tests/elk.nix b/nixos/tests/elk.nix
index fee350de65b..db51aede0de 100644
--- a/nixos/tests/elk.nix
+++ b/nixos/tests/elk.nix
@@ -56,6 +56,24 @@ let
                 '');
               };
 
+              metricbeat = {
+                enable = true;
+                package = elk.metricbeat;
+                modules.system = {
+                  metricsets = ["cpu" "load" "memory" "network" "process" "process_summary" "uptime" "socket_summary"];
+                  enabled = true;
+                  period = "5s";
+                  processes = [".*"];
+                  cpu.metrics = ["percentages" "normalized_percentages"];
+                  core.metrics = ["percentages"];
+                };
+                settings = {
+                  output.elasticsearch = {
+                    hosts = ["127.0.0.1:9200"];
+                  };
+                };
+              };
+
               logstash = {
                 enable = true;
                 package = elk.logstash;
@@ -135,6 +153,16 @@ let
           )
 
 
+      def has_metricbeat():
+          dictionary = {"query": {"match": {"event.dataset": {"query": "system.cpu"}}}}
+          return (
+              "curl --silent --show-error '${esUrl}/_search' "
+              + "-H 'Content-Type: application/json' "
+              + "-d '{}' ".format(json.dumps(dictionary))
+              + "| jq '.hits.total > 0'"
+          )
+
+
       start_all()
 
       one.wait_for_unit("elasticsearch.service")
@@ -161,6 +189,12 @@ let
               "curl --silent --show-error 'http://localhost:5601/api/status' | jq .status.overall.state | grep green"
           )
 
+      with subtest("Metricbeat is running"):
+          one.wait_for_unit("metricbeat.service")
+
+      with subtest("Metricbeat metrics arrive in elasticsearch"):
+          one.wait_until_succeeds(has_metricbeat() + " | tee /dev/console | grep 'true'")
+
       with subtest("Logstash messages arive in elasticsearch"):
           one.wait_until_succeeds(total_hits("flowers") + " | grep -v 0")
           one.wait_until_succeeds(total_hits("dragons") + " | grep 0")
@@ -190,12 +224,14 @@ in pkgs.lib.mapAttrs mkElkTest {
       logstash      = pkgs.logstash6;
       kibana        = pkgs.kibana6;
       journalbeat   = pkgs.journalbeat6;
+      metricbeat    = pkgs.metricbeat6;
     }
     else {
       elasticsearch = pkgs.elasticsearch6-oss;
       logstash      = pkgs.logstash6-oss;
       kibana        = pkgs.kibana6-oss;
       journalbeat   = pkgs.journalbeat6;
+      metricbeat    = pkgs.metricbeat6;
     };
   ELK-7 =
     if enableUnfree
@@ -204,11 +240,13 @@ in pkgs.lib.mapAttrs mkElkTest {
       logstash      = pkgs.logstash7;
       kibana        = pkgs.kibana7;
       journalbeat   = pkgs.journalbeat7;
+      metricbeat    = pkgs.metricbeat7;
     }
     else {
       elasticsearch = pkgs.elasticsearch7-oss;
       logstash      = pkgs.logstash7-oss;
       kibana        = pkgs.kibana7-oss;
       journalbeat   = pkgs.journalbeat7;
+      metricbeat    = pkgs.metricbeat7;
     };
 }