1
+ [role="xpack"]
1
2
[[ml-count-functions]]
2
- === Count Functions
3
+ === Count functions
3
4
4
5
Count functions detect anomalies when the number of events in a bucket is
5
6
anomalous.
@@ -21,7 +22,7 @@ The {xpackml} features include the following count functions:
21
22
22
23
[float]
23
24
[[ml-count]]
24
- ===== Count, High_count, Low_count
25
+ ===== Count, high_count, low_count
25
26
26
27
The `count` function detects anomalies when the number of events in a bucket is
27
28
anomalous.
@@ -44,8 +45,20 @@ see {ref}/ml-job-resource.html#ml-detectorconfig[Detector Configuration Objects]
44
45
.Example 1: Analyzing events with the count function
45
46
[source,js]
46
47
--------------------------------------------------
47
- { "function" : "count" }
48
+ PUT _xpack/ml/anomaly_detectors/example1
49
+ {
50
+ "analysis_config": {
51
+ "detectors": [{
52
+ "function" : "count"
53
+ }]
54
+ },
55
+ "data_description": {
56
+ "time_field":"timestamp",
57
+ "time_format": "epoch_ms"
58
+ }
59
+ }
48
60
--------------------------------------------------
61
+ // CONSOLE
49
62
50
63
This example is probably the simplest possible analysis. It identifies
51
64
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.
57
70
.Example 2: Analyzing errors with the high_count function
58
71
[source,js]
59
72
--------------------------------------------------
73
+ PUT _xpack/ml/anomaly_detectors/example2
60
74
{
61
- "function" : "high_count",
62
- "by_field_name" : "error_code",
63
- "over_field_name": "user"
75
+ "analysis_config": {
76
+ "detectors": [{
77
+ "function" : "high_count",
78
+ "by_field_name" : "error_code",
79
+ "over_field_name": "user"
80
+ }]
81
+ },
82
+ "data_description": {
83
+ "time_field":"timestamp",
84
+ "time_format": "epoch_ms"
85
+ }
64
86
}
65
87
--------------------------------------------------
88
+ // CONSOLE
66
89
67
90
If you use this `high_count` function in a detector in your job, it
68
91
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.
72
95
.Example 3: Analyzing status codes with the low_count function
73
96
[source,js]
74
97
--------------------------------------------------
98
+ PUT _xpack/ml/anomaly_detectors/example3
75
99
{
76
- "function" : "low_count",
77
- "by_field_name" : "status_code"
100
+ "analysis_config": {
101
+ "detectors": [{
102
+ "function" : "low_count",
103
+ "by_field_name" : "status_code"
104
+ }]
105
+ },
106
+ "data_description": {
107
+ "time_field":"timestamp",
108
+ "time_format": "epoch_ms"
109
+ }
78
110
}
79
111
--------------------------------------------------
112
+ // CONSOLE
80
113
81
114
In this example, the function detects when the count of events for a
82
115
status code is lower than usual.
@@ -88,22 +121,30 @@ compared to its past behavior.
88
121
.Example 4: Analyzing aggregated data with the count function
89
122
[source,js]
90
123
--------------------------------------------------
124
+ PUT _xpack/ml/anomaly_detectors/example4
91
125
{
92
- "summary_count_field_name" : "events_per_min",
93
- "detectors" [
94
- { "function" : "count" }
95
- ]
96
- }
126
+ "analysis_config": {
127
+ "summary_count_field_name" : "events_per_min",
128
+ "detectors": [{
129
+ "function" : "count"
130
+ }]
131
+ },
132
+ "data_description": {
133
+ "time_field":"timestamp",
134
+ "time_format": "epoch_ms"
135
+ }
136
+ }
97
137
--------------------------------------------------
138
+ // CONSOLE
98
139
99
140
If you are analyzing an aggregated `events_per_min` field, do not use a sum
100
141
function (for example, `sum(events_per_min)`). Instead, use the count function
101
- and the `summary_count_field_name` property.
102
- //TO-DO: For more information, see <<aggreggations.asciidoc >>.
142
+ and the `summary_count_field_name` property. For more information, see
143
+ <<ml-configuring-aggregation >>.
103
144
104
145
[float]
105
146
[[ml-nonzero-count]]
106
- ===== Non_zero_count, High_non_zero_count, Low_non_zero_count
147
+ ===== Non_zero_count, high_non_zero_count, low_non_zero_count
107
148
108
149
The `non_zero_count` function detects anomalies when the number of events in a
109
150
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:
144
185
.Example 5: Analyzing signatures with the high_non_zero_count function
145
186
[source,js]
146
187
--------------------------------------------------
188
+ PUT _xpack/ml/anomaly_detectors/example5
147
189
{
148
- "function" : "high_non_zero_count",
149
- "by_field_name" : "signaturename"
190
+ "analysis_config": {
191
+ "detectors": [{
192
+ "function" : "high_non_zero_count",
193
+ "by_field_name" : "signaturename"
194
+ }]
195
+ },
196
+ "data_description": {
197
+ "time_field":"timestamp",
198
+ "time_format": "epoch_ms"
199
+ }
150
200
}
151
201
--------------------------------------------------
202
+ // CONSOLE
152
203
153
204
If you use this `high_non_zero_count` function in a detector in your job, it
154
205
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
163
214
164
215
[float]
165
216
[[ml-distinct-count]]
166
- ===== Distinct_count, High_distinct_count, Low_distinct_count
217
+ ===== Distinct_count, high_distinct_count, low_distinct_count
167
218
168
219
The `distinct_count` function detects anomalies where the number of distinct
169
220
values in one field is unusual.
@@ -187,11 +238,21 @@ see {ref}/ml-job-resource.html#ml-detectorconfig[Detector Configuration Objects]
187
238
.Example 6: Analyzing users with the distinct_count function
188
239
[source,js]
189
240
--------------------------------------------------
241
+ PUT _xpack/ml/anomaly_detectors/example6
190
242
{
191
- "function" : "distinct_count",
192
- "field_name" : "user"
243
+ "analysis_config": {
244
+ "detectors": [{
245
+ "function" : "distinct_count",
246
+ "field_name" : "user"
247
+ }]
248
+ },
249
+ "data_description": {
250
+ "time_field":"timestamp",
251
+ "time_format": "epoch_ms"
252
+ }
193
253
}
194
254
--------------------------------------------------
255
+ // CONSOLE
195
256
196
257
This `distinct_count` function detects when a system has an unusual number
197
258
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.
201
262
.Example 7: Analyzing ports with the high_distinct_count function
202
263
[source,js]
203
264
--------------------------------------------------
265
+ PUT _xpack/ml/anomaly_detectors/example7
204
266
{
205
- "function" : "high_distinct_count",
206
- "field_name" : "dst_port",
207
- "over_field_name": "src_ip"
267
+ "analysis_config": {
268
+ "detectors": [{
269
+ "function" : "high_distinct_count",
270
+ "field_name" : "dst_port",
271
+ "over_field_name": "src_ip"
272
+ }]
273
+ },
274
+ "data_description": {
275
+ "time_field":"timestamp",
276
+ "time_format": "epoch_ms"
277
+ }
208
278
}
209
279
--------------------------------------------------
280
+ // CONSOLE
210
281
211
282
This example detects instances of port scanning. When you use this function in a
212
283
detector in your job, it models the distinct count of ports. It also detects the
0 commit comments