Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mentat-test
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
713
Mentat
mentat-test
Commits
48081ff3
Commit
48081ff3
authored
7 years ago
by
Jan Mach
Browse files
Options
Downloads
Patches
Plain Diff
Updated documentation for mentat-statistician.py module.
(Redmine issue:
#3379
,
#3361
)
parent
d9d68e0f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/sphinx/_doclib/bin_mentat-statistician.rst
+1
-1
1 addition, 1 deletion
doc/sphinx/_doclib/bin_mentat-statistician.rst
lib/mentat/module/statistician.py
+43
-23
43 additions, 23 deletions
lib/mentat/module/statistician.py
with
44 additions
and
24 deletions
doc/sphinx/_doclib/bin_mentat-statistician.rst
+
1
−
1
View file @
48081ff3
...
@@ -6,4 +6,4 @@ mentat-statistician.py
...
@@ -6,4 +6,4 @@ mentat-statistician.py
.. automodule:: mentat.module.statistician
.. automodule:: mentat.module.statistician
.. include:: _inc_bin.help.
script
.rst
.. include:: _inc_bin.help.
fetcher
.rst
This diff is collapsed.
Click to expand it.
lib/mentat/module/statistician.py
+
43
−
23
View file @
48081ff3
...
@@ -259,8 +259,6 @@ class MentatStatisticianScript(mentat.script.fetcher.FetcherScript):
...
@@ -259,8 +259,6 @@ class MentatStatisticianScript(mentat.script.fetcher.FetcherScript):
"""
"""
result
=
{}
result
=
{}
#self.logger.warning("Running in simulation mode, no data will be actually removed")
(
time_low
,
time_high
)
=
self
.
calculate_interval_thresholds
(
(
time_low
,
time_high
)
=
self
.
calculate_interval_thresholds
(
time_high
=
self
.
c
(
self
.
CONFIG_TIME_HIGH
),
time_high
=
self
.
c
(
self
.
CONFIG_TIME_HIGH
),
interval
=
self
.
c
(
self
.
CONFIG_INTERVAL
),
interval
=
self
.
c
(
self
.
CONFIG_INTERVAL
),
...
@@ -294,15 +292,21 @@ class MentatStatisticianScript(mentat.script.fetcher.FetcherScript):
...
@@ -294,15 +292,21 @@ class MentatStatisticianScript(mentat.script.fetcher.FetcherScript):
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
def
_update_rrds
(
self
,
result
,
tstamp
):
def
_update_rrds
(
self
,
stats
,
tstamp
):
"""
"""
Update add RRD database files with given statistics and timestamp.
:param dict stats: Calculated message statistics.
:param datetime.datetime tstamp: Update timestamp.
"""
"""
stats
=
result
[
mentat
.
stats
.
idea
.
ST_OVERALL
]
# We are interested only in overall statistics.
stats_oa
=
stats
[
mentat
.
stats
.
idea
.
ST_OVERALL
]
utstamp
=
int
(
tstamp
.
timestamp
())
utstamp
=
int
(
tstamp
.
timestamp
())
if
not
stats
[
'
cnt_alerts
'
]
>
0
:
# In case there are no messages at all update all existing databases with
# value '0'
if
not
stats_oa
[
'
cnt_alerts
'
]
>
0
:
self
.
_rrd_update_all
(
tstamp
)
self
.
_rrd_update_all
(
tstamp
)
return
return
...
@@ -314,7 +318,7 @@ class MentatStatisticianScript(mentat.script.fetcher.FetcherScript):
...
@@ -314,7 +318,7 @@ class MentatStatisticianScript(mentat.script.fetcher.FetcherScript):
total
=
0
total
=
0
updated
=
{}
updated
=
{}
for
(
stat_key
,
stat_value
)
in
stats
[
itm
[
1
]].
items
():
for
(
stat_key
,
stat_value
)
in
stats
_oa
[
itm
[
1
]].
items
():
try
:
try
:
db_name
=
self
.
stats_rrd
.
clean
(
stat_key
)
db_name
=
self
.
stats_rrd
.
clean
(
stat_key
)
...
@@ -347,7 +351,9 @@ class MentatStatisticianScript(mentat.script.fetcher.FetcherScript):
...
@@ -347,7 +351,9 @@ class MentatStatisticianScript(mentat.script.fetcher.FetcherScript):
def
_generate_charts
(
self
,
tstamp
):
def
_generate_charts
(
self
,
tstamp
):
"""
"""
Generate charts and export files.
:param datetime.datetime tstamp: Update timestamp.
"""
"""
utstamp
=
int
(
tstamp
.
timestamp
())
utstamp
=
int
(
tstamp
.
timestamp
())
...
@@ -355,9 +361,35 @@ class MentatStatisticianScript(mentat.script.fetcher.FetcherScript):
...
@@ -355,9 +361,35 @@ class MentatStatisticianScript(mentat.script.fetcher.FetcherScript):
self
.
runlog
[
'
generated_files
'
]
=
result
self
.
runlog
[
'
generated_files
'
]
=
result
def
_update_db
(
self
,
stats
):
"""
Store given message statistics into database.
:param dict stats: Message statistics to store.
"""
stats
[
'
ts
'
]
=
int
(
time
.
time
())
try
:
db_id
=
self
.
collection_stats
.
insert
(
stats
)
self
.
logger
.
info
(
"
Stored statistics log to database document
'
%s
'"
,
db_id
)
stats
[
'
flag_stored
'
]
=
True
stats
[
'
db_id
'
]
=
db_id
except
Exception
as
exc
:
self
.
logger
.
error
(
str
(
exc
))
return
stats
#---------------------------------------------------------------------------
def
_rrd_update_all
(
self
,
tstamp
,
value
=
0
):
def
_rrd_update_all
(
self
,
tstamp
,
value
=
0
):
"""
"""
Update all RRD database files with given timestamp and the same value, ``0``
by default. This method is usefull in case there were no messages in given
time interval and the statistics are empty.
:param datetime.datetime tstamp: Update timestamp.
"""
"""
utstamp
=
int
(
tstamp
.
timestamp
())
utstamp
=
int
(
tstamp
.
timestamp
())
self
.
logger
.
info
(
"
Updating all existing RRD DBs with default value
'
%d
'
and timestamp
'
%s
'
:
'
%d
'"
,
value
,
str
(
tstamp
),
utstamp
)
self
.
logger
.
info
(
"
Updating all existing RRD DBs with default value
'
%d
'
and timestamp
'
%s
'
:
'
%d
'"
,
value
,
str
(
tstamp
),
utstamp
)
...
@@ -365,27 +397,15 @@ class MentatStatisticianScript(mentat.script.fetcher.FetcherScript):
...
@@ -365,27 +397,15 @@ class MentatStatisticianScript(mentat.script.fetcher.FetcherScript):
def
_rrd_update_database
(
self
,
db_type
,
db_name
,
tstamp
,
value
):
def
_rrd_update_database
(
self
,
db_type
,
db_name
,
tstamp
,
value
):
"""
"""
Update given RRD database with given timestamp and value.
:param str db_type: Type part of the database identifier.
:param str db_name: Name part of the database identifier.
:param datetime.datetime tstamp: Update timestamp.
:param int value: Update value.
"""
"""
db_id
=
'
{}.{}
'
.
format
(
db_type
,
self
.
stats_rrd
.
clean
(
db_name
))
db_id
=
'
{}.{}
'
.
format
(
db_type
,
self
.
stats_rrd
.
clean
(
db_name
))
utstamp
=
int
(
tstamp
.
timestamp
())
utstamp
=
int
(
tstamp
.
timestamp
())
self
.
logger
.
info
(
"
Updating RRD DB
'
%s
'
with value
'
%d
'
and timestamp
'
%s
'
:
'
%d
'"
,
db_id
,
value
,
str
(
tstamp
),
utstamp
)
self
.
logger
.
info
(
"
Updating RRD DB
'
%s
'
with value
'
%d
'
and timestamp
'
%s
'
:
'
%d
'"
,
db_id
,
value
,
str
(
tstamp
),
utstamp
)
(
rrddb
,
flag_new
)
=
self
.
stats_rrd
.
update
(
db_id
,
value
,
tst
=
utstamp
)
(
rrddb
,
flag_new
)
=
self
.
stats_rrd
.
update
(
db_id
,
value
,
tst
=
utstamp
)
return
(
rrddb
,
flag_new
)
return
(
rrddb
,
flag_new
)
def
_update_db
(
self
,
stats
):
"""
"""
stats
[
'
ts
'
]
=
int
(
time
.
time
())
try
:
db_id
=
self
.
collection_stats
.
insert
(
stats
)
self
.
logger
.
info
(
"
Stored statistics log to database document
'
%s
'"
,
db_id
)
stats
[
'
flag_stored
'
]
=
True
stats
[
'
db_id
'
]
=
db_id
except
Exception
as
exc
:
self
.
logger
.
error
(
str
(
exc
))
return
stats
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment