Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ai
autoca
Commits
9e38af68
Commit
9e38af68
authored
Jan 09, 2012
by
ale
Browse files
have a single function to serialize unix timestamps as redis keys
parent
c756b263
Changes
1
Hide whitespace changes
Inline
Side-by-side
autovpn/acct.py
View file @
9e38af68
...
...
@@ -4,6 +4,10 @@ import redis
import
time
def
time2day
(
unix_stamp
):
return
time
.
strftime
(
'%Y%m%d'
,
time
.
gmtime
(
unix_stamp
))
class
Accounting
(
object
):
def
__init__
(
self
,
local_db
,
aggr_db
=
None
):
...
...
@@ -44,7 +48,7 @@ class Accounting(object):
for
data
in
conns
:
pipe
.
lpush
(
'connections:%s'
%
cn
,
data
)
conn_info
=
json
.
loads
(
data
)
day
=
time
.
strftime
(
'%Y%m%d'
,
time
.
gmtime
(
conn_info
[
'end_time'
])
)
day
=
time
2day
(
conn_info
[
'end_time'
])
aggr_day
=
aggr
.
setdefault
(
day
,
{
'conn_time'
:
0
,
'bytes_sent'
:
0
,
'bytes_recv'
:
0
})
...
...
@@ -98,7 +102,7 @@ class Accounting(object):
def
get_aggregate_counts
(
self
,
cn
,
when
=
None
):
if
not
when
:
when
=
time
.
time
()
day
=
time
.
strftime
(
'%Y%m%d'
,
time
.
gmtime
(
when
)
)
day
=
time
2day
(
when
)
data
=
self
.
_aggr_db
.
hget
(
'aggr:%s'
%
cn
,
day
)
if
data
:
return
json
.
loads
(
data
)
...
...
Write
Preview
Supports
Markdown
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