From 00b9cf49e95a6825bdfc0251581672dc712ede26 Mon Sep 17 00:00:00 2001 From: Simon Crowle <sgc@it-innovation.soton.ac.uk> Date: Thu, 15 Feb 2018 11:11:23 +0000 Subject: [PATCH] Adds Apache2 alert rule and fixes Kapacitor.conf Slack endpoint Also updates manual with instructions on how to configure Kapacitor (manually) so Slack messages are sent OK. --- test/streaming/kapacitor.conf | 2 +- test/streaming/manual.md | 39 ++++++++++++++++++++++++++++++++--- test/streaming/rules.json | 6 ++++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/test/streaming/kapacitor.conf b/test/streaming/kapacitor.conf index 6a2f688..e8332d6 100644 --- a/test/streaming/kapacitor.conf +++ b/test/streaming/kapacitor.conf @@ -347,7 +347,7 @@ default-retention-policy = "" # an Incoming Webhook integration. # Visit https://slack.com/services/new/incoming-webhook # to add new webhook for Kapacitor. - url = "https:\/\/hooks.slack.com\/services\/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" + url = "https://hooks.slack.com/services/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" # Default channel for messages channel = "#clmc" # If true all the alerts will be sent to Slack diff --git a/test/streaming/manual.md b/test/streaming/manual.md index 4d3d8be..5e26bd9 100644 --- a/test/streaming/manual.md +++ b/test/streaming/manual.md @@ -38,7 +38,22 @@ The following command brings up the services To automatically set up a demonstrator CLMC dashboard and Kapacitor, run the following: ### TO-DO: RE-FACTOR AUTOMATION FOR CONFIGURING KAPACITOR (kapacitor.conf) +Once Vagrant is finished, you will need to copy the kapacitor.conf file into clmc-service, then SSH in, configure Kapacitor and restart it: +``` +# Copy the kapacitor.conf file in +vagrant plugin install vagrant-scp +vagrant scp ./test/streaming/kapacitor.conf clmc-service:/tmp/kapacitor.conf + +# Configure and re-start kapacitor +vagrant --infra=streaming ssh clmc-service +sudo systemctl stop kapacitor +sudo mv /tmp/kapacitor.conf /etc/kapacitor/ +sudo systemctl start kapacitor +exit +``` + +### Run the test set-up ``` cd ./test/streaming/ ./setup.sh @@ -84,17 +99,19 @@ Press the Data Explorer in the menu and select the apache measurement and create ## KPI triggers -In this demonstrator an example KPI rule has been set up in Kapacitor which fires when the average requests per second on the Apache 1 server goes above certain thresholds ( a 'warning' at 0.2 requests/second and a 'critical' message at 0.5 requests/second ). The TICKscript specification for this rule is as follows: +In this demonstrator an example KPI rule has been set up in Kapacitor which fires when the average requests per second on the Apache 1 or Apache2 server goes above certain thresholds ( a 'warning' at 0.2 requests/second and a 'critical' message at 0.5 requests/second ). The TICKscript specification for this rule is as follows: ``` dbrp "CLMCMetrics"."autogen" -var data = batch +// Apache 1 rule +// ------------- +var a1Data = batch |query(''' SELECT mean("ReqPerSec") AS "mean_RPS" FROM "CLMCMetrics"."autogen"."apache" WHERE "ipendpoint"='adaptive_streaming_I1_apache1' ''') .period(5s) .every(5s) -var alert = data +var a1Alert = a1Data |alert() .id('{{ .Name }}/adaptive_streaming_I1_apache1') .message('{{ .ID }} is {{ .Level }} Mean Requests Per Second: {{ index .Fields "mean_RPS" }}') @@ -102,6 +119,22 @@ var alert = data .crit(lambda: "mean_RPS" > 0.5) .slack() .log( '/tmp/RPSLoad.log' ) + +// Apache 2 rule +// ------------- +var a2Data = batch + |query(''' SELECT mean("ReqPerSec") AS "mean_RPS" FROM "CLMCMetrics"."autogen"."apache" WHERE "ipendpoint"='adaptive_streaming_I1_apache2' ''') + .period(5s) + .every(5s) + +var a2Alert = a2Data + |alert() + .id('{{ .Name }}/adaptive_streaming_I1_apache2') + .message('{{ .ID }} is {{ .Level }} Mean Requests Per Second: {{ index .Fields "mean_RPS" }}') + .warn(lambda: "mean_RPS" > 0.2) + .crit(lambda: "mean_RPS" > 0.5) + .slack() + .log( '/tmp/RPSLoad.log' ) ``` Alerts are sent both an internal logging within the CLMC service file system and also to a FLAME demo Slack service: diff --git a/test/streaming/rules.json b/test/streaming/rules.json index 2074e92..f2406fa 100644 --- a/test/streaming/rules.json +++ b/test/streaming/rules.json @@ -1,7 +1,9 @@ { - "id" : "Request_Rate_Alert", + "id" : "Request_Rate_Alert_ApacheServers", "type" : "batch", "dbrps" : [{"db": "CLMCMetrics", "rp" : "autogen"}], - "script" : "var data = batch\r\n |query(''' SELECT mean(\"ReqPerSec\") AS \"mean_RPS\" FROM \"CLMCMetrics\".\"autogen\".\"apache\" WHERE \"ipendpoint\"='adaptive_streaming_I1_apache1' ''')\r\n .period(5s)\r\n .every(5s)\r\n\r\nvar alert = data\r\n |alert()\r\n .id('{{ .Name }}\/adaptive_streaming_I1_apache1')\r\n .message('{{ .ID }} is {{ .Level }} Mean Requests Per Second: {{ index .Fields \"mean_RPS\" }}')\r\n .warn(lambda: \"mean_RPS\" > 0.2)\r\n .crit(lambda: \"mean_RPS\" > 0.5)\r\n .slack()\r\n .log( '\/tmp\/RPSLoad.log' )", + + "script" : "\/\/ Apache 1 rule\r\n\/\/ -------------\r\nvar a1Data = batch\r\n |query(''' SELECT mean(\"ReqPerSec\") AS \"mean_RPS\" FROM \"CLMCMetrics\".\"autogen\".\"apache\" WHERE \"ipendpoint\"='adaptive_streaming_I1_apache1' ''')\r\n .period(5s)\r\n .every(5s)\r\n\r\nvar a1Alert = a1Data\r\n |alert()\r\n .id('{{ .Name }}\/adaptive_streaming_I1_apache1')\r\n .message('{{ .ID }} is {{ .Level }} Mean Requests Per Second: {{ index .Fields \"mean_RPS\" }}')\r\n .warn(lambda: \"mean_RPS\" > 0.2)\r\n .crit(lambda: \"mean_RPS\" > 0.5)\r\n .slack()\r\n .log( '\/tmp\/RPSLoad.log' )\r\n\r\n\/\/ Apache 2 rule\r\n\/\/ -------------\r\nvar a2Data = batch\r\n |query(''' SELECT mean(\"ReqPerSec\") AS \"mean_RPS\" FROM \"CLMCMetrics\".\"autogen\".\"apache\" WHERE \"ipendpoint\"='adaptive_streaming_I1_apache2' ''')\r\n .period(5s)\r\n .every(5s)\r\n\r\nvar a2Alert = a2Data\r\n |alert()\r\n .id('{{ .Name }}\/adaptive_streaming_I1_apache2')\r\n .message('{{ .ID }} is {{ .Level }} Mean Requests Per Second: {{ index .Fields \"mean_RPS\" }}')\r\n .warn(lambda: \"mean_RPS\" > 0.2)\r\n .crit(lambda: \"mean_RPS\" > 0.5)\r\n .slack()\r\n .log( '\/tmp\/RPSLoad.log' )", + "status" : "enabled" } \ No newline at end of file -- GitLab