Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorGustavo <gustavo@gustavo-HP.(none)>2013-02-07 15:23:18 (GMT)
committer Gustavo <gustavo@gustavo-HP.(none)>2013-02-07 15:23:18 (GMT)
commit0ff42bd59fdc7d3f2c491a12f55e7df587667054 (patch)
tree2ce7f8f22fc4685ea683cab8b42b84782a010d37 /build
parent7b76144318a26fbd672232046fa94914826a51b9 (diff)
fixe, detection of None periods for a while activity still running. Modify rrd_files.py
Diffstat (limited to 'build')
-rw-r--r--build/lib.linux-x86_64-2.7/stats_consolidation/rrd_files.py45
-rw-r--r--build/lib.linux-x86_64-2.7/stats_consolidation/test_rrd.py22
2 files changed, 46 insertions, 21 deletions
diff --git a/build/lib.linux-x86_64-2.7/stats_consolidation/rrd_files.py b/build/lib.linux-x86_64-2.7/stats_consolidation/rrd_files.py
index c5561d7..5ef1d55 100644
--- a/build/lib.linux-x86_64-2.7/stats_consolidation/rrd_files.py
+++ b/build/lib.linux-x86_64-2.7/stats_consolidation/rrd_files.py
@@ -1,6 +1,7 @@
import rrdtool
import os
import sys
+from datetime import datetime
class RRD:
@@ -9,7 +10,7 @@ class RRD:
data_item = 2
DS = {'active':0, 'buddies':0, 'instances':0, 'new':0, 'resumed':0, 'uptime':0}
- def __init__(self, path, name, date_start, date_end):
+ def __init__(self, path, name, date_start=None, date_end=None):
self.rrd_name = name
@@ -33,9 +34,9 @@ class RRD:
self.user_hash[:2],
self.user_hash
)
-
+ """
self.uuid = self.get_uuid_from_file(self.user_path)
-
+ """
print "*******************************************"
print " RRD "
@@ -67,32 +68,42 @@ class RRD:
i=+1
return -1
- def get_uptime_by_interval (self):
- ds_name = "uptime"
+ """
+ Find several valid record consecutives, the last one is time of the interval.
+ Return: a list (start_time, total_time)
+ """
+ def get_last_value_by_interval (self, ds_name):
res=list()
-
- print "-------Calcule "+ ds_name +"-------"
+ prev_value = 0.0
i=0
found = False
+
+ print "-------Calcule "+ ds_name +"-------"
while i < len(self.rrd[self.data_item]):
- value = str(self.rrd[self.data_item][i][self.DS[ds_name]])
- if value != "None":
- uptime = value
- end = str (long(self.date_start) + ((i+1) * 60))
+ value = str(self.rrd[self.data_item][i][self.DS[ds_name]])
+
+ if (value != "None") and (float(value) > 0) and (float(value) > float(prev_value)):
+ prev_value = value
+ end = long(self.date_start) + ((i+1) * 60)
if found == False:
found = True
- start = str (long (self.date_start) + ((i+1) * 60))
+ start = long (self.date_start) + ((i+1) * 60)
else:
if found:
- print start + "->" + end + ": " + uptime
- if float(uptime) > 0:
- res.append((start, uptime))
+ print str(datetime.fromtimestamp(float(start))) + " -> " + str(datetime.fromtimestamp(float(end))) + ": " + prev_value
+ res.append((start, prev_value))
found = False
+ prev_value = 0.0
i=i+1
return res
print "---------------------------------------------------"
+
+ def get_active_by_interval (self):
+ return self.get_last_value_by_interval ("active")
-
+ def get_uptime_by_interval (self):
+ return self.get_last_value_by_interval ("uptime")
+
def get_name(self):
return self.rrd_name.partition(".rrd")[0]
@@ -104,7 +115,7 @@ class RRD:
value = str (self.rrd[self.data_item][i][self.DS[ds_name]])
if value != "None":
- print timestamp+ ": " + value
+ print str(datetime.fromtimestamp(float(timestamp))) + " (" + timestamp + ")" + ": " + value
i=i+1
print "---------------------------------------------------"
diff --git a/build/lib.linux-x86_64-2.7/stats_consolidation/test_rrd.py b/build/lib.linux-x86_64-2.7/stats_consolidation/test_rrd.py
index 657ce18..81dd3c8 100644
--- a/build/lib.linux-x86_64-2.7/stats_consolidation/test_rrd.py
+++ b/build/lib.linux-x86_64-2.7/stats_consolidation/test_rrd.py
@@ -1,8 +1,15 @@
-from db import *
+#!/usr/bin/env python
+import argparse
+from db import *
from rrd_files import *
from db import *
+parser = argparse.ArgumentParser()
+parser.add_argument('--rrd_path',required=False)
+parser.add_argument('--rrd_name',required=True)
+
+args = parser.parse_args()
print "============================== TEST RRD -> Relational DB ========================================"
db = DB_Stats('statistics', 'root', 'gustavo')
@@ -26,13 +33,20 @@ DATE_END = datetime(year=2012,
DATE_START = db.get_date_last_record()
DATE_END = datetime.now().strftime("%s")
-act_rrd = RRD (path = "/home/gustavo/AC/consolidation/rrds", name="pippy.rrd", date_start=DATE_START, date_end=DATE_END)
+act_rrd = RRD (path = "/home/gustavo/AC/consolidation/rrds", name=args.rrd_name)
+"""
+act_rrd = RRD (path = "/home/gustavo/AC/consolidation/rrds", name="abacus.rrd", date_start=DATE_START, date_end=DATE_END)
+"""
"""
-act_rrd.show_valid_ds("uptime")
act_rrd.show_valid_ds("resumed")
act_rrd.show_valid_ds("new")
act_rrd.show_valid_ds("instances")
act_rrd.show_valid_ds("buddies")
-"""
data = {}
db.store_activity_uptime(act_rrd)
+"""
+act_rrd.show_valid_ds("uptime")
+act_rrd.show_valid_ds("active")
+
+act_rrd.get_uptime_by_interval()
+act_rrd.get_active_by_interval()