Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apachedex
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
apachedex
Commits
31723edb
Commit
31723edb
authored
Apr 05, 2013
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move graph-related code to top level functions for reuse.
parent
fdb023e7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
67 deletions
+85
-67
apachedex/__init__.py
apachedex/__init__.py
+85
-67
No files found.
apachedex/__init__.py
View file @
31723edb
...
@@ -126,6 +126,77 @@ def getApdexTableHeader(overall=False):
...
@@ -126,6 +126,77 @@ def getApdexTableHeader(overall=False):
return
'<th>apdex</th><th>hits</th><th>avg (s)</th>'
\
return
'<th>apdex</th><th>hits</th><th>avg (s)</th>'
\
'<th%s>max (s)</th>'
%
extra
'<th%s>max (s)</th>'
%
extra
def
getDataPoints
(
apdex_dict
):
return
[
(
date
,
apdex
.
getApdex
()
*
100
,
apdex
.
hit
)
for
date
,
apdex
in
sorted
(
apdex_dict
.
iteritems
(),
key
=
ITEMGETTER0
)]
def
prepareDataForGraph
(
daily_data
,
date_format
,
placeholder_delta
):
current_date
=
datetime
.
strptime
(
daily_data
[
0
][
0
],
date_format
)
new_daily_data
=
[]
append
=
new_daily_data
.
append
for
measure
in
daily_data
:
measure_date
=
datetime
.
strptime
(
measure
[
0
],
date_format
)
while
current_date
<
measure_date
:
append
((
current_date
.
strftime
(
date_format
),
100
,
0
))
current_date
+=
placeholder_delta
append
(
measure
)
current_date
=
measure_date
+
placeholder_delta
return
new_daily_data
def
graphPair
(
daily_data
,
date_format
,
graph_period
):
date_list
=
[
int
(
time
.
mktime
(
time
.
strptime
(
x
[
0
],
date_format
))
*
1000
)
for
x
in
daily_data
]
timeformat
=
'%Y<br/>%m/%d<br/>%H:%M'
# There is room for about 10 labels on the X axis.
minTickSize
=
(
max
(
1
,
(
date_list
[
-
1
]
-
date_list
[
0
])
/
(
60
*
60
*
1000
*
10
)),
'hour'
)
# Guesstimation: 6px per digit. If only em were allowed...
yLabelWidth
=
max
(
int
(
math
.
log10
(
max
(
x
[
2
]
for
x
in
daily_data
)))
+
1
,
3
)
*
6
return
graph
(
'apdex'
,
[
zip
(
date_list
,
(
x
[
1
]
for
x
in
daily_data
))],
{
'xaxis'
:
{
'mode'
:
'time'
,
'timeformat'
:
timeformat
,
'minTickSize'
:
minTickSize
,
},
'yaxis'
:
{
'max'
:
100
,
'axisLabel'
:
'%'
,
'labelWidth'
:
yLabelWidth
,
},
'lines'
:
{
'show'
:
True
},
},
)
+
graph
(
'Hits (per %s)'
%
graph_period
,
[
zip
(
date_list
,
(
x
[
2
]
for
x
in
daily_data
))],
{
'xaxis'
:
{
'mode'
:
'time'
,
'timeformat'
:
timeformat
,
'minTickSize'
:
minTickSize
,
},
'yaxis'
:
{
'axisLabel'
:
'Hits'
,
'labelWidth'
:
yLabelWidth
,
'tickDecimals'
:
0
,
},
'lines'
:
{
'show'
:
True
},
},
)
def
graph
(
title
,
data
,
options
=
{}):
result
=
[]
append
=
result
.
append
append
(
'<h2>%s</h2><div class="graph" '
'style="width:600px;height:300px" data-points="'
%
title
)
append
(
escape
(
json
.
dumps
(
data
),
quote
=
True
))
append
(
'" data-options="'
)
append
(
escape
(
json
.
dumps
(
options
),
quote
=
True
))
append
(
'"></div>'
)
return
''
.
join
(
result
)
class
APDEXStats
(
object
):
class
APDEXStats
(
object
):
def
__init__
(
self
,
threshold
,
getDuration
):
def
__init__
(
self
,
threshold
,
getDuration
):
threshold
*=
US_PER_S
threshold
*=
US_PER_S
...
@@ -196,9 +267,7 @@ class GenericSiteStats(object):
...
@@ -196,9 +267,7 @@ class GenericSiteStats(object):
self
.
error_url_count
[
status
][
url
].
append
(
match
.
group
(
'referer'
))
self
.
error_url_count
[
status
][
url
].
append
(
match
.
group
(
'referer'
))
def
getApdexData
(
self
):
def
getApdexData
(
self
):
return
[
return
getDataPoints
(
self
.
apdex
)
(
date
,
apdex
.
getApdex
()
*
100
,
apdex
.
hit
)
for
date
,
apdex
in
sorted
(
self
.
apdex
.
iteritems
(),
key
=
ITEMGETTER0
)]
def
asHTML
(
self
,
stat_filter
=
lambda
x
:
x
):
def
asHTML
(
self
,
stat_filter
=
lambda
x
:
x
):
result
=
[]
result
=
[]
...
@@ -670,72 +739,21 @@ def main():
...
@@ -670,72 +739,21 @@ def main():
for
date
,
hit
in
sorted
(
hit_per_day
.
iteritems
(),
key
=
ITEMGETTER0
):
for
date
,
hit
in
sorted
(
hit_per_day
.
iteritems
(),
key
=
ITEMGETTER0
):
out
.
write
(
'<tr><td>%s</td><td>%s</td></tr>'
%
(
date
,
hit
))
out
.
write
(
'<tr><td>%s</td><td>%s</td></tr>'
%
(
date
,
hit
))
out
.
write
(
'</table>'
)
out
.
write
(
'</table>'
)
def
graph
(
title
,
data
,
options
=
{}):
result
=
[]
append
=
result
.
append
append
(
'<h2>%s</h2><div class="graph" '
'style="width:600px;height:300px" data-points="'
%
title
)
append
(
escape
(
json
.
dumps
(
data
),
quote
=
True
))
append
(
'" data-options="'
)
append
(
escape
(
json
.
dumps
(
options
),
quote
=
True
))
append
(
'"></div>'
)
return
''
.
join
(
result
)
for
site_id
,
data
in
per_site
.
iteritems
():
for
site_id
,
data
in
per_site
.
iteritems
():
out
.
write
(
'<h1>Site: %s</h1>'
%
site_id
)
out
.
write
(
'<h1>Site: %s</h1>'
%
site_id
)
daily_data
=
data
.
getApdexData
()
out
.
write
(
current_date
=
datetime
.
strptime
(
daily_data
[
0
][
0
],
date_format
)
graphPair
(
new_daily_data
=
[]
prepareDataForGraph
(
append
=
new_daily_data
.
append
data
.
getApdexData
(),
for
measure
in
daily_data
:
date_format
,
measure_date
=
datetime
.
strptime
(
measure
[
0
],
date_format
)
placeholder_delta
,
while
current_date
<
measure_date
:
),
append
((
current_date
.
strftime
(
date_format
),
100
,
0
))
date_format
,
current_date
+=
placeholder_delta
graph_period
,
append
(
measure
)
)
current_date
=
measure_date
+
placeholder_delta
)
daily_data
=
new_daily_data
out
.
write
(
data
.
asHTML
(
date_format
,
placeholder_delta
,
graph_period
,
date_list
=
[
int
(
time
.
mktime
(
time
.
strptime
(
x
[
0
],
date_format
))
*
1000
)
decimator
))
for
x
in
daily_data
]
timeformat
=
'%Y<br/>%m/%d<br/>%H:%M'
# There is room for about 10 labels on the X axis.
minTickSize
=
(
max
(
1
,
(
date_list
[
-
1
]
-
date_list
[
0
])
/
(
60
*
60
*
1000
*
10
)),
'hour'
)
# Guesstimation: 6px per digit. If only em were allowed...
yLabelWidth
=
max
(
int
(
math
.
log10
(
max
(
x
[
2
]
for
x
in
daily_data
)))
+
1
,
3
)
*
6
out
.
write
(
graph
(
'apdex'
,
[
zip
(
date_list
,
(
x
[
1
]
for
x
in
daily_data
))],
{
'xaxis'
:
{
'mode'
:
'time'
,
'timeformat'
:
timeformat
,
'minTickSize'
:
minTickSize
,
},
'yaxis'
:
{
'max'
:
100
,
'axisLabel'
:
'%'
,
'labelWidth'
:
yLabelWidth
,
},
'lines'
:
{
'show'
:
True
},
},
))
out
.
write
(
graph
(
'Hits (per %s)'
%
graph_period
,
[
zip
(
date_list
,
(
x
[
2
]
for
x
in
daily_data
))],
{
'xaxis'
:
{
'mode'
:
'time'
,
'timeformat'
:
timeformat
,
'minTickSize'
:
minTickSize
,
},
'yaxis'
:
{
'axisLabel'
:
'Hits'
,
'labelWidth'
:
yLabelWidth
,
'tickDecimals'
:
0
,
},
'lines'
:
{
'show'
:
True
},
},
))
out
.
write
(
data
.
asHTML
(
decimator
))
end_stat_time
=
time
.
time
()
end_stat_time
=
time
.
time
()
if
args
.
stats
:
if
args
.
stats
:
out
.
write
(
'<h1>Parsing stats</h1><table class="stats">'
)
out
.
write
(
'<h1>Parsing stats</h1><table class="stats">'
)
...
...
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