|
@@ -1,5 +1,6 @@
|
|
|
+[role="xpack"]
|
|
|
[[ml-count-functions]]
|
|
|
-=== Count Functions
|
|
|
+=== Count functions
|
|
|
|
|
|
Count functions detect anomalies when the number of events in a bucket is
|
|
|
anomalous.
|
|
@@ -21,7 +22,7 @@ The {xpackml} features include the following count functions:
|
|
|
|
|
|
[float]
|
|
|
[[ml-count]]
|
|
|
-===== Count, High_count, Low_count
|
|
|
+===== Count, high_count, low_count
|
|
|
|
|
|
The `count` function detects anomalies when the number of events in a bucket is
|
|
|
anomalous.
|
|
@@ -44,8 +45,20 @@ see {ref}/ml-job-resource.html#ml-detectorconfig[Detector Configuration Objects]
|
|
|
.Example 1: Analyzing events with the count function
|
|
|
[source,js]
|
|
|
--------------------------------------------------
|
|
|
-{ "function" : "count" }
|
|
|
+PUT _xpack/ml/anomaly_detectors/example1
|
|
|
+{
|
|
|
+ "analysis_config": {
|
|
|
+ "detectors": [{
|
|
|
+ "function" : "count"
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ "data_description": {
|
|
|
+ "time_field":"timestamp",
|
|
|
+ "time_format": "epoch_ms"
|
|
|
+ }
|
|
|
+}
|
|
|
--------------------------------------------------
|
|
|
+// CONSOLE
|
|
|
|
|
|
This example is probably the simplest possible analysis. It identifies
|
|
|
time buckets during which the overall count of events is higher or lower than
|
|
@@ -57,12 +70,22 @@ and detects when the event rate is unusual compared to its past behavior.
|
|
|
.Example 2: Analyzing errors with the high_count function
|
|
|
[source,js]
|
|
|
--------------------------------------------------
|
|
|
+PUT _xpack/ml/anomaly_detectors/example2
|
|
|
{
|
|
|
- "function" : "high_count",
|
|
|
- "by_field_name" : "error_code",
|
|
|
- "over_field_name": "user"
|
|
|
+ "analysis_config": {
|
|
|
+ "detectors": [{
|
|
|
+ "function" : "high_count",
|
|
|
+ "by_field_name" : "error_code",
|
|
|
+ "over_field_name": "user"
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ "data_description": {
|
|
|
+ "time_field":"timestamp",
|
|
|
+ "time_format": "epoch_ms"
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
+// CONSOLE
|
|
|
|
|
|
If you use this `high_count` function in a detector in your job, it
|
|
|
models the event rate for each error code. It detects users that generate an
|
|
@@ -72,11 +95,21 @@ unusually high count of error codes compared to other users.
|
|
|
.Example 3: Analyzing status codes with the low_count function
|
|
|
[source,js]
|
|
|
--------------------------------------------------
|
|
|
+PUT _xpack/ml/anomaly_detectors/example3
|
|
|
{
|
|
|
- "function" : "low_count",
|
|
|
- "by_field_name" : "status_code"
|
|
|
+ "analysis_config": {
|
|
|
+ "detectors": [{
|
|
|
+ "function" : "low_count",
|
|
|
+ "by_field_name" : "status_code"
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ "data_description": {
|
|
|
+ "time_field":"timestamp",
|
|
|
+ "time_format": "epoch_ms"
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
+// CONSOLE
|
|
|
|
|
|
In this example, the function detects when the count of events for a
|
|
|
status code is lower than usual.
|
|
@@ -88,22 +121,30 @@ compared to its past behavior.
|
|
|
.Example 4: Analyzing aggregated data with the count function
|
|
|
[source,js]
|
|
|
--------------------------------------------------
|
|
|
+PUT _xpack/ml/anomaly_detectors/example4
|
|
|
{
|
|
|
- "summary_count_field_name" : "events_per_min",
|
|
|
- "detectors" [
|
|
|
- { "function" : "count" }
|
|
|
- ]
|
|
|
-}
|
|
|
+ "analysis_config": {
|
|
|
+ "summary_count_field_name" : "events_per_min",
|
|
|
+ "detectors": [{
|
|
|
+ "function" : "count"
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ "data_description": {
|
|
|
+ "time_field":"timestamp",
|
|
|
+ "time_format": "epoch_ms"
|
|
|
+ }
|
|
|
+}
|
|
|
--------------------------------------------------
|
|
|
+// CONSOLE
|
|
|
|
|
|
If you are analyzing an aggregated `events_per_min` field, do not use a sum
|
|
|
function (for example, `sum(events_per_min)`). Instead, use the count function
|
|
|
-and the `summary_count_field_name` property.
|
|
|
-//TO-DO: For more information, see <<aggreggations.asciidoc>>.
|
|
|
+and the `summary_count_field_name` property. For more information, see
|
|
|
+<<ml-configuring-aggregation>>.
|
|
|
|
|
|
[float]
|
|
|
[[ml-nonzero-count]]
|
|
|
-===== Non_zero_count, High_non_zero_count, Low_non_zero_count
|
|
|
+===== Non_zero_count, high_non_zero_count, low_non_zero_count
|
|
|
|
|
|
The `non_zero_count` function detects anomalies when the number of events in a
|
|
|
bucket is anomalous, but it ignores cases where the bucket count is zero. Use
|
|
@@ -144,11 +185,21 @@ The `non_zero_count` function models only the following data:
|
|
|
.Example 5: Analyzing signatures with the high_non_zero_count function
|
|
|
[source,js]
|
|
|
--------------------------------------------------
|
|
|
+PUT _xpack/ml/anomaly_detectors/example5
|
|
|
{
|
|
|
- "function" : "high_non_zero_count",
|
|
|
- "by_field_name" : "signaturename"
|
|
|
+ "analysis_config": {
|
|
|
+ "detectors": [{
|
|
|
+ "function" : "high_non_zero_count",
|
|
|
+ "by_field_name" : "signaturename"
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ "data_description": {
|
|
|
+ "time_field":"timestamp",
|
|
|
+ "time_format": "epoch_ms"
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
+// CONSOLE
|
|
|
|
|
|
If you use this `high_non_zero_count` function in a detector in your job, it
|
|
|
models the count of events for the `signaturename` field. It ignores any buckets
|
|
@@ -163,7 +214,7 @@ data is sparse, use the `count` functions, which are optimized for that scenario
|
|
|
|
|
|
[float]
|
|
|
[[ml-distinct-count]]
|
|
|
-===== Distinct_count, High_distinct_count, Low_distinct_count
|
|
|
+===== Distinct_count, high_distinct_count, low_distinct_count
|
|
|
|
|
|
The `distinct_count` function detects anomalies where the number of distinct
|
|
|
values in one field is unusual.
|
|
@@ -187,11 +238,21 @@ see {ref}/ml-job-resource.html#ml-detectorconfig[Detector Configuration Objects]
|
|
|
.Example 6: Analyzing users with the distinct_count function
|
|
|
[source,js]
|
|
|
--------------------------------------------------
|
|
|
+PUT _xpack/ml/anomaly_detectors/example6
|
|
|
{
|
|
|
- "function" : "distinct_count",
|
|
|
- "field_name" : "user"
|
|
|
+ "analysis_config": {
|
|
|
+ "detectors": [{
|
|
|
+ "function" : "distinct_count",
|
|
|
+ "field_name" : "user"
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ "data_description": {
|
|
|
+ "time_field":"timestamp",
|
|
|
+ "time_format": "epoch_ms"
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
+// CONSOLE
|
|
|
|
|
|
This `distinct_count` function detects when a system has an unusual number
|
|
|
of logged in users. When you use this function in a detector in your job, it
|
|
@@ -201,12 +262,22 @@ users is unusual compared to the past.
|
|
|
.Example 7: Analyzing ports with the high_distinct_count function
|
|
|
[source,js]
|
|
|
--------------------------------------------------
|
|
|
+PUT _xpack/ml/anomaly_detectors/example7
|
|
|
{
|
|
|
- "function" : "high_distinct_count",
|
|
|
- "field_name" : "dst_port",
|
|
|
- "over_field_name": "src_ip"
|
|
|
+ "analysis_config": {
|
|
|
+ "detectors": [{
|
|
|
+ "function" : "high_distinct_count",
|
|
|
+ "field_name" : "dst_port",
|
|
|
+ "over_field_name": "src_ip"
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ "data_description": {
|
|
|
+ "time_field":"timestamp",
|
|
|
+ "time_format": "epoch_ms"
|
|
|
+ }
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
+// CONSOLE
|
|
|
|
|
|
This example detects instances of port scanning. When you use this function in a
|
|
|
detector in your job, it models the distinct count of ports. It also detects the
|