* add JSON api for traffic graphs.

* bugfix for when empty graphs are encountered
 * service monitor bugfix for processes that have more than 1 day of CPU time
This commit is contained in:
KeyserSosa
2009-04-17 13:52:39 -07:00
parent c139744886
commit 969238b574
6 changed files with 36 additions and 9 deletions

View File

@@ -44,3 +44,4 @@ api('listing', ListingJsonTemplate)
api('usertableitem', UserItemJsonTemplate)
api('organiclisting', OrganicListingJsonTemplate)
api('reddittraffic', TrafficJsonTemplate)

View File

@@ -347,3 +347,12 @@ class ListingJsonTemplate(ThingJsonTemplate):
class OrganicListingJsonTemplate(ListingJsonTemplate):
def kind(self, wrapped):
return "OrganicListing"
class TrafficJsonTemplate(JsonTemplate):
def render(self, thing, *a, **kw):
res = {}
for ival in ("hour", "day", "month"):
if hasattr(thing, ival + "_data"):
res[ival] = [[time.mktime(date.timetuple())] + list(data)
for date, data in getattr(thing, ival+"_data")]
return res

View File

@@ -28,7 +28,7 @@ def google_extended(n):
"0123456789-.")
base = len(numerals)
assert(0 <= n <= base ** 2)
q, r = divmod(n, base)
q, r = divmod(int(n), base)
return numerals[q] + numerals[r]
def make_date_axis_labels(series):
@@ -101,7 +101,10 @@ class DataSeries(list):
return DataSeries(data)
def toBarX(self):
delta = self[-1] - self[-2]
if len(self) > 1:
delta = self[-1] - self[-2]
else:
delta = 0
data = self.toBarY()
return DataSeries(data[1:] + [data[-1] + delta])

View File

@@ -359,10 +359,16 @@ def process_info(proc_ids = [], name = '', exe = "/usr/bin/env ps"):
n = ' '.join(line[ageid+1:])
if (n.startswith(name) and
(not proc_ids or int(pid) in proc_ids)):
age = line[ageid].split(':')[0]
# patch for > 24 hour old processes
if '-' in age:
days, hours = age.split('-')
age = float(days) * 24 + float(hours)
else:
age = float(age)
res[pid] = dict(cpu = float(line[cpuid]),
mem = float(line[memid]),
age = float(line[ageid].split(':')[0]),
name = n)
age = age, name = n)
except (ValueError, IndexError):
pass
return res

View File

@@ -69,10 +69,15 @@ def load_traffic(interval, what, iden,
npoints = npoints)
if res and isinstance(res[0][0], datetime.datetime):
res = zip(*res)
res[0] = [x.replace(tzinfo=None) - datetime.timedelta(0, time.timezone)
for x in res[0]]
res = zip(*res)
dates, data = zip(*res)
if interval == 'hour':
# shift hourly totals into local time zone.
dates = [x.replace(tzinfo=None) -
datetime.timedelta(0, time.timezone) for x in dates]
else:
# we don't care about the hours
dates = [x.date() for x in dates]
res = zip(dates, data)
return res

View File

@@ -28,7 +28,10 @@
<%def name="daily_summary()">
<%
umin = min(data[0] for date, data in filter(None, thing.day_data))
thing.day_data = filter(None, thing.day_data)
umin = min(data[0] for date, data in thing.day_data)
if len(filter(lambda x: x[1][0] == umin, thing.day_data)) > 1:
umin = -1
umax = max(data[0] for date, data in filter(None, thing.day_data))
%>
<table class="traffic-table">