AD_system_demo_1.ipynb 5.18 MB
Newer Older
smetaj's avatar
smetaj committed
1
2
3
4
{
 "cells": [
  {
   "cell_type": "markdown",
5
   "id": "known-novel",
6
7
8
9
10
   "metadata": {
    "toc": true
   },
   "source": [
    "<h1>Table of Contents<span class=\"tocSkip\"></span></h1>\n",
11
    "<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#Demo-Notebook-for-TimeSeries-Anomaly-Detection\" data-toc-modified-id=\"Demo-Notebook-for-TimeSeries-Anomaly-Detection-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>Demo Notebook for TimeSeries Anomaly Detection</a></span></li><li><span><a href=\"#Installation-of-libraries-and-imports\" data-toc-modified-id=\"Installation-of-libraries-and-imports-2\"><span class=\"toc-item-num\">2&nbsp;&nbsp;</span>Installation of libraries and imports</a></span><ul class=\"toc-item\"><li><span><a href=\"#Installation-of-adcern-and-others-libraries\" data-toc-modified-id=\"Installation-of-adcern-and-others-libraries-2.1\"><span class=\"toc-item-num\">2.1&nbsp;&nbsp;</span>Installation of adcern and others libraries</a></span></li><li><span><a href=\"#Imports\" data-toc-modified-id=\"Imports-2.2\"><span class=\"toc-item-num\">2.2&nbsp;&nbsp;</span>Imports</a></span></li></ul></li><li><span><a href=\"#Init-of-configuration-files---ETL\" data-toc-modified-id=\"Init-of-configuration-files---ETL-3\"><span class=\"toc-item-num\">3&nbsp;&nbsp;</span>Init of configuration files - ETL</a></span><ul class=\"toc-item\"><li><span><a href=\"#Creation\" data-toc-modified-id=\"Creation-3.1\"><span class=\"toc-item-num\">3.1&nbsp;&nbsp;</span>Creation</a></span></li><li><span><a href=\"#Reading-the-json\" data-toc-modified-id=\"Reading-the-json-3.2\"><span class=\"toc-item-num\">3.2&nbsp;&nbsp;</span>Reading the json</a></span></li></ul></li><li><span><a href=\"#ETL-steps-(Extract,-Transform,-Load)\" data-toc-modified-id=\"ETL-steps-(Extract,-Transform,-Load)-4\"><span class=\"toc-item-num\">4&nbsp;&nbsp;</span>ETL steps (Extract, Transform, Load)</a></span><ul class=\"toc-item\"><li><span><a href=\"#Compute-Normalization\" data-toc-modified-id=\"Compute-Normalization-4.1\"><span class=\"toc-item-num\">4.1&nbsp;&nbsp;</span>Compute Normalization</a></span></li><li><span><a href=\"#Transform-Data\" data-toc-modified-id=\"Transform-Data-4.2\"><span class=\"toc-item-num\">4.2&nbsp;&nbsp;</span>Transform Data</a></span></li><li><span><a href=\"#Copy-Locally\" data-toc-modified-id=\"Copy-Locally-4.3\"><span class=\"toc-item-num\">4.3&nbsp;&nbsp;</span>Copy Locally</a></span></li></ul></li><li><span><a href=\"#Visualization-of-downloaded-time-series\" data-toc-modified-id=\"Visualization-of-downloaded-time-series-5\"><span class=\"toc-item-num\">5&nbsp;&nbsp;</span>Visualization of downloaded time series</a></span><ul class=\"toc-item\"><li><span><a href=\"#Reading-time-series-with-pandas-and-host-definition\" data-toc-modified-id=\"Reading-time-series-with-pandas-and-host-definition-5.1\"><span class=\"toc-item-num\">5.1&nbsp;&nbsp;</span>Reading time series with pandas and host definition</a></span></li><li><span><a href=\"#Reconstruction-function\" data-toc-modified-id=\"Reconstruction-function-5.2\"><span class=\"toc-item-num\">5.2&nbsp;&nbsp;</span>Reconstruction function</a></span></li><li><span><a href=\"#Normalized-data-visualization\" data-toc-modified-id=\"Normalized-data-visualization-5.3\"><span class=\"toc-item-num\">5.3&nbsp;&nbsp;</span>Normalized data visualization</a></span></li><li><span><a href=\"#How-to-retrieve-the-original-data-without-normalization\" data-toc-modified-id=\"How-to-retrieve-the-original-data-without-normalization-5.4\"><span class=\"toc-item-num\">5.4&nbsp;&nbsp;</span>How to retrieve the original data without normalization</a></span></li><li><span><a href=\"#Original-data-visualization\" data-toc-modified-id=\"Original-data-visualization-5.5\"><span class=\"toc-item-num\">5.5&nbsp;&nbsp;</span>Original data visualization</a></span></li></ul></li><li><span><a href=\"#Init-of-configuration-file---ANALYSIS\" data-toc-modified-id=\"Init-of-configuration-file---ANALYSIS-6\"><span class=\"toc-item-num\">6&nbsp;&nbsp;</span>Init of configuration file - ANALYSIS</a></span><ul class=\"toc-item\"><li><span><a href=\"#Creation\" data-toc-modified-id=\"Creation-6.1\"><span class=\"toc-item-num\">6.1&nbsp;&nbsp;</span>Creation</a></span></li><li><span><a href=\"#Reading-the-json\" data-toc-modified-id=\"Reading-the-json-6.2\"><span class=\"toc-item-num\">6.2&nbsp;&nbsp;</span>Reading the json</a></span></li></ul></li><li><span><a href=\"#ANALYSIS-to-produce-anomaly-scores\" data-toc-modified-id=\"ANALYSIS-to-produce-anomaly-scores-7\"><span class=\"toc-item-num\">7&nbsp;&nbsp;</span>ANALYSIS to produce anomaly scores</a></span><ul class=\"toc-item\"><li><span><a href=\"#Analysis\" data-toc-modified-id=\"Analysis-7.1\"><span class=\"toc-item-num\">7.1&nbsp;&nbsp;</span>Analysis</a></span></li></ul></li><li><span><a href=\"#Visualization-of-the-results\" data-toc-modified-id=\"Visualization-of-the-results-8\"><span class=\"toc-item-num\">8&nbsp;&nbsp;</span>Visualization of the results</a></span><ul class=\"toc-item\"><li><span><a href=\"#Reading-the-scores\" data-toc-modified-id=\"Reading-the-scores-8.1\"><span class=\"toc-item-num\">8.1&nbsp;&nbsp;</span>Reading the scores</a></span></li><li><span><a href=\"#Visualization-of-both-downloaded-data-and-scores\" data-toc-modified-id=\"Visualization-of-both-downloaded-data-and-scores-8.2\"><span class=\"toc-item-num\">8.2&nbsp;&nbsp;</span>Visualization of both downloaded data and scores</a></span></li></ul></li><li><span><a href=\"#ETL-Steps-not-used\" data-toc-modified-id=\"ETL-Steps-not-used-9\"><span class=\"toc-item-num\">9&nbsp;&nbsp;</span>ETL Steps not used</a></span><ul class=\"toc-item\"><li><span><a href=\"#Data-Presence\" data-toc-modified-id=\"Data-Presence-9.1\"><span class=\"toc-item-num\">9.1&nbsp;&nbsp;</span>Data Presence</a></span></li><li><span><a href=\"#Check-Normalization\" data-toc-modified-id=\"Check-Normalization-9.2\"><span class=\"toc-item-num\">9.2&nbsp;&nbsp;</span>Check Normalization</a></span></li></ul></li><li><span><a href=\"#Adding-a-model\" data-toc-modified-id=\"Adding-a-model-10\"><span class=\"toc-item-num\">10&nbsp;&nbsp;</span>Adding a model</a></span><ul class=\"toc-item\"><li><span><a href=\"#Changing-config-file---Analysis\" data-toc-modified-id=\"Changing-config-file---Analysis-10.1\"><span class=\"toc-item-num\">10.1&nbsp;&nbsp;</span>Changing config file - Analysis</a></span></li><li><span><a href=\"#Reading-the-json\" data-toc-modified-id=\"Reading-the-json-10.2\"><span class=\"toc-item-num\">10.2&nbsp;&nbsp;</span>Reading the json</a></span></li><li><span><a href=\"#Analysis-of-multiple-models\" data-toc-modified-id=\"Analysis-of-multiple-models-10.3\"><span class=\"toc-item-num\">10.3&nbsp;&nbsp;</span>Analysis of multiple models</a></span></li><li><span><a href=\"#Checking-new-results\" data-toc-modified-id=\"Checking-new-results-10.4\"><span class=\"toc-item-num\">10.4&nbsp;&nbsp;</span>Checking new results</a></span></li></ul></li></ul></div>"
12
13
14
15
   ]
  },
  {
   "cell_type": "markdown",
16
17
18
19
   "id": "understood-cross",
   "metadata": {
    "heading_collapsed": true
   },
smetaj's avatar
smetaj committed
20
   "source": [
21
    "# Demo Notebook for TimeSeries Anomaly Detection\n",
22
    "This notebook shows the Anomaly Detection system for TimeSeries in action using the tools provided in this  repository.\n",
smetaj's avatar
smetaj committed
23
    "\n",
24
25
26
27
28
    "**Note that we recommend to run this notebook using swan004.cern.ch with the following configuration:**\n",
    "- Software stack: Other releases, **97a**\n",
    "- Spark cluster: **General Purpose (Analytix)**\n",
    "\n",
    "---\n",
29
    "**REMEMBER TO ACTIVATE THE ANALYTIX CLUSTER IN THE SWAN CONFIGURATION!!**\n",
30
    "Activating it means to activate spark (click the spark icon in the upper part of the notebook to enable spark before starting to run the notebook cells)."
smetaj's avatar
smetaj committed
31
32
33
34
   ]
  },
  {
   "cell_type": "markdown",
35
36
37
38
   "id": "legendary-curve",
   "metadata": {
    "heading_collapsed": true
   },
smetaj's avatar
smetaj committed
39
   "source": [
40
    "# Installation of libraries and imports"
smetaj's avatar
smetaj committed
41
42
43
44
   ]
  },
  {
   "cell_type": "markdown",
45
46
47
48
   "id": "union-teaching",
   "metadata": {
    "hidden": true
   },
smetaj's avatar
smetaj committed
49
   "source": [
50
    "## Installation of adcern and others libraries"
smetaj's avatar
smetaj committed
51
52
53
54
55
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
56
   "id": "manual-accuracy",
smetaj's avatar
smetaj committed
57
58
   "metadata": {
    "ExecuteTime": {
59
60
61
62
     "end_time": "2021-05-03T14:28:15.289755Z",
     "start_time": "2021-05-03T14:28:15.284123Z"
    },
    "hidden": true
smetaj's avatar
smetaj committed
63
64
65
   },
   "outputs": [],
   "source": [
66
67
    "# Set the variable to True the first time to download the libraries.\n",
    "# Note that with @branch you can install a specific branch\n",
68
    "\n",
smetaj's avatar
smetaj committed
69
70
    "first_time = False\n",
    "if first_time:\n",
71
    "    # If you install the libraries it takes some minutes\n",
72
    "    !pip install --user git+https://:@gitlab.cern.ch:8443/cloud-infrastructure/data-analytics.git"
smetaj's avatar
smetaj committed
73
74
75
76
   ]
  },
  {
   "cell_type": "markdown",
77
78
79
80
   "id": "played-aluminum",
   "metadata": {
    "hidden": true
   },
smetaj's avatar
smetaj committed
81
   "source": [
82
    "## Imports"
smetaj's avatar
smetaj committed
83
84
85
86
87
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
88
   "id": "romance-prevention",
smetaj's avatar
smetaj committed
89
90
   "metadata": {
    "ExecuteTime": {
91
92
93
94
     "end_time": "2021-05-03T14:28:25.414952Z",
     "start_time": "2021-05-03T14:28:19.143582Z"
    },
    "hidden": true
smetaj's avatar
smetaj committed
95
96
97
98
99
100
101
   },
   "outputs": [],
   "source": [
    "# AD System Libraries ----------------------------------------------------\n",
    "import adcern.cmd.data_mining as DM\n",
    "import etl.spark_etl.etl_pipeline as PL\n",
    "\n",
102
103
    "# To pass command line parameters and to use other functions -------------\n",
    "import sys, os, re, json\n",
smetaj's avatar
smetaj committed
104
105
106
107
108
109
110
111
    "\n",
    "# To run the visualization function --------------------------------------\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import plotly.graph_objects as go\n",
    "from plotly.subplots import make_subplots\n",
    "\n",
112
113
    "from dateutil import tz\n",
    "\n",
smetaj's avatar
smetaj committed
114
    "# To read more parquet files with pandas ---------------------------------\n",
115
    "import glob"
smetaj's avatar
smetaj committed
116
117
118
119
   ]
  },
  {
   "cell_type": "markdown",
120
121
122
123
   "id": "superb-queens",
   "metadata": {
    "heading_collapsed": true
   },
smetaj's avatar
smetaj committed
124
   "source": [
125
    "# Init of configuration files - ETL"
smetaj's avatar
smetaj committed
126
127
128
129
   ]
  },
  {
   "cell_type": "markdown",
130
131
132
133
   "id": "confused-navigation",
   "metadata": {
    "hidden": true
   },
smetaj's avatar
smetaj committed
134
   "source": [
135
136
    "Our ETL and analysis methods work with json configuration files in input. In these files we save all the paths, the dates and the hyperparameters used then by the methods.\n",
    "\n",
137
    "Usually we have the files already saved for static tests or we create them in our production pipeline; **for the purpose of this notebook instead, we create the json files starting from a python dict.**\n",
138
    "\n",
smetaj's avatar
smetaj committed
139
140
    "Note that we need 2 config files: \n",
    "- A config file about the training part.\n",
141
    "- A config file about the data used by the trained model to infer the scores. "
smetaj's avatar
smetaj committed
142
143
144
145
   ]
  },
  {
   "cell_type": "markdown",
146
147
148
149
   "id": "possible-memory",
   "metadata": {
    "hidden": true
   },
smetaj's avatar
smetaj committed
150
   "source": [
151
    "## Creation\n",
smetaj's avatar
smetaj committed
152
153
154
155
    "Note that the 2 config files share most of the parameters so we will have:\n",
    "- json_data: containing all the main information\n",
    "- json_data_train, json_data_inference: containing specific paths for the 2 different purposes\n",
    "\n",
156
    "**Note also that you have to be sure that you have the writing rights for all the paths contained here, in particular *HDFS_folder_with_write_rights* should point to your hdfs personal folder to ensure that**"
smetaj's avatar
smetaj committed
157
158
159
160
   ]
  },
  {
   "cell_type": "code",
161
162
   "execution_count": 38,
   "id": "spoken-finding",
smetaj's avatar
smetaj committed
163
164
   "metadata": {
    "ExecuteTime": {
165
166
167
168
     "end_time": "2021-05-03T14:49:25.662860Z",
     "start_time": "2021-05-03T14:49:25.210257Z"
    },
    "hidden": true
smetaj's avatar
smetaj committed
169
170
171
172
173
174
   },
   "outputs": [],
   "source": [
    "demo_name = 'demo_AD_System'\n",
    "json_file_train = 'demo_config_train.json'\n",
    "json_file_inference = 'demo_config_inference.json'\n",
175
176
    "username = os.environ['USER']\n",
    "HDFS_folder_with_write_rights = '/user/' + username + '/'\n",
177
    "print(\"Folder to save data and results: \" + HDFS_folder_with_write_rights)\n",
smetaj's avatar
smetaj committed
178
    "\n",
179
180
    "collectd_path = \"/project/monitoring/collectd/\"\n",
    "                                  \n",
smetaj's avatar
smetaj committed
181
182
183
184
185
    "json_data = {}\n",
    "\n",
    "# Absolute path identifier of the cell/hostgroup that you want to mine.\n",
    "# Note that it is in a list format, but only one hostgroup is supported so far.\n",
    "json_data['hostgroups'] = []\n",
186
    "json_data['hostgroups'].append('cloud_compute/level2/main/gva_shared_017')\n",
smetaj's avatar
smetaj committed
187
188
189
190
191
192
193
    "\n",
    "# The pattern of the names of your data folders and \".metadata\" files.\n",
    "json_data['code_project_name'] = demo_name\n",
    "\n",
    "# Local area of your VM where to save your data and metadata data are saved in\n",
    "# folders with one parquet only. Metadata are saved in file with the same name\n",
    "# of the resepctive foler plus the \".metadata\" extension.\n",
194
195
    "json_data['local_cache_folder'] = '/eos/user/' + username[:1] + \\\n",
    "    '/' + username + '/' + demo_name + '/local_cache_'\n",
smetaj's avatar
smetaj committed
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
    "\n",
    "# HDFS Area where Spark saves the aggregated data of your cell.\n",
    "# Note that the saving can create multiple file depending on the number of\n",
    "# partitions that the workers were using.\n",
    "json_data['hdfs_out_folder'] = HDFS_folder_with_write_rights + \\\n",
    "    demo_name + '/raw_parquet_'\n",
    "\n",
    "# HDFS Area where Spark saves the aggregated data of your cell.\n",
    "# Note that here we force it to be one partiotion only.\n",
    "json_data['hdfs_cache_folder'] = HDFS_folder_with_write_rights + \\\n",
    "    demo_name + '/compressed_'\n",
    "\n",
    "# HDFS Area where Spark saves the normalization coefficients computed on the\n",
    "# normalziation chunk of data between the normalization dates.\n",
    "json_data['normalization_out_folder'] = HDFS_folder_with_write_rights + \\\n",
    "    demo_name + '/normalization/'\n",
    "\n",
    "# ----------------------------------------------------------------------------\n",
    "# ----------------------------------------------------------------------------\n",
    "\n",
    "# Wether you want to overwrite (true) or not (false) the raw data in HDFS.\n",
    "# If not sure leave true.\n",
    "json_data['overwrite_on_hdfs'] = True\n",
    "\n",
    "# Wether you want to overwrite (true) or not (false) the noramlization\n",
    "# coefficeints in HDFS. If not sure leave true.\n",
    "json_data['overwrite_normalization'] = True\n",
    "\n",
    "# The level of aggregation of your raw time series data.\n",
    "# The aggregator is typically the mean operator.\n",
    "# e.g. if 5 it means that we summarize the data every 5 min, and the values\n",
    "# with timestamp 7.45 will represent the mean of the previous 5 minutes from\n",
    "# 7.40 to 7.45 but that value will have 7.45 as timestamp\n",
    "json_data['aggregate_every_n_minutes'] = 10\n",
    "\n",
    "# The length of your windows of data.\n",
    "# e.g. if aggregate_every_n_minutes = 10 and history_steps = 6 it means that\n",
    "# every windows is summarizing 6 * 10 = 60 minutes\n",
    "json_data['history_steps'] = 48\n",
    "\n",
    "# The number of step you want to move your window.\n",
    "# e.g. if aggregate_every_n_minutes = 10 and history_steps = 2 it means that\n",
    "# you will get a window of data that is translated of 10 * 2 = 20 min with\n",
    "# respect to the previous.\n",
    "# Note that if slide_steps has the same value of history_steps you have non-\n",
    "# overlapping windows.\n",
    "json_data['slide_steps'] = 1\n",
    "\n",
    "# Used to create windows with future steps. If not sure keep this to 0.\n",
    "json_data['future_steps'] = 0\n",
    "\n",
    "# ----------------------------------------------------------------------------\n",
    "# ----------------------------------------------------------------------------\n",
    "\n",
    "# Dates representing the start/end of the data and noramlization chunks.\n",
    "# - start_date -> the starting date of data chunk of ETL\n",
    "# - end_date -> the ending date of data chunk of ETL\n",
    "# - start_date_normalization -> the starting date of the chunk of data used\n",
    "#   to learn noramlization coefficeints (typically this chunk preceeds the\n",
    "#   chunk of data)\n",
    "# - end_date_normalization -> the ending date of the chunk of data used\n",
    "#   to learn noramlization coefficeints\n",
    "# Note that the upper extremum is excluded (i.e. data will stop at the 23:59\n",
    "# of the day preeceeding the date_end_excluded)\n",
260
261
262
263
    "json_data['date_start'] = \"2021-03-01\"\n",
    "json_data['date_end_excluded'] = \"2021-03-20\"\n",
    "json_data['date_start_normalization'] = \"2021-03-01\"\n",
    "json_data['date_end_normalization_excluded'] = \"2021-03-20\"\n",
smetaj's avatar
smetaj committed
264
265
266
267
268
269
270
271
272
273
274
275
276
277
    "\n",
    "# ----------------------------------------------------------------------------\n",
    "# ----------------------------------------------------------------------------\n",
    "\n",
    "# List of plugins to mine.\n",
    "# Note that it is a dictionary where every key represents the name your plugin\n",
    "# have and the value is a dictionary with:\n",
    "# 'plugin_instance', 'type' 'type_instance', 'plugin_name'\n",
    "# the value asigned to these key is defining an and-filter.\n",
    "# you will get only the data that have all those attributes\n",
    "# ('plugin_instance', 'type' 'type_instance', 'plugin_name') in and with the\n",
    "# specified value.\n",
    "# Note that if you do not want to filter on one attribute do not express it.\n",
    "json_data['selected_plugins'] = {\n",
278
279
    "    'cpu__percent_idle': {\n",
    "        'plugin_data_path': collectd_path + 'cpu',\n",
280
    "        'plugin_filter': \"type == 'percent' and type_instance == 'idle' and plugin == 'cpu'\"\n",
281
282
283
    "    }, \n",
    "    'load_longterm': {\n",
    "        'plugin_data_path': collectd_path + 'load',\n",
284
    "        'plugin_filter': \"value_instance == 'longterm' and plugin == 'load'\"\n",
smetaj's avatar
smetaj committed
285
    "    },\n",
286
287
    "    'disk_io_time': {\n",
    "        'plugin_data_path': collectd_path + 'cloud',\n",
288
    "        'plugin_filter': \"value_instance == 'io_time' and plugin == 'disk'\"\n",
smetaj's avatar
smetaj committed
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
    "    }\n",
    "}\n",
    "\n",
    "json_data_train = json_data.copy()\n",
    "json_data_train['local_cache_folder'] += 'train/'\n",
    "json_data_train['hdfs_out_folder'] += 'train/'\n",
    "json_data_train['hdfs_cache_folder'] += 'train/'\n",
    "\n",
    "json_data_inference = json_data.copy()\n",
    "json_data_inference['local_cache_folder'] += 'inference/'\n",
    "json_data_inference['hdfs_out_folder'] += 'inference/'\n",
    "json_data_inference['hdfs_cache_folder'] += 'inference/'\n",
    "# The imporant change is that we want to have NON OVERLAPPING windows\n",
    "# in the inference!\n",
    "json_data_inference['slide_steps'] = 48\n",
304
    "# I want to infer only 24 hours!\n",
305
306
    "json_data_inference['date_start'] = \"2021-03-20\"\n",
    "json_data_inference['date_end_excluded'] = \"2021-04-20\"\n",
smetaj's avatar
smetaj committed
307
308
309
310
311
312
313
314
315
316
    "\n",
    "with open(json_file_train, 'w') as outfile:\n",
    "    json.dump(json_data_train, outfile, indent=4)\n",
    "\n",
    "with open(json_file_inference, 'w') as outfile:\n",
    "    json.dump(json_data_inference, outfile, indent=4)"
   ]
  },
  {
   "cell_type": "markdown",
317
318
319
320
   "id": "anticipated-messenger",
   "metadata": {
    "hidden": true
   },
smetaj's avatar
smetaj committed
321
   "source": [
322
    "## Reading the json"
smetaj's avatar
smetaj committed
323
324
325
326
   ]
  },
  {
   "cell_type": "code",
327
328
   "execution_count": 39,
   "id": "empty-september",
smetaj's avatar
smetaj committed
329
330
   "metadata": {
    "ExecuteTime": {
331
332
333
334
     "end_time": "2021-05-03T14:49:30.976439Z",
     "start_time": "2021-05-03T14:49:30.953248Z"
    },
    "hidden": true
smetaj's avatar
smetaj committed
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "RESOURCE DETAILS: demo_config_train.json\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "{\n",
      "    \"hostgroups\": [\n",
350
      "        \"cloud_compute/level2/main/gva_shared_017\"\n",
smetaj's avatar
smetaj committed
351
352
      "    ],\n",
      "    \"code_project_name\": \"demo_AD_System\",\n",
353
      "    \"local_cache_folder\": \"/eos/user/s/smetaj/demo_AD_System/local_cache_train/\",\n",
smetaj's avatar
smetaj committed
354
355
356
357
358
359
360
361
362
      "    \"hdfs_out_folder\": \"/user/smetaj/demo_AD_System/raw_parquet_train/\",\n",
      "    \"hdfs_cache_folder\": \"/user/smetaj/demo_AD_System/compressed_train/\",\n",
      "    \"normalization_out_folder\": \"/user/smetaj/demo_AD_System/normalization/\",\n",
      "    \"overwrite_on_hdfs\": true,\n",
      "    \"overwrite_normalization\": true,\n",
      "    \"aggregate_every_n_minutes\": 10,\n",
      "    \"history_steps\": 48,\n",
      "    \"slide_steps\": 1,\n",
      "    \"future_steps\": 0,\n",
363
364
365
366
      "    \"date_start\": \"2021-03-01\",\n",
      "    \"date_end_excluded\": \"2021-03-20\",\n",
      "    \"date_start_normalization\": \"2021-03-01\",\n",
      "    \"date_end_normalization_excluded\": \"2021-03-20\",\n",
smetaj's avatar
smetaj committed
367
      "    \"selected_plugins\": {\n",
368
369
      "        \"cpu__percent_idle\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cpu\",\n",
370
      "            \"plugin_filter\": \"type == 'percent' and type_instance == 'idle' and plugin == 'cpu'\"\n",
smetaj's avatar
smetaj committed
371
      "        },\n",
372
373
      "        \"load_longterm\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/load\",\n",
374
      "            \"plugin_filter\": \"value_instance == 'longterm' and plugin == 'load'\"\n",
smetaj's avatar
smetaj committed
375
      "        },\n",
376
377
      "        \"disk_io_time\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cloud\",\n",
378
      "            \"plugin_filter\": \"value_instance == 'io_time' and plugin == 'disk'\"\n",
smetaj's avatar
smetaj committed
379
380
381
382
383
384
385
386
387
388
389
390
      "        }\n",
      "    }\n",
      "}\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "RESOURCE DETAILS: demo_config_inference.json\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "{\n",
      "    \"hostgroups\": [\n",
391
      "        \"cloud_compute/level2/main/gva_shared_017\"\n",
smetaj's avatar
smetaj committed
392
393
      "    ],\n",
      "    \"code_project_name\": \"demo_AD_System\",\n",
394
      "    \"local_cache_folder\": \"/eos/user/s/smetaj/demo_AD_System/local_cache_inference/\",\n",
smetaj's avatar
smetaj committed
395
396
397
398
399
400
401
402
403
      "    \"hdfs_out_folder\": \"/user/smetaj/demo_AD_System/raw_parquet_inference/\",\n",
      "    \"hdfs_cache_folder\": \"/user/smetaj/demo_AD_System/compressed_inference/\",\n",
      "    \"normalization_out_folder\": \"/user/smetaj/demo_AD_System/normalization/\",\n",
      "    \"overwrite_on_hdfs\": true,\n",
      "    \"overwrite_normalization\": true,\n",
      "    \"aggregate_every_n_minutes\": 10,\n",
      "    \"history_steps\": 48,\n",
      "    \"slide_steps\": 48,\n",
      "    \"future_steps\": 0,\n",
404
405
406
407
      "    \"date_start\": \"2021-03-20\",\n",
      "    \"date_end_excluded\": \"2021-04-20\",\n",
      "    \"date_start_normalization\": \"2021-03-01\",\n",
      "    \"date_end_normalization_excluded\": \"2021-03-20\",\n",
smetaj's avatar
smetaj committed
408
      "    \"selected_plugins\": {\n",
409
410
      "        \"cpu__percent_idle\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cpu\",\n",
411
      "            \"plugin_filter\": \"type == 'percent' and type_instance == 'idle' and plugin == 'cpu'\"\n",
smetaj's avatar
smetaj committed
412
      "        },\n",
413
414
      "        \"load_longterm\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/load\",\n",
415
      "            \"plugin_filter\": \"value_instance == 'longterm' and plugin == 'load'\"\n",
smetaj's avatar
smetaj committed
416
      "        },\n",
417
418
      "        \"disk_io_time\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cloud\",\n",
419
      "            \"plugin_filter\": \"value_instance == 'io_time' and plugin == 'disk'\"\n",
smetaj's avatar
smetaj committed
420
421
422
423
424
425
426
      "        }\n",
      "    }\n",
      "}\n"
     ]
    }
   ],
   "source": [
427
428
429
    "# Let's use the read_resource function in the data_mining library to be \n",
    "# sure that the format is correct and to print the files.\n",
    "\n",
smetaj's avatar
smetaj committed
430
431
432
433
434
435
    "_ = DM.read_resource(resource_file=json_file_train)\n",
    "_ = DM.read_resource(resource_file=json_file_inference)"
   ]
  },
  {
   "cell_type": "markdown",
436
437
438
439
   "id": "focused-ballot",
   "metadata": {
    "heading_collapsed": true
   },
smetaj's avatar
smetaj committed
440
   "source": [
441
    "# ETL steps (Extract, Transform, Load)"
smetaj's avatar
smetaj committed
442
443
444
445
   ]
  },
  {
   "cell_type": "markdown",
446
447
448
449
   "id": "figured-ground",
   "metadata": {
    "hidden": true
   },
smetaj's avatar
smetaj committed
450
451
452
453
   "source": [
    "What we want to achieve here is to reproduce the steps to download and normalize the data (following the order in the graph below).\n",
    "![](https://mattermost.web.cern.ch/files/skktqwaws7nkzpb16c73n11tac/public?h=KflwzsI6wpa58LJCUgTGH-r8dJHEskq_a4R_05QMOPg)\n",
    "\n",
454
    "For every step, we will call the specific function of the data_mining library (for both the json files in most of the cases). \n",
smetaj's avatar
smetaj committed
455
    "\n",
456
    "**Note that we use the click python library (it permits to use python functions through the command line but it has a default behavior that calls exit(0) at the end of them). To avoid the exit(0) problem just use the standalone_mode=False option.**\n",
smetaj's avatar
smetaj committed
457
    "\n",
458
    "Moreover, we will skip the first 2 steps of the pipeline that we show in the image above (data_presence and check_normalization) because they are used in production pipelines to check and avoid the re-processing of already processed time intervals. For the purpose of this example, we will force the reprocessing if data are available"
smetaj's avatar
smetaj committed
459
460
461
462
   ]
  },
  {
   "cell_type": "markdown",
463
464
465
466
   "id": "played-faculty",
   "metadata": {
    "hidden": true
   },
smetaj's avatar
smetaj committed
467
   "source": [
468
    "## Compute Normalization"
smetaj's avatar
smetaj committed
469
470
471
472
   ]
  },
  {
   "cell_type": "code",
473
474
   "execution_count": 40,
   "id": "attempted-wrist",
smetaj's avatar
smetaj committed
475
476
   "metadata": {
    "ExecuteTime": {
477
478
     "end_time": "2021-05-03T14:51:01.068276Z",
     "start_time": "2021-05-03T14:49:34.205805Z"
smetaj's avatar
smetaj committed
479
    },
480
    "hidden": true,
481
    "scrolled": false
smetaj's avatar
smetaj committed
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "PREPARING SPARK:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SPARK CONTEXT: <SparkContext master=yarn appName=pyspark_shell_swan>\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
505
      "SPARK OBJECT: <pyspark.sql.session.SparkSession object at 0x7f40f5cfdd90>\n",
smetaj's avatar
smetaj committed
506
507
508
509
510
511
512
513
514
515
516
517
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "RESOURCE DETAILS: demo_config_train.json\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "{\n",
      "    \"hostgroups\": [\n",
518
      "        \"cloud_compute/level2/main/gva_shared_017\"\n",
smetaj's avatar
smetaj committed
519
520
      "    ],\n",
      "    \"code_project_name\": \"demo_AD_System\",\n",
521
      "    \"local_cache_folder\": \"/eos/user/s/smetaj/demo_AD_System/local_cache_train/\",\n",
smetaj's avatar
smetaj committed
522
523
524
525
526
527
528
529
530
      "    \"hdfs_out_folder\": \"/user/smetaj/demo_AD_System/raw_parquet_train/\",\n",
      "    \"hdfs_cache_folder\": \"/user/smetaj/demo_AD_System/compressed_train/\",\n",
      "    \"normalization_out_folder\": \"/user/smetaj/demo_AD_System/normalization/\",\n",
      "    \"overwrite_on_hdfs\": true,\n",
      "    \"overwrite_normalization\": true,\n",
      "    \"aggregate_every_n_minutes\": 10,\n",
      "    \"history_steps\": 48,\n",
      "    \"slide_steps\": 1,\n",
      "    \"future_steps\": 0,\n",
531
532
533
534
      "    \"date_start\": \"2021-03-01\",\n",
      "    \"date_end_excluded\": \"2021-03-20\",\n",
      "    \"date_start_normalization\": \"2021-03-01\",\n",
      "    \"date_end_normalization_excluded\": \"2021-03-20\",\n",
smetaj's avatar
smetaj committed
535
      "    \"selected_plugins\": {\n",
536
537
      "        \"cpu__percent_idle\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cpu\",\n",
538
      "            \"plugin_filter\": \"type == 'percent' and type_instance == 'idle' and plugin == 'cpu'\"\n",
smetaj's avatar
smetaj committed
539
      "        },\n",
540
541
      "        \"load_longterm\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/load\",\n",
542
      "            \"plugin_filter\": \"value_instance == 'longterm' and plugin == 'load'\"\n",
smetaj's avatar
smetaj committed
543
      "        },\n",
544
545
      "        \"disk_io_time\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cloud\",\n",
546
      "            \"plugin_filter\": \"value_instance == 'io_time' and plugin == 'disk'\"\n",
smetaj's avatar
smetaj committed
547
548
549
550
551
552
553
554
555
556
      "        }\n",
      "    }\n",
      "}\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "COMPUTE NORMALIZATION COEFFICIENTS:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
      "Start: (2021, 3, 1) - End (2021, 3, 19)\n",
      "{'plugin_data_path': '/project/monitoring/collectd/cpu', 'plugin_filter': \"type == 'percent' and type_instance == 'idle' and plugin == 'cpu'\"}\n",
      "{'plugin_data_path': '/project/monitoring/collectd/load', 'plugin_filter': \"value_instance == 'longterm' and plugin == 'load'\"}\n",
      "{'plugin_data_path': '/project/monitoring/collectd/cloud', 'plugin_filter': \"value_instance == 'io_time' and plugin == 'disk'\"}\n",
      "/project/monitoring/collectd/cloud/2021/03/01/\n",
      "/project/monitoring/collectd/cloud/2021/03/02/\n",
      "/project/monitoring/collectd/cloud/2021/03/03/\n",
      "/project/monitoring/collectd/cloud/2021/03/04/\n",
      "/project/monitoring/collectd/cloud/2021/03/05/\n",
      "/project/monitoring/collectd/cloud/2021/03/06/\n",
      "/project/monitoring/collectd/cloud/2021/03/07/\n",
      "/project/monitoring/collectd/cloud/2021/03/08/\n",
      "/project/monitoring/collectd/cloud/2021/03/09/\n",
      "/project/monitoring/collectd/cloud/2021/03/10/\n",
      "/project/monitoring/collectd/cloud/2021/03/11/\n",
      "/project/monitoring/collectd/cloud/2021/03/12/\n",
      "/project/monitoring/collectd/cloud/2021/03/13/\n",
      "/project/monitoring/collectd/cloud/2021/03/14/\n",
      "/project/monitoring/collectd/cloud/2021/03/15/\n",
      "/project/monitoring/collectd/cloud/2021/03/16/\n",
      "/project/monitoring/collectd/cloud/2021/03/17/\n",
      "/project/monitoring/collectd/cloud/2021/03/18/\n",
      "/project/monitoring/collectd/cloud/2021/03/19/\n",
      "/project/monitoring/collectd/cpu/2021/03/01/\n",
      "/project/monitoring/collectd/cpu/2021/03/02/\n",
      "/project/monitoring/collectd/cpu/2021/03/03/\n",
      "/project/monitoring/collectd/cpu/2021/03/04/\n",
      "/project/monitoring/collectd/cpu/2021/03/05/\n",
      "/project/monitoring/collectd/cpu/2021/03/06/\n",
      "/project/monitoring/collectd/cpu/2021/03/07/\n",
      "/project/monitoring/collectd/cpu/2021/03/08/\n",
      "/project/monitoring/collectd/cpu/2021/03/09/\n",
      "/project/monitoring/collectd/cpu/2021/03/10/\n",
      "/project/monitoring/collectd/cpu/2021/03/11/\n",
      "/project/monitoring/collectd/cpu/2021/03/12/\n",
      "/project/monitoring/collectd/cpu/2021/03/13/\n",
      "/project/monitoring/collectd/cpu/2021/03/14/\n",
      "/project/monitoring/collectd/cpu/2021/03/15/\n",
      "/project/monitoring/collectd/cpu/2021/03/16/\n",
      "/project/monitoring/collectd/cpu/2021/03/17/\n",
      "/project/monitoring/collectd/cpu/2021/03/18/\n",
      "/project/monitoring/collectd/cpu/2021/03/19/\n",
      "/project/monitoring/collectd/load/2021/03/01/\n",
      "/project/monitoring/collectd/load/2021/03/02/\n",
      "/project/monitoring/collectd/load/2021/03/03/\n",
      "/project/monitoring/collectd/load/2021/03/04/\n",
      "/project/monitoring/collectd/load/2021/03/05/\n",
      "/project/monitoring/collectd/load/2021/03/06/\n",
      "/project/monitoring/collectd/load/2021/03/07/\n",
      "/project/monitoring/collectd/load/2021/03/08/\n",
      "/project/monitoring/collectd/load/2021/03/09/\n",
      "/project/monitoring/collectd/load/2021/03/10/\n",
      "/project/monitoring/collectd/load/2021/03/11/\n",
      "/project/monitoring/collectd/load/2021/03/12/\n",
      "/project/monitoring/collectd/load/2021/03/13/\n",
      "/project/monitoring/collectd/load/2021/03/14/\n",
      "/project/monitoring/collectd/load/2021/03/15/\n",
      "/project/monitoring/collectd/load/2021/03/16/\n",
      "/project/monitoring/collectd/load/2021/03/17/\n",
      "/project/monitoring/collectd/load/2021/03/18/\n",
      "/project/monitoring/collectd/load/2021/03/19/\n",
618
      "filter_str:  ( type == 'percent' and type_instance == 'idle' and plugin == 'cpu' ) or ( value_instance == 'longterm' and plugin == 'load' ) or ( value_instance == 'io_time' and plugin == 'disk' )\n",
619
      "NEW id_norm:  ef8bce\n",
smetaj's avatar
smetaj committed
620
621
622
623
624
625
626
627
628
      "Normalization Saved successfully\n",
      "Coefficient preparation shared:  0\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SUCCESS (inspect the first 40 rows):\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
629
      "                                  hostgroup             plugin    mean  stddev\n",
630
631
632
      "0  cloud_compute/level2/main/gva_shared_017  cpu__percent_idle  74.198  18.997\n",
      "1  cloud_compute/level2/main/gva_shared_017      load_longterm   0.302   0.294\n",
      "2  cloud_compute/level2/main/gva_shared_017       disk_io_time  60.421  69.629\n"
smetaj's avatar
smetaj committed
633
634
635
636
     ]
    }
   ],
   "source": [
637
    "# We must download firstly the normalization coefficients that we will use\n",
638
    "# to normalize the real data that we will download later.\n",
639
640
    "\n",
    "# Note that the function will use the same path for both both train and \n",
641
    "# inference (because the hostgroup, the dates and the plugins are the same).\n",
642
643
644
    "\n",
    "sys.argv = ['', '--resource_file', json_file_train]\n",
    "DM.compute_normalization(standalone_mode=False)"
smetaj's avatar
smetaj committed
645
646
647
648
   ]
  },
  {
   "cell_type": "markdown",
649
   "id": "nonprofit-furniture",
smetaj's avatar
smetaj committed
650
651
652
653
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-04-15T08:08:23.318591Z",
     "start_time": "2021-04-15T08:08:23.267079Z"
654
655
    },
    "hidden": true
smetaj's avatar
smetaj committed
656
657
   },
   "source": [
658
    "## Transform Data"
smetaj's avatar
smetaj committed
659
660
661
662
   ]
  },
  {
   "cell_type": "code",
663
664
   "execution_count": 41,
   "id": "middle-convention",
smetaj's avatar
smetaj committed
665
666
   "metadata": {
    "ExecuteTime": {
667
668
669
670
671
     "end_time": "2021-05-03T14:52:57.741856Z",
     "start_time": "2021-05-03T14:51:01.075438Z"
    },
    "hidden": true,
    "scrolled": true
smetaj's avatar
smetaj committed
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "PREPARING SPARK:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SPARK CONTEXT: <SparkContext master=yarn appName=pyspark_shell_swan>\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
695
      "SPARK OBJECT: <pyspark.sql.session.SparkSession object at 0x7f4081d8a4d0>\n",
smetaj's avatar
smetaj committed
696
697
698
699
700
701
702
703
704
705
706
707
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "RESOURCE DETAILS: demo_config_train.json\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "{\n",
      "    \"hostgroups\": [\n",
708
      "        \"cloud_compute/level2/main/gva_shared_017\"\n",
smetaj's avatar
smetaj committed
709
710
      "    ],\n",
      "    \"code_project_name\": \"demo_AD_System\",\n",
711
      "    \"local_cache_folder\": \"/eos/user/s/smetaj/demo_AD_System/local_cache_train/\",\n",
smetaj's avatar
smetaj committed
712
713
714
715
716
717
718
719
720
      "    \"hdfs_out_folder\": \"/user/smetaj/demo_AD_System/raw_parquet_train/\",\n",
      "    \"hdfs_cache_folder\": \"/user/smetaj/demo_AD_System/compressed_train/\",\n",
      "    \"normalization_out_folder\": \"/user/smetaj/demo_AD_System/normalization/\",\n",
      "    \"overwrite_on_hdfs\": true,\n",
      "    \"overwrite_normalization\": true,\n",
      "    \"aggregate_every_n_minutes\": 10,\n",
      "    \"history_steps\": 48,\n",
      "    \"slide_steps\": 1,\n",
      "    \"future_steps\": 0,\n",
721
722
723
724
      "    \"date_start\": \"2021-03-01\",\n",
      "    \"date_end_excluded\": \"2021-03-20\",\n",
      "    \"date_start_normalization\": \"2021-03-01\",\n",
      "    \"date_end_normalization_excluded\": \"2021-03-20\",\n",
smetaj's avatar
smetaj committed
725
      "    \"selected_plugins\": {\n",
726
727
      "        \"cpu__percent_idle\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cpu\",\n",
728
      "            \"plugin_filter\": \"type == 'percent' and type_instance == 'idle' and plugin == 'cpu'\"\n",
smetaj's avatar
smetaj committed
729
      "        },\n",
730
731
      "        \"load_longterm\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/load\",\n",
732
      "            \"plugin_filter\": \"value_instance == 'longterm' and plugin == 'load'\"\n",
smetaj's avatar
smetaj committed
733
      "        },\n",
734
735
      "        \"disk_io_time\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cloud\",\n",
736
      "            \"plugin_filter\": \"value_instance == 'io_time' and plugin == 'disk'\"\n",
smetaj's avatar
smetaj committed
737
738
739
740
741
742
743
744
745
746
      "        }\n",
      "    }\n",
      "}\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "DOWNLOAD DATA - LONG MINING PROCESS...\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
      "Start: (2021, 3, 1) - End (2021, 3, 19)\n",
      "Reading normalization:  ef8bce\n",
      "{'plugin_data_path': '/project/monitoring/collectd/cpu', 'plugin_filter': \"type == 'percent' and type_instance == 'idle' and plugin == 'cpu'\"}\n",
      "{'plugin_data_path': '/project/monitoring/collectd/load', 'plugin_filter': \"value_instance == 'longterm' and plugin == 'load'\"}\n",
      "{'plugin_data_path': '/project/monitoring/collectd/cloud', 'plugin_filter': \"value_instance == 'io_time' and plugin == 'disk'\"}\n",
      "/project/monitoring/collectd/cloud/2021/03/01/\n",
      "/project/monitoring/collectd/cloud/2021/03/02/\n",
      "/project/monitoring/collectd/cloud/2021/03/03/\n",
      "/project/monitoring/collectd/cloud/2021/03/04/\n",
      "/project/monitoring/collectd/cloud/2021/03/05/\n",
      "/project/monitoring/collectd/cloud/2021/03/06/\n",
      "/project/monitoring/collectd/cloud/2021/03/07/\n",
      "/project/monitoring/collectd/cloud/2021/03/08/\n",
      "/project/monitoring/collectd/cloud/2021/03/09/\n",
      "/project/monitoring/collectd/cloud/2021/03/10/\n",
      "/project/monitoring/collectd/cloud/2021/03/11/\n",
      "/project/monitoring/collectd/cloud/2021/03/12/\n",
      "/project/monitoring/collectd/cloud/2021/03/13/\n",
      "/project/monitoring/collectd/cloud/2021/03/14/\n",
      "/project/monitoring/collectd/cloud/2021/03/15/\n",
      "/project/monitoring/collectd/cloud/2021/03/16/\n",
      "/project/monitoring/collectd/cloud/2021/03/17/\n",
      "/project/monitoring/collectd/cloud/2021/03/18/\n",
      "/project/monitoring/collectd/cloud/2021/03/19/\n",
      "/project/monitoring/collectd/cpu/2021/03/01/\n",
      "/project/monitoring/collectd/cpu/2021/03/02/\n",
      "/project/monitoring/collectd/cpu/2021/03/03/\n",
      "/project/monitoring/collectd/cpu/2021/03/04/\n",
      "/project/monitoring/collectd/cpu/2021/03/05/\n",
      "/project/monitoring/collectd/cpu/2021/03/06/\n",
      "/project/monitoring/collectd/cpu/2021/03/07/\n",
      "/project/monitoring/collectd/cpu/2021/03/08/\n",
      "/project/monitoring/collectd/cpu/2021/03/09/\n",
      "/project/monitoring/collectd/cpu/2021/03/10/\n",
      "/project/monitoring/collectd/cpu/2021/03/11/\n",
      "/project/monitoring/collectd/cpu/2021/03/12/\n",
      "/project/monitoring/collectd/cpu/2021/03/13/\n",
      "/project/monitoring/collectd/cpu/2021/03/14/\n",
      "/project/monitoring/collectd/cpu/2021/03/15/\n",
      "/project/monitoring/collectd/cpu/2021/03/16/\n",
      "/project/monitoring/collectd/cpu/2021/03/17/\n",
      "/project/monitoring/collectd/cpu/2021/03/18/\n",
      "/project/monitoring/collectd/cpu/2021/03/19/\n",
      "/project/monitoring/collectd/load/2021/03/01/\n",
      "/project/monitoring/collectd/load/2021/03/02/\n",
      "/project/monitoring/collectd/load/2021/03/03/\n",
      "/project/monitoring/collectd/load/2021/03/04/\n",
      "/project/monitoring/collectd/load/2021/03/05/\n",
      "/project/monitoring/collectd/load/2021/03/06/\n",
      "/project/monitoring/collectd/load/2021/03/07/\n",
      "/project/monitoring/collectd/load/2021/03/08/\n",
      "/project/monitoring/collectd/load/2021/03/09/\n",
      "/project/monitoring/collectd/load/2021/03/10/\n",
      "/project/monitoring/collectd/load/2021/03/11/\n",
      "/project/monitoring/collectd/load/2021/03/12/\n",
      "/project/monitoring/collectd/load/2021/03/13/\n",
      "/project/monitoring/collectd/load/2021/03/14/\n",
      "/project/monitoring/collectd/load/2021/03/15/\n",
      "/project/monitoring/collectd/load/2021/03/16/\n",
      "/project/monitoring/collectd/load/2021/03/17/\n",
      "/project/monitoring/collectd/load/2021/03/18/\n",
      "/project/monitoring/collectd/load/2021/03/19/\n",
809
810
      "filter_str:  ( type == 'percent' and type_instance == 'idle' and plugin == 'cpu' ) or ( value_instance == 'longterm' and plugin == 'load' ) or ( value_instance == 'io_time' and plugin == 'disk' )\n",
      "['cpu__percent_idle', 'load_longterm', 'disk_io_time']\n",
smetaj's avatar
smetaj committed
811
812
813
814
815
816
817
818
819
820
      "Deleting any previous/old remainders in /user/smetaj/demo_AD_System/raw_parquet_train//demo_AD_System ...\n",
      "Error while deleting directory:  [Errno 2] No such file or directory: '/user/smetaj/demo_AD_System/raw_parquet_train//demo_AD_System'\n",
      "Saving the big guy (window dataframe) in: /user/smetaj/demo_AD_System/raw_parquet_train//demo_AD_System ..\n",
      "Saved successfully: /user/smetaj/demo_AD_System/raw_parquet_train//demo_AD_System\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SUCCESS - DATA AGGREGATED IN HDFS.\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
821
822
823
824
825
826
      "\n"
     ]
    }
   ],
   "source": [
    "# Here we download the data that we will normalize using the coefficients \n",
827
    "# produced by the previous step.\n",
828
829
830
831
832
    "\n",
    "# Note that we have to download both the train and the inference datasets,\n",
    "# so we will have 2 different download_data calls.\n",
    "    \n",
    "sys.argv = ['', '--resource_file', json_file_train]\n",
833
    "DM.transform_data(standalone_mode=False)"
834
835
836
837
   ]
  },
  {
   "cell_type": "code",
838
839
   "execution_count": 42,
   "id": "theoretical-visit",
840
841
   "metadata": {
    "ExecuteTime": {
842
843
844
845
     "end_time": "2021-05-03T14:55:39.191564Z",
     "start_time": "2021-05-03T14:52:57.746059Z"
    },
    "hidden": true
846
847
848
849
850
851
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
smetaj's avatar
smetaj committed
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "PREPARING SPARK:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SPARK CONTEXT: <SparkContext master=yarn appName=pyspark_shell_swan>\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
869
      "SPARK OBJECT: <pyspark.sql.session.SparkSession object at 0x7f4081da5d10>\n",
smetaj's avatar
smetaj committed
870
871
872
873
874
875
876
877
878
879
880
881
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "RESOURCE DETAILS: demo_config_inference.json\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "{\n",
      "    \"hostgroups\": [\n",
882
      "        \"cloud_compute/level2/main/gva_shared_017\"\n",
smetaj's avatar
smetaj committed
883
884
      "    ],\n",
      "    \"code_project_name\": \"demo_AD_System\",\n",
885
      "    \"local_cache_folder\": \"/eos/user/s/smetaj/demo_AD_System/local_cache_inference/\",\n",
smetaj's avatar
smetaj committed
886
887
888
889
890
891
892
893
894
      "    \"hdfs_out_folder\": \"/user/smetaj/demo_AD_System/raw_parquet_inference/\",\n",
      "    \"hdfs_cache_folder\": \"/user/smetaj/demo_AD_System/compressed_inference/\",\n",
      "    \"normalization_out_folder\": \"/user/smetaj/demo_AD_System/normalization/\",\n",
      "    \"overwrite_on_hdfs\": true,\n",
      "    \"overwrite_normalization\": true,\n",
      "    \"aggregate_every_n_minutes\": 10,\n",
      "    \"history_steps\": 48,\n",
      "    \"slide_steps\": 48,\n",
      "    \"future_steps\": 0,\n",
895
896
897
898
      "    \"date_start\": \"2021-03-20\",\n",
      "    \"date_end_excluded\": \"2021-04-20\",\n",
      "    \"date_start_normalization\": \"2021-03-01\",\n",
      "    \"date_end_normalization_excluded\": \"2021-03-20\",\n",
smetaj's avatar
smetaj committed
899
      "    \"selected_plugins\": {\n",
900
901
      "        \"cpu__percent_idle\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cpu\",\n",
902
      "            \"plugin_filter\": \"type == 'percent' and type_instance == 'idle' and plugin == 'cpu'\"\n",
smetaj's avatar
smetaj committed
903
      "        },\n",
904
905
      "        \"load_longterm\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/load\",\n",
906
      "            \"plugin_filter\": \"value_instance == 'longterm' and plugin == 'load'\"\n",
smetaj's avatar
smetaj committed
907
      "        },\n",
908
909
      "        \"disk_io_time\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cloud\",\n",
910
      "            \"plugin_filter\": \"value_instance == 'io_time' and plugin == 'disk'\"\n",
smetaj's avatar
smetaj committed
911
912
913
914
915
916
917
918
919
920
      "        }\n",
      "    }\n",
      "}\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "DOWNLOAD DATA - LONG MINING PROCESS...\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
      "Start: (2021, 3, 20) - End (2021, 4, 19)\n",
      "Reading normalization:  ef8bce\n",
      "{'plugin_data_path': '/project/monitoring/collectd/cpu', 'plugin_filter': \"type == 'percent' and type_instance == 'idle' and plugin == 'cpu'\"}\n",
      "{'plugin_data_path': '/project/monitoring/collectd/load', 'plugin_filter': \"value_instance == 'longterm' and plugin == 'load'\"}\n",
      "{'plugin_data_path': '/project/monitoring/collectd/cloud', 'plugin_filter': \"value_instance == 'io_time' and plugin == 'disk'\"}\n",
      "not found:  /project/monitoring/collectd/load/2021/04/14/\n",
      "not found:  /project/monitoring/collectd/cpu/2021/04/14/\n",
      "not found:  /project/monitoring/collectd/cloud/2021/04/14/\n",
      "/project/monitoring/collectd/cloud/2021/03/20/\n",
      "/project/monitoring/collectd/cloud/2021/03/21/\n",
      "/project/monitoring/collectd/cloud/2021/03/22/\n",
      "/project/monitoring/collectd/cloud/2021/03/23/\n",
      "/project/monitoring/collectd/cloud/2021/03/24/\n",
      "/project/monitoring/collectd/cloud/2021/03/25/\n",
      "/project/monitoring/collectd/cloud/2021/03/26/\n",
      "/project/monitoring/collectd/cloud/2021/03/27/\n",
      "/project/monitoring/collectd/cloud/2021/03/28/\n",
      "/project/monitoring/collectd/cloud/2021/03/29/\n",
      "/project/monitoring/collectd/cloud/2021/03/30/\n",
      "/project/monitoring/collectd/cloud/2021/03/31/\n",
      "/project/monitoring/collectd/cloud/2021/04/01/\n",
      "/project/monitoring/collectd/cloud/2021/04/02/\n",
      "/project/monitoring/collectd/cloud/2021/04/03/\n",
      "/project/monitoring/collectd/cloud/2021/04/04/\n",
      "/project/monitoring/collectd/cloud/2021/04/05/\n",
      "/project/monitoring/collectd/cloud/2021/04/06/\n",
      "/project/monitoring/collectd/cloud/2021/04/07/\n",
      "/project/monitoring/collectd/cloud/2021/04/08/\n",
      "/project/monitoring/collectd/cloud/2021/04/09/\n",
      "/project/monitoring/collectd/cloud/2021/04/10/\n",
      "/project/monitoring/collectd/cloud/2021/04/11/\n",
952
      "/project/monitoring/collectd/cloud/2021/04/12/\n",
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
      "/project/monitoring/collectd/cloud/2021/04/13/\n",
      "/project/monitoring/collectd/cloud/2021/04/15/\n",
      "/project/monitoring/collectd/cloud/2021/04/16/\n",
      "/project/monitoring/collectd/cloud/2021/04/17/\n",
      "/project/monitoring/collectd/cloud/2021/04/18/\n",
      "/project/monitoring/collectd/cloud/2021/04/19/\n",
      "/project/monitoring/collectd/cpu/2021/03/20/\n",
      "/project/monitoring/collectd/cpu/2021/03/21/\n",
      "/project/monitoring/collectd/cpu/2021/03/22/\n",
      "/project/monitoring/collectd/cpu/2021/03/23/\n",
      "/project/monitoring/collectd/cpu/2021/03/24/\n",
      "/project/monitoring/collectd/cpu/2021/03/25/\n",
      "/project/monitoring/collectd/cpu/2021/03/26/\n",
      "/project/monitoring/collectd/cpu/2021/03/27/\n",
      "/project/monitoring/collectd/cpu/2021/03/28/\n",
      "/project/monitoring/collectd/cpu/2021/03/29/\n",
      "/project/monitoring/collectd/cpu/2021/03/30/\n",
      "/project/monitoring/collectd/cpu/2021/03/31/\n",
      "/project/monitoring/collectd/cpu/2021/04/01/\n",
      "/project/monitoring/collectd/cpu/2021/04/02/\n",
      "/project/monitoring/collectd/cpu/2021/04/03/\n",
      "/project/monitoring/collectd/cpu/2021/04/04/\n",
      "/project/monitoring/collectd/cpu/2021/04/05/\n",
      "/project/monitoring/collectd/cpu/2021/04/06/\n",
      "/project/monitoring/collectd/cpu/2021/04/07/\n",
      "/project/monitoring/collectd/cpu/2021/04/08/\n",
      "/project/monitoring/collectd/cpu/2021/04/09/\n",
      "/project/monitoring/collectd/cpu/2021/04/10/\n",
      "/project/monitoring/collectd/cpu/2021/04/11/\n",
982
      "/project/monitoring/collectd/cpu/2021/04/12/\n",
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
      "/project/monitoring/collectd/cpu/2021/04/13/\n",
      "/project/monitoring/collectd/cpu/2021/04/15/\n",
      "/project/monitoring/collectd/cpu/2021/04/16/\n",
      "/project/monitoring/collectd/cpu/2021/04/17/\n",
      "/project/monitoring/collectd/cpu/2021/04/18/\n",
      "/project/monitoring/collectd/cpu/2021/04/19/\n",
      "/project/monitoring/collectd/load/2021/03/20/\n",
      "/project/monitoring/collectd/load/2021/03/21/\n",
      "/project/monitoring/collectd/load/2021/03/22/\n",
      "/project/monitoring/collectd/load/2021/03/23/\n",
      "/project/monitoring/collectd/load/2021/03/24/\n",
      "/project/monitoring/collectd/load/2021/03/25/\n",
      "/project/monitoring/collectd/load/2021/03/26/\n",
      "/project/monitoring/collectd/load/2021/03/27/\n",
      "/project/monitoring/collectd/load/2021/03/28/\n",
      "/project/monitoring/collectd/load/2021/03/29/\n",
      "/project/monitoring/collectd/load/2021/03/30/\n",
      "/project/monitoring/collectd/load/2021/03/31/\n",
      "/project/monitoring/collectd/load/2021/04/01/\n",
      "/project/monitoring/collectd/load/2021/04/02/\n",
      "/project/monitoring/collectd/load/2021/04/03/\n",
      "/project/monitoring/collectd/load/2021/04/04/\n",
      "/project/monitoring/collectd/load/2021/04/05/\n",
      "/project/monitoring/collectd/load/2021/04/06/\n",
      "/project/monitoring/collectd/load/2021/04/07/\n",
      "/project/monitoring/collectd/load/2021/04/08/\n",
      "/project/monitoring/collectd/load/2021/04/09/\n",
      "/project/monitoring/collectd/load/2021/04/10/\n",
      "/project/monitoring/collectd/load/2021/04/11/\n",
1012
      "/project/monitoring/collectd/load/2021/04/12/\n",
1013
1014
1015
1016
1017
1018
      "/project/monitoring/collectd/load/2021/04/13/\n",
      "/project/monitoring/collectd/load/2021/04/15/\n",
      "/project/monitoring/collectd/load/2021/04/16/\n",
      "/project/monitoring/collectd/load/2021/04/17/\n",
      "/project/monitoring/collectd/load/2021/04/18/\n",
      "/project/monitoring/collectd/load/2021/04/19/\n",
1019
1020
      "filter_str:  ( type == 'percent' and type_instance == 'idle' and plugin == 'cpu' ) or ( value_instance == 'longterm' and plugin == 'load' ) or ( value_instance == 'io_time' and plugin == 'disk' )\n",
      "['cpu__percent_idle', 'load_longterm', 'disk_io_time']\n",
smetaj's avatar
smetaj committed
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
      "Deleting any previous/old remainders in /user/smetaj/demo_AD_System/raw_parquet_inference//demo_AD_System ...\n",
      "Error while deleting directory:  [Errno 2] No such file or directory: '/user/smetaj/demo_AD_System/raw_parquet_inference//demo_AD_System'\n",
      "Saving the big guy (window dataframe) in: /user/smetaj/demo_AD_System/raw_parquet_inference//demo_AD_System ..\n",
      "Saved successfully: /user/smetaj/demo_AD_System/raw_parquet_inference//demo_AD_System\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SUCCESS - DATA AGGREGATED IN HDFS.\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n"
     ]
    }
   ],
   "source": [
1036
    "sys.argv = ['', '--resource_file', json_file_inference]\n",
1037
    "DM.transform_data(standalone_mode=False)"
smetaj's avatar
smetaj committed
1038
1039
1040
1041
   ]
  },
  {
   "cell_type": "markdown",
1042
1043
1044
1045
   "id": "sonic-mounting",
   "metadata": {
    "hidden": true
   },
smetaj's avatar
smetaj committed
1046
   "source": [
1047
    "## Copy Locally"
smetaj's avatar
smetaj committed
1048
1049
1050
1051
   ]
  },
  {
   "cell_type": "code",
1052
1053
   "execution_count": 43,
   "id": "desperate-pathology",
smetaj's avatar
smetaj committed
1054
1055
   "metadata": {
    "ExecuteTime": {
1056
1057
1058
1059
1060
     "end_time": "2021-05-03T14:56:27.466547Z",
     "start_time": "2021-05-03T14:55:39.195524Z"
    },
    "hidden": true,
    "scrolled": true
smetaj's avatar
smetaj committed
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "PREPARING SPARK:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SPARK CONTEXT: <SparkContext master=yarn appName=pyspark_shell_swan>\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
1084
      "SPARK OBJECT: <pyspark.sql.session.SparkSession object at 0x7f40a81eda10>\n",
smetaj's avatar
smetaj committed
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "RESOURCE DETAILS: demo_config_train.json\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "{\n",
      "    \"hostgroups\": [\n",
1097
      "        \"cloud_compute/level2/main/gva_shared_017\"\n",
smetaj's avatar
smetaj committed
1098
1099
      "    ],\n",
      "    \"code_project_name\": \"demo_AD_System\",\n",
1100
      "    \"local_cache_folder\": \"/eos/user/s/smetaj/demo_AD_System/local_cache_train/\",\n",
smetaj's avatar
smetaj committed
1101
1102
1103
1104
1105
1106
1107
1108
1109
      "    \"hdfs_out_folder\": \"/user/smetaj/demo_AD_System/raw_parquet_train/\",\n",
      "    \"hdfs_cache_folder\": \"/user/smetaj/demo_AD_System/compressed_train/\",\n",
      "    \"normalization_out_folder\": \"/user/smetaj/demo_AD_System/normalization/\",\n",
      "    \"overwrite_on_hdfs\": true,\n",
      "    \"overwrite_normalization\": true,\n",
      "    \"aggregate_every_n_minutes\": 10,\n",
      "    \"history_steps\": 48,\n",
      "    \"slide_steps\": 1,\n",
      "    \"future_steps\": 0,\n",
1110
1111
1112
1113
      "    \"date_start\": \"2021-03-01\",\n",
      "    \"date_end_excluded\": \"2021-03-20\",\n",
      "    \"date_start_normalization\": \"2021-03-01\",\n",
      "    \"date_end_normalization_excluded\": \"2021-03-20\",\n",
smetaj's avatar
smetaj committed
1114
      "    \"selected_plugins\": {\n",
1115
1116
      "        \"cpu__percent_idle\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cpu\",\n",
1117
      "            \"plugin_filter\": \"type == 'percent' and type_instance == 'idle' and plugin == 'cpu'\"\n",
smetaj's avatar
smetaj committed
1118
      "        },\n",
1119
1120
      "        \"load_longterm\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/load\",\n",
1121
      "            \"plugin_filter\": \"value_instance == 'longterm' and plugin == 'load'\"\n",
smetaj's avatar
smetaj committed
1122
      "        },\n",
1123
1124
      "        \"disk_io_time\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cloud\",\n",
1125
      "            \"plugin_filter\": \"value_instance == 'io_time' and plugin == 'disk'\"\n",
smetaj's avatar
smetaj committed
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
      "        }\n",
      "    }\n",
      "}\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "CACHE NEW DATA:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "ASSUMPTION: no data was in cache before and if anything is there, it will be deleted.\n",
      "Deleting any old remainders...\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "CACHE CREATION\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
1145
      "1614553200\n",
smetaj's avatar
smetaj committed
1146
      "SUCCESS\n",
1147
      "Deleting the raw data saved in /user/smetaj/demo_AD_System/raw_parquet_train/demo_AD_System ...\n",
1148
      "Save the config file locally: /eos/user/s/smetaj/demo_AD_System/local_cache_train/demo_AD_System.metadata\n",
smetaj's avatar
smetaj committed
1149
1150
1151
1152
1153
1154
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SUCCESS - CACHED DATA AVAILABLE LOCALLY\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
      "\n"
     ]
    }
   ],
   "source": [
    "# The final step of the ETL procedure is to save the HDFS downloaded \n",
    "# files into EOS, in this way the data are easier to be accessed and used.\n",
    "\n",
    "# As always we must do the same for both the datasets.\n",
    "\n",
    "sys.argv = ['', '--resource_file', json_file_train]\n",
1166
    "DM.copy_locally(standalone_mode=False)"
1167
1168
1169
1170
   ]
  },
  {
   "cell_type": "code",
1171
1172
   "execution_count": 44,
   "id": "formal-enterprise",
1173
1174
   "metadata": {
    "ExecuteTime": {
1175
1176
1177
1178
     "end_time": "2021-05-03T14:56:42.692287Z",
     "start_time": "2021-05-03T14:56:27.529326Z"
    },
    "hidden": true
1179
1180
1181
1182
1183
1184
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
smetaj's avatar
smetaj committed
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "PREPARING SPARK:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SPARK CONTEXT: <SparkContext master=yarn appName=pyspark_shell_swan>\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
1202
      "SPARK OBJECT: <pyspark.sql.session.SparkSession object at 0x7f40abc32d90>\n",
smetaj's avatar
smetaj committed
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "RESOURCE DETAILS: demo_config_inference.json\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "{\n",
      "    \"hostgroups\": [\n",
1215
      "        \"cloud_compute/level2/main/gva_shared_017\"\n",
smetaj's avatar
smetaj committed
1216
1217
      "    ],\n",
      "    \"code_project_name\": \"demo_AD_System\",\n",
1218
      "    \"local_cache_folder\": \"/eos/user/s/smetaj/demo_AD_System/local_cache_inference/\",\n",
smetaj's avatar
smetaj committed
1219
1220
1221
1222
1223
1224
1225
1226
1227
      "    \"hdfs_out_folder\": \"/user/smetaj/demo_AD_System/raw_parquet_inference/\",\n",
      "    \"hdfs_cache_folder\": \"/user/smetaj/demo_AD_System/compressed_inference/\",\n",
      "    \"normalization_out_folder\": \"/user/smetaj/demo_AD_System/normalization/\",\n",
      "    \"overwrite_on_hdfs\": true,\n",
      "    \"overwrite_normalization\": true,\n",
      "    \"aggregate_every_n_minutes\": 10,\n",
      "    \"history_steps\": 48,\n",
      "    \"slide_steps\": 48,\n",
      "    \"future_steps\": 0,\n",
1228
1229
1230
1231
      "    \"date_start\": \"2021-03-20\",\n",
      "    \"date_end_excluded\": \"2021-04-20\",\n",
      "    \"date_start_normalization\": \"2021-03-01\",\n",
      "    \"date_end_normalization_excluded\": \"2021-03-20\",\n",
smetaj's avatar
smetaj committed
1232
      "    \"selected_plugins\": {\n",
1233
1234
      "        \"cpu__percent_idle\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cpu\",\n",
1235
      "            \"plugin_filter\": \"type == 'percent' and type_instance == 'idle' and plugin == 'cpu'\"\n",
smetaj's avatar
smetaj committed
1236
      "        },\n",
1237
1238
      "        \"load_longterm\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/load\",\n",
1239
      "            \"plugin_filter\": \"value_instance == 'longterm' and plugin == 'load'\"\n",
smetaj's avatar
smetaj committed
1240
      "        },\n",
1241
1242
      "        \"disk_io_time\": {\n",
      "            \"plugin_data_path\": \"/project/monitoring/collectd/cloud\",\n",
1243
      "            \"plugin_filter\": \"value_instance == 'io_time' and plugin == 'disk'\"\n",
smetaj's avatar
smetaj committed
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
      "        }\n",
      "    }\n",
      "}\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "CACHE NEW DATA:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "ASSUMPTION: no data was in cache before and if anything is there, it will be deleted.\n",
      "Deleting any old remainders...\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "CACHE CREATION\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
1263
      "1616194800\n",
smetaj's avatar
smetaj committed
1264
      "SUCCESS\n",
1265
      "Deleting the raw data saved in /user/smetaj/demo_AD_System/raw_parquet_inference/demo_AD_System ...\n",
1266
      "Save the config file locally: /eos/user/s/smetaj/demo_AD_System/local_cache_inference/demo_AD_System.metadata\n",
smetaj's avatar
smetaj committed
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SUCCESS - CACHED DATA AVAILABLE LOCALLY\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n"
     ]
    }
   ],
   "source": [
1278
    "sys.argv = ['', '--resource_file', json_file_inference]\n",
1279
    "DM.copy_locally(standalone_mode=False)"
smetaj's avatar
smetaj committed
1280
1281
1282
1283
   ]
  },
  {
   "cell_type": "markdown",
1284
1285
1286
1287
   "id": "frank-viking",
   "metadata": {
    "heading_collapsed": true
   },
smetaj's avatar
smetaj committed
1288
   "source": [
1289
    "# Visualization of downloaded time series"
smetaj's avatar
smetaj committed
1290
1291
1292
1293
   ]
  },
  {
   "cell_type": "markdown",
1294
1295
1296
1297
   "id": "decreased-conflict",
   "metadata": {
    "hidden": true
   },
smetaj's avatar
smetaj committed
1298
   "source": [
1299
    "## Reading time series with pandas and host definition"
smetaj's avatar
smetaj committed
1300
1301
1302
1303
   ]
  },
  {
   "cell_type": "code",
1304
1305
   "execution_count": 45,
   "id": "nonprofit-dragon",
smetaj's avatar
smetaj committed
1306
1307
   "metadata": {
    "ExecuteTime": {
1308
1309
1310
1311
     "end_time": "2021-05-03T14:56:46.529305Z",
     "start_time": "2021-05-03T14:56:42.699288Z"
    },
    "hidden": true
smetaj's avatar
smetaj committed
1312
1313
1314
   },
   "outputs": [],
   "source": [
1315
    "# Now we have downloaded the data. \n",
1316
    "# We also want some tools to visualize the time series.\n",
1317
    "\n",
smetaj's avatar
smetaj committed
1318
    "# in local_path we have our data saved in EOS\n",
1319
1320
    "local_path_train = json_data[\"local_cache_folder\"] + 'train/' + json_data[\"code_project_name\"]\n",
    "local_path_inference = json_data[\"local_cache_folder\"] + 'inference/' + json_data[\"code_project_name\"]\n",
smetaj's avatar
smetaj committed
1321
1322
1323
1324
1325
    "\n",
    "# nr_timeseries will be equal to the number of plugins that we have downloaded\n",
    "nr_timeseries = len(json_data[\"selected_plugins\"])\n",
    "\n",
    "# finally df will be the pandas dataframe containing the data\n",
1326
1327
1328
    "# (it is eaisier to print them with pandas)\n",
    "df_train = pd.read_parquet(local_path_train)\n",
    "df_inference = pd.read_parquet(local_path_inference)"
smetaj's avatar
smetaj committed
1329
1330
1331
1332
   ]
  },
  {
   "cell_type": "code",
1333
1334
   "execution_count": 46,
   "id": "operating-running",
smetaj's avatar
smetaj committed
1335
1336
   "metadata": {
    "ExecuteTime": {
1337
1338
1339
1340
     "end_time": "2021-05-03T14:56:46.579295Z",
     "start_time": "2021-05-03T14:56:46.533965Z"
    },
    "hidden": true
smetaj's avatar
smetaj committed
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>hostname</th>\n",
       "      <th>hostgroup</th>\n",
1367
1368
1369
1370
1371
1372
1373
       "      <th>cpu__percent_idle_h0</th>\n",
       "      <th>cpu__percent_idle_h1</th>\n",
       "      <th>cpu__percent_idle_h2</th>\n",
       "      <th>cpu__percent_idle_h3</th>\n",
       "      <th>cpu__percent_idle_h4</th>\n",
       "      <th>cpu__percent_idle_h5</th>\n",
       "      <th>cpu__percent_idle_h6</th>\n",
smetaj's avatar
smetaj committed
1374
       "      <th>...</th>\n",
1375
1376
1377
1378
1379
1380
1381
1382
1383
       "      <th>load_longterm_h39</th>\n",
       "      <th>load_longterm_h40</th>\n",
       "      <th>load_longterm_h41</th>\n",
       "      <th>load_longterm_h42</th>\n",
       "      <th>load_longterm_h43</th>\n",
       "      <th>load_longterm_h44</th>\n",
       "      <th>load_longterm_h45</th>\n",
       "      <th>load_longterm_h46</th>\n",
       "      <th>load_longterm_h47</th>\n",
smetaj's avatar
smetaj committed
1384
1385
1386
1387
1388
1389
       "      <th>ts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
1390
1391
       "      <td>1617289200</td>\n",
       "      <td>p06428644w55120.cern.ch</td>\n",
1392
       "      <td>cloud_compute/level2/main/gva_shared_017</td>\n",
1393
1394
1395
1396
1397
1398
1399
       "      <td>0.236088</td>\n",
       "      <td>0.227848</td>\n",
       "      <td>0.243771</td>\n",
       "      <td>0.223976</td>\n",
       "      <td>0.198013</td>\n",
       "      <td>0.207111</td>\n",
       "      <td>0.193086</td>\n",
smetaj's avatar
smetaj committed
1400
       "      <td>...</td>\n",
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
       "      <td>-0.441156</td>\n",
       "      <td>-0.387925</td>\n",
       "      <td>-0.323980</td>\n",
       "      <td>-0.426701</td>\n",
       "      <td>-0.444898</td>\n",
       "      <td>-0.464626</td>\n",
       "      <td>-0.497619</td>\n",
       "      <td>-0.472619</td>\n",
       "      <td>-0.382993</td>\n",
       "      <td>2021-04-01 17:00:00</td>\n",
smetaj's avatar
smetaj committed
1411
1412
1413
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
1414
1415
       "      <td>1616770800</td>\n",
       "      <td>p06492044x27120.cern.ch</td>\n",
1416
       "      <td>cloud_compute/level2/main/gva_shared_017</td>\n",
1417
1418
1419
1420
1421
1422
1423
       "      <td>-0.607309</td>\n",
       "      <td>-0.593825</td>\n",
       "      <td>-0.539714</td>\n",
       "      <td>-0.609813</td>\n",
       "      <td>-0.832071</td>\n",
       "      <td>-0.663781</td>\n",
       "      <td>-0.510553</td>\n",
smetaj's avatar
smetaj committed
1424
       "      <td>...</td>\n",
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
       "      <td>1.719558</td>\n",
       "      <td>1.712075</td>\n",
       "      <td>1.800340</td>\n",
       "      <td>1.461054</td>\n",
       "      <td>1.266837</td>\n",
       "      <td>0.829422</td>\n",
       "      <td>0.421259</td>\n",
       "      <td>0.274320</td>\n",
       "      <td>0.477721</td>\n",
       "      <td>2021-03-26 16:00:00</td>\n",
smetaj's avatar
smetaj committed
1435
1436
1437
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
1438
1439
       "      <td>1617836400</td>\n",
       "      <td>p06428644r12066.cern.ch</td>\n",
1440
       "      <td>cloud_compute/level2/main/gva_shared_017</td>\n",
1441
1442
1443
1444
1445
1446
1447
       "      <td>-2.064705</td>\n",
       "      <td>-1.436896</td>\n",
       "      <td>-0.930914</td>\n",
       "      <td>-1.901045</td>\n",
       "      <td>-0.657402</td>\n",
       "      <td>-0.541086</td>\n",
       "      <td>-0.013392</td>\n",
smetaj's avatar
smetaj committed
1448
       "      <td>...</td>\n",
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
       "      <td>-0.697704</td>\n",
       "      <td>-0.810091</td>\n",
       "      <td>-0.843537</td>\n",
       "      <td>-0.904762</td>\n",
       "      <td>-0.924320</td>\n",
       "      <td>-0.895408</td>\n",
       "      <td>-0.839002</td>\n",
       "      <td>-0.762755</td>\n",
       "      <td>-0.623639</td>\n",
       "      <td>2021-04-08 01:00:00</td>\n",
smetaj's avatar
smetaj committed
1459
1460
1461
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
1462
       "<p>3 rows × 148 columns</p>\n",
smetaj's avatar
smetaj committed
1463
1464
1465
1466
       "</div>"
      ],
      "text/plain": [
       "    timestamp                 hostname  \\\n",
1467
1468
1469
       "0  1617289200  p06428644w55120.cern.ch   \n",
       "1  1616770800  p06492044x27120.cern.ch   \n",
       "2  1617836400  p06428644r12066.cern.ch   \n",
smetaj's avatar
smetaj committed
1470
       "\n",
1471
       "                                  hostgroup  cpu__percent_idle_h0  \\\n",
1472
1473
1474
       "0  cloud_compute/level2/main/gva_shared_017              0.236088   \n",
       "1  cloud_compute/level2/main/gva_shared_017             -0.607309   \n",
       "2  cloud_compute/level2/main/gva_shared_017             -2.064705   \n",
smetaj's avatar
smetaj committed
1475
       "\n",
1476
       "   cpu__percent_idle_h1  cpu__percent_idle_h2  cpu__percent_idle_h3  \\\n",
1477
1478
1479
       "0              0.227848              0.243771              0.223976   \n",
       "1             -0.593825             -0.539714             -0.609813   \n",
       "2             -1.436896             -0.930914             -1.901045   \n",
smetaj's avatar
smetaj committed
1480
       "\n",
1481
       "   cpu__percent_idle_h4  cpu__percent_idle_h5  cpu__percent_idle_h6  ...  \\\n",
1482
1483
1484
       "0              0.198013              0.207111              0.193086  ...   \n",
       "1             -0.832071             -0.663781             -0.510553  ...   \n",
       "2             -0.657402             -0.541086             -0.013392  ...   \n",
smetaj's avatar
smetaj committed
1485
       "\n",
1486
       "   load_longterm_h39  load_longterm_h40  load_longterm_h41  load_longterm_h42  \\\n",
1487
1488
1489
       "0          -0.441156          -0.387925          -0.323980          -0.426701   \n",
       "1           1.719558           1.712075           1.800340           1.461054   \n",
       "2          -0.697704          -0.810091          -0.843537          -0.904762   \n",
smetaj's avatar
smetaj committed
1490
       "\n",
1491
       "   load_longterm_h43  load_longterm_h44  load_longterm_h45  load_longterm_h46  \\\n",
1492
1493
1494
       "0          -0.444898          -0.464626          -0.497619          -0.472619   \n",
       "1           1.266837           0.829422           0.421259           0.274320   \n",
       "2          -0.924320          -0.895408          -0.839002          -0.762755   \n",
smetaj's avatar
smetaj committed
1495
       "\n",
1496
       "   load_longterm_h47                   ts  \n",
1497
1498
1499
       "0          -0.382993  2021-04-01 17:00:00  \n",
       "1           0.477721  2021-03-26 16:00:00  \n",
       "2          -0.623639  2021-04-08 01:00:00  \n",
smetaj's avatar
smetaj committed
1500
       "\n",
1501
       "[3 rows x 148 columns]"
smetaj's avatar
smetaj committed
1502
1503
      ]
     },
1504
     "execution_count": 46,
smetaj's avatar
smetaj committed
1505
1506
1507
1508
1509
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
1510
1511
    "# Note that each row of df will be a window of data following the granularity definition in the configuration file. \n",
    "# In this example it consists of 48 points representing 8 hours of time interval with an aggregation of 10 minutes.\n",
smetaj's avatar
smetaj committed
1512
1513
1514
    "# So for every day, for every hostname, we will have 3 rows (3 x 8hours = 24),\n",
    "# each row will be composed by timestamp, hostname, hostgroup, ts and\n",
    "# for each plugin we will have 48 columns, 1 for each 10 minutes.\n",
1515
    "df_inference.head(3)"
smetaj's avatar
smetaj committed
1516
1517
1518
1519
   ]
  },
  {
   "cell_type": "code",
1520
1521
   "execution_count": 47,
   "id": "refined-chester",
smetaj's avatar
smetaj committed
1522
1523
   "metadata": {
    "ExecuteTime": {
1524
1525
1526
1527
     "end_time": "2021-05-03T14:56:46.589975Z",
     "start_time": "2021-05-03T14:56:46.582582Z"
    },
    "hidden": true
smetaj's avatar
smetaj committed
1528
1529
1530
1531
1532
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
1533
1534
1535
1536
1537
       "['p06428644y58212.cern.ch',\n",
       " 'p06428644w00836.cern.ch',\n",
       " 'p06428644y16173.cern.ch',\n",
       " 'p06428644u33510.cern.ch',\n",
       " 'p06428644w45688.cern.ch']"
smetaj's avatar
smetaj committed
1538
1539
      ]
     },
1540
     "execution_count": 47,
smetaj's avatar
smetaj committed
1541
1542
1543
1544
1545
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
1546
1547
    "# We want to visualize the data about 1 host in particular \n",
    "# (let's print 5 random hosts we have in our pandas dataframe).\n",
1548
    "\n",
1549
    "hostnames_in_df = list(set(list(df_inference['hostname'])))\n",
smetaj's avatar
smetaj committed
1550
1551
1552
1553
1554
    "hostnames_in_df[:5]"
   ]
  },
  {
   "cell_type": "code",
1555
1556
   "execution_count": 48,
   "id": "mental-norfolk",
smetaj's avatar
smetaj committed
1557
1558
   "metadata": {
    "ExecuteTime": {
1559
1560
1561
1562
     "end_time": "2021-05-03T14:56:46.595739Z",
     "start_time": "2021-05-03T14:56:46.592808Z"
    },
    "hidden": true
smetaj's avatar
smetaj committed
1563
1564
1565
   },
   "outputs": [],
   "source": [
1566
1567
1568
1569
    "# From previous studies we know that in this specific hostgroup there is a\n",
    "# particular host that was anomalous in the specific period of time we are\n",
    "# studying, so let's initizialize the host_to_viz variable.\n",
    "\n",
1570
    "host_to_viz = 'p06428644y10205.cern.ch'  "
smetaj's avatar
smetaj committed
1571
1572
1573
1574
   ]
  },
  {
   "cell_type": "markdown",
1575
1576
1577
1578
   "id": "found-effectiveness",
   "metadata": {
    "hidden": true
   },
smetaj's avatar
smetaj committed
1579
   "source": [
1580
    "## Reconstruction function"
smetaj's avatar
smetaj committed
1581
1582
1583
1584
   ]
  },
  {
   "cell_type": "code",
1585
1586
   "execution_count": 49,
   "id": "continuous-transition",
smetaj's avatar
smetaj committed
1587
1588
   "metadata": {
    "ExecuteTime": {