Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rafael Monnerat
slapos.toolbox
Commits
c1673418
Commit
c1673418
authored
Apr 06, 2017
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
monitor: Automatic build statistics on promise hisotry for archive.
parent
82cf4505
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
1 deletion
+64
-1
setup.py
setup.py
+1
-0
slapos/monitor/build_statistic.py
slapos/monitor/build_statistic.py
+59
-0
slapos/monitor/monitor.py
slapos/monitor/monitor.py
+4
-1
No files found.
setup.py
View file @
c1673418
...
...
@@ -86,6 +86,7 @@ setup(name=name,
'killpidfromfile = slapos.systool:killpidfromfile'
,
# BBB
'monitor.bootstrap = slapos.monitor.monitor:main'
,
'monitor.collect = slapos.monitor.collect:main'
,
'monitor.statistic = slapos.monitor.build_statistic:main'
,
'monitor.runpromise = slapos.monitor.runpromise:main'
,
'monitor.genstatus = slapos.monitor.globalstate:main'
,
'monitor.configwrite = slapos.monitor.monitor_config_write:main'
,
...
...
slapos/monitor/build_statistic.py
0 → 100644
View file @
c1673418
import
json
import
sys
import
glob
import
time
import
os
import
argparse
def
parseArguments
():
"""
Parse arguments for monitor statistics.
"""
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--history_folder'
,
help
=
'Path where history files are located and where stats will be generated.'
)
return
parser
def
buildStatistic
(
history_folder
):
for
p
in
glob
.
glob
(
"%s/*.history.json"
%
history_folder
):
result
=
{}
stats_list
=
[]
promise_name
=
p
.
split
(
"/"
)[
-
1
].
replace
(
".history.json"
,
""
)
with
open
(
p
)
as
f
:
j
=
json
.
load
(
f
)
for
entry
in
j
[
'data'
]:
day
=
entry
[
"start-date"
].
split
(
" "
)[
0
]
result
.
setdefault
(
day
,
{
"ERROR"
:
0
,
"OK"
:
0
})
result
[
day
][
str
(
entry
[
"status"
])]
+=
1
f
.
close
()
for
date
,
stat
in
result
.
iteritems
():
stats_list
.
append
(
{
"status"
:
"ERROR"
if
stat
[
"ERROR"
]
>
0
else
"OK"
,
"change-time"
:
0
,
"start-date"
:
"%s 00:00:00"
%
date
,
"message"
:
stat
})
stat_file_path
=
p
.
replace
(
".history.json"
,
".stats.json"
)
if
os
.
path
.
exists
(
stat_file_path
):
with
open
(
stat_file_path
)
as
f
:
stats_dict
=
json
.
load
(
f
)
f
.
close
()
else
:
stats_dict
=
{
"date"
:
time
.
time
(),
"data"
:
[]}
stats_dict
[
"data"
].
extend
(
stats_list
)
with
open
(
stat_file_path
,
"w+"
)
as
f
:
f
.
write
(
json
.
dumps
(
stats_dict
))
f
.
truncate
()
f
.
close
()
def
main
():
arg_parser
=
parseArguments
()
config
=
arg_parser
.
parse_args
()
buildStatistic
(
config
.
history_folder
)
sys
.
exit
(
0
)
slapos/monitor/monitor.py
View file @
c1673418
...
...
@@ -80,6 +80,7 @@ class Monitoring(object):
self
.
private_folder
=
config
.
get
(
"monitor"
,
"private-folder"
)
self
.
collector_db
=
config
.
get
(
"monitor"
,
"collector-db"
)
self
.
collect_script
=
config
.
get
(
"monitor"
,
"collect-script"
)
self
.
statistic_script
=
config
.
get
(
"monitor"
,
"statistic-script"
)
self
.
webdav_folder
=
config
.
get
(
"monitor"
,
"webdav-folder"
)
self
.
report_script_folder
=
config
.
get
(
"monitor"
,
"report-folder"
)
self
.
webdav_url
=
'%s/share'
%
config
.
get
(
"monitor"
,
"base-url"
)
...
...
@@ -495,7 +496,9 @@ class Monitoring(object):
# Rotate public history status file, delete data of previous days
option_list
=
[
'daily'
,
'nocreate'
,
'rotate 0'
,
'nocompress'
,
'notifempty'
'nocompress'
,
'notifempty'
,
'prerotate'
,
' %s --history_folder %s'
%
(
self
.
statistic_script
,
self
.
public_folder
),
'endscript'
]
file_list
=
[
"%s/*.history.json"
%
self
.
public_folder
]
self
.
generateLogrotateEntry
(
'monitor.service.status'
,
file_list
,
option_list
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment