-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetric-anomaly.r
More file actions
64 lines (52 loc) · 1.91 KB
/
metric-anomaly.r
File metadata and controls
64 lines (52 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Script to perform anomaly detection on metrics and plot the results.
#
# Copyright 2017-2020 ICTU
# Copyright 2017-2022 Leiden University
# Copyright 2017-2023 Leon Helwerda
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
library(MonetDB.R)
library(DBI)
library(digest)
library(AnomalyDetection)
library(xts)
source('include/database.r')
conn <- connect()
metrics <- dbGetQuery(conn, 'SELECT metric_id, name FROM gros.metric')
summary(metrics)
apply(metrics, 1, function(row) {
data <- dbGetQuery(conn, paste('SELECT date, value FROM gros.metric_value
WHERE metric_id =', row[1],
'ORDER BY date'))
nrow(data)
summary(data)
data[[1]] <- as.POSIXlt(data[[1]])
nrow(data)
summary(data)
a <- min(data[[1]])
b <- max(data[[1]])
stamps <- do.call(rbind.data.frame,
apply(data, 1,
function(row) {
data.frame(date=as.POSIXct(row[1]),
value=row[2])
}))
nrow(stamps)
ncol(stamps)
summary(stamps)
# 1 measurement per 15 minutes (4 per hour) during a weekday from
# 8 to 18 hours during a 2-week long sprint
res <- AnomalyDetectionVec(data[, 2], max_anoms=0.02, direction='pos',
longterm=TRUE, plot=TRUE, period=4*10*5*2)
res$plot
})