4 from twisted.internet import defer
5 from nevow import rend, inevow, tags as T
6 from allmydata.util import base32, idlib
7 from allmydata.web.common import IClient, getxmlfile, abbreviate_time, \
8 abbreviate_rate, abbreviate_size, get_arg
9 from allmydata.interfaces import IUploadStatus, IDownloadStatus, \
10 IPublishStatus, IRetrieveStatus, IServermapUpdaterStatus
12 def plural(sequence_or_length):
13 if isinstance(sequence_or_length, int):
14 length = sequence_or_length
16 length = len(sequence_or_length)
21 class RateAndTimeMixin:
23 def render_time(self, ctx, data):
24 return abbreviate_time(data)
26 def render_rate(self, ctx, data):
27 return abbreviate_rate(data)
29 class UploadResultsRendererMixin(RateAndTimeMixin):
30 # this requires a method named 'upload_results'
32 def render_pushed_shares(self, ctx, data):
33 d = self.upload_results()
34 d.addCallback(lambda res: res.pushed_shares)
37 def render_preexisting_shares(self, ctx, data):
38 d = self.upload_results()
39 d.addCallback(lambda res: res.preexisting_shares)
42 def render_sharemap(self, ctx, data):
43 d = self.upload_results()
44 d.addCallback(lambda res: res.sharemap)
45 def _render(sharemap):
49 for shnum in sorted(sharemap.keys()):
50 l[T.li["%d -> %s" % (shnum, sharemap[shnum])]]
52 d.addCallback(_render)
55 def render_servermap(self, ctx, data):
56 d = self.upload_results()
57 d.addCallback(lambda res: res.servermap)
58 def _render(servermap):
62 for peerid in sorted(servermap.keys()):
63 peerid_s = idlib.shortnodeid_b2a(peerid)
64 shares_s = ",".join(["#%d" % shnum
65 for shnum in servermap[peerid]])
66 l[T.li["[%s] got share%s: %s" % (peerid_s,
67 plural(servermap[peerid]),
70 d.addCallback(_render)
73 def data_file_size(self, ctx, data):
74 d = self.upload_results()
75 d.addCallback(lambda res: res.file_size)
78 def _get_time(self, name):
79 d = self.upload_results()
80 d.addCallback(lambda res: res.timings.get(name))
83 def data_time_total(self, ctx, data):
84 return self._get_time("total")
86 def data_time_storage_index(self, ctx, data):
87 return self._get_time("storage_index")
89 def data_time_contacting_helper(self, ctx, data):
90 return self._get_time("contacting_helper")
92 def data_time_existence_check(self, ctx, data):
93 return self._get_time("existence_check")
95 def data_time_cumulative_fetch(self, ctx, data):
96 return self._get_time("cumulative_fetch")
98 def data_time_helper_total(self, ctx, data):
99 return self._get_time("helper_total")
101 def data_time_peer_selection(self, ctx, data):
102 return self._get_time("peer_selection")
104 def data_time_total_encode_and_push(self, ctx, data):
105 return self._get_time("total_encode_and_push")
107 def data_time_cumulative_encoding(self, ctx, data):
108 return self._get_time("cumulative_encoding")
110 def data_time_cumulative_sending(self, ctx, data):
111 return self._get_time("cumulative_sending")
113 def data_time_hashes_and_close(self, ctx, data):
114 return self._get_time("hashes_and_close")
116 def _get_rate(self, name):
117 d = self.upload_results()
119 file_size = r.file_size
120 time = r.timings.get(name)
124 return 1.0 * file_size / time
125 except ZeroDivisionError:
127 d.addCallback(_convert)
130 def data_rate_total(self, ctx, data):
131 return self._get_rate("total")
133 def data_rate_storage_index(self, ctx, data):
134 return self._get_rate("storage_index")
136 def data_rate_encode(self, ctx, data):
137 return self._get_rate("cumulative_encoding")
139 def data_rate_push(self, ctx, data):
140 return self._get_rate("cumulative_sending")
142 def data_rate_encode_and_push(self, ctx, data):
143 d = self.upload_results()
145 file_size = r.file_size
146 if file_size is None:
148 time1 = r.timings.get("cumulative_encoding")
151 time2 = r.timings.get("cumulative_sending")
155 return 1.0 * file_size / (time1+time2)
156 except ZeroDivisionError:
158 d.addCallback(_convert)
161 def data_rate_ciphertext_fetch(self, ctx, data):
162 d = self.upload_results()
164 fetch_size = r.ciphertext_fetched
165 if fetch_size is None:
167 time = r.timings.get("cumulative_fetch")
171 return 1.0 * fetch_size / time
172 except ZeroDivisionError:
174 d.addCallback(_convert)
177 class UploadStatusPage(UploadResultsRendererMixin, rend.Page):
178 docFactory = getxmlfile("upload-status.xhtml")
180 def __init__(self, data):
181 rend.Page.__init__(self, data)
182 self.upload_status = data
184 def upload_results(self):
185 return defer.maybeDeferred(self.upload_status.get_results)
187 def render_results(self, ctx, data):
188 d = self.upload_results()
189 def _got_results(results):
193 d.addCallback(_got_results)
196 def render_started(self, ctx, data):
197 TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
198 started_s = time.strftime(TIME_FORMAT,
199 time.localtime(data.get_started()))
202 def render_si(self, ctx, data):
203 si_s = base32.b2a_or_none(data.get_storage_index())
208 def render_helper(self, ctx, data):
210 False: "No"}[data.using_helper()]
212 def render_total_size(self, ctx, data):
213 size = data.get_size()
218 def render_progress_hash(self, ctx, data):
219 progress = data.get_progress()[0]
220 # TODO: make an ascii-art bar
221 return "%.1f%%" % (100.0 * progress)
223 def render_progress_ciphertext(self, ctx, data):
224 progress = data.get_progress()[1]
225 # TODO: make an ascii-art bar
226 return "%.1f%%" % (100.0 * progress)
228 def render_progress_encode_push(self, ctx, data):
229 progress = data.get_progress()[2]
230 # TODO: make an ascii-art bar
231 return "%.1f%%" % (100.0 * progress)
233 def render_status(self, ctx, data):
234 return data.get_status()
236 class DownloadResultsRendererMixin(RateAndTimeMixin):
237 # this requires a method named 'download_results'
239 def render_servermap(self, ctx, data):
240 d = self.download_results()
241 d.addCallback(lambda res: res.servermap)
242 def _render(servermap):
243 if servermap is None:
246 for peerid in sorted(servermap.keys()):
247 peerid_s = idlib.shortnodeid_b2a(peerid)
248 shares_s = ",".join(["#%d" % shnum
249 for shnum in servermap[peerid]])
250 l[T.li["[%s] has share%s: %s" % (peerid_s,
251 plural(servermap[peerid]),
254 d.addCallback(_render)
257 def render_servers_used(self, ctx, data):
258 d = self.download_results()
259 d.addCallback(lambda res: res.servers_used)
260 def _got(servers_used):
263 peerids_s = ", ".join(["[%s]" % idlib.shortnodeid_b2a(peerid)
264 for peerid in servers_used])
265 return T.li["Servers Used: ", peerids_s]
269 def render_problems(self, ctx, data):
270 d = self.download_results()
271 d.addCallback(lambda res: res.server_problems)
272 def _got(server_problems):
273 if not server_problems:
276 for peerid in sorted(server_problems.keys()):
277 peerid_s = idlib.shortnodeid_b2a(peerid)
278 l[T.li["[%s]: %s" % (peerid_s, server_problems[peerid])]]
279 return T.li["Server Problems:", l]
283 def data_file_size(self, ctx, data):
284 d = self.download_results()
285 d.addCallback(lambda res: res.file_size)
288 def _get_time(self, name):
289 d = self.download_results()
290 d.addCallback(lambda res: res.timings.get(name))
293 def data_time_total(self, ctx, data):
294 return self._get_time("total")
296 def data_time_peer_selection(self, ctx, data):
297 return self._get_time("peer_selection")
299 def data_time_uri_extension(self, ctx, data):
300 return self._get_time("uri_extension")
302 def data_time_hashtrees(self, ctx, data):
303 return self._get_time("hashtrees")
305 def data_time_segments(self, ctx, data):
306 return self._get_time("segments")
308 def data_time_cumulative_fetch(self, ctx, data):
309 return self._get_time("cumulative_fetch")
311 def data_time_cumulative_decode(self, ctx, data):
312 return self._get_time("cumulative_decode")
314 def data_time_cumulative_decrypt(self, ctx, data):
315 return self._get_time("cumulative_decrypt")
317 def _get_rate(self, name):
318 d = self.download_results()
320 file_size = r.file_size
321 time = r.timings.get(name)
325 return 1.0 * file_size / time
326 except ZeroDivisionError:
328 d.addCallback(_convert)
331 def data_rate_total(self, ctx, data):
332 return self._get_rate("total")
334 def data_rate_segments(self, ctx, data):
335 return self._get_rate("segments")
337 def data_rate_fetch(self, ctx, data):
338 return self._get_rate("cumulative_fetch")
340 def data_rate_decode(self, ctx, data):
341 return self._get_rate("cumulative_decode")
343 def data_rate_decrypt(self, ctx, data):
344 return self._get_rate("cumulative_decrypt")
346 def render_server_timings(self, ctx, data):
347 d = self.download_results()
348 d.addCallback(lambda res: res.timings.get("fetch_per_server"))
349 def _render(per_server):
350 if per_server is None:
353 for peerid in sorted(per_server.keys()):
354 peerid_s = idlib.shortnodeid_b2a(peerid)
355 times_s = ", ".join([self.render_time(None, t)
356 for t in per_server[peerid]])
357 l[T.li["[%s]: %s" % (peerid_s, times_s)]]
358 return T.li["Per-Server Segment Fetch Response Times: ", l]
359 d.addCallback(_render)
362 class DownloadStatusPage(DownloadResultsRendererMixin, rend.Page):
363 docFactory = getxmlfile("download-status.xhtml")
365 def __init__(self, data):
366 rend.Page.__init__(self, data)
367 self.download_status = data
369 def download_results(self):
370 return defer.maybeDeferred(self.download_status.get_results)
372 def render_results(self, ctx, data):
373 d = self.download_results()
374 def _got_results(results):
378 d.addCallback(_got_results)
381 def render_started(self, ctx, data):
382 TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
383 started_s = time.strftime(TIME_FORMAT,
384 time.localtime(data.get_started()))
387 def render_si(self, ctx, data):
388 si_s = base32.b2a_or_none(data.get_storage_index())
393 def render_helper(self, ctx, data):
395 False: "No"}[data.using_helper()]
397 def render_total_size(self, ctx, data):
398 size = data.get_size()
403 def render_progress(self, ctx, data):
404 progress = data.get_progress()
405 # TODO: make an ascii-art bar
406 return "%.1f%%" % (100.0 * progress)
408 def render_status(self, ctx, data):
409 return data.get_status()
411 class RetrieveStatusPage(rend.Page, RateAndTimeMixin):
412 docFactory = getxmlfile("retrieve-status.xhtml")
414 def __init__(self, data):
415 rend.Page.__init__(self, data)
416 self.retrieve_status = data
418 def render_started(self, ctx, data):
419 TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
420 started_s = time.strftime(TIME_FORMAT,
421 time.localtime(data.get_started()))
424 def render_si(self, ctx, data):
425 si_s = base32.b2a_or_none(data.get_storage_index())
430 def render_helper(self, ctx, data):
432 False: "No"}[data.using_helper()]
434 def render_current_size(self, ctx, data):
435 size = data.get_size()
440 def render_progress(self, ctx, data):
441 progress = data.get_progress()
442 # TODO: make an ascii-art bar
443 return "%.1f%%" % (100.0 * progress)
445 def render_status(self, ctx, data):
446 return data.get_status()
448 def render_encoding(self, ctx, data):
449 k, n = data.get_encoding()
450 return ctx.tag["Encoding: %s of %s" % (k, n)]
452 def render_problems(self, ctx, data):
453 problems = data.problems
457 for peerid in sorted(problems.keys()):
458 peerid_s = idlib.shortnodeid_b2a(peerid)
459 l[T.li["[%s]: %s" % (peerid_s, problems[peerid])]]
460 return ctx.tag["Server Problems:", l]
462 def _get_rate(self, data, name):
463 file_size = self.retrieve_status.get_size()
464 time = self.retrieve_status.timings.get(name)
465 if time is None or file_size is None:
468 return 1.0 * file_size / time
469 except ZeroDivisionError:
472 def data_time_total(self, ctx, data):
473 return self.retrieve_status.timings.get("total")
474 def data_rate_total(self, ctx, data):
475 return self._get_rate(data, "total")
477 def data_time_peer_selection(self, ctx, data):
478 return self.retrieve_status.timings.get("peer_selection")
480 def data_time_fetch(self, ctx, data):
481 return self.retrieve_status.timings.get("fetch")
482 def data_rate_fetch(self, ctx, data):
483 return self._get_rate(data, "fetch")
485 def data_time_cumulative_verify(self, ctx, data):
486 return self.retrieve_status.timings.get("cumulative_verify")
488 def data_time_decode(self, ctx, data):
489 return self.retrieve_status.timings.get("decode")
490 def data_rate_decode(self, ctx, data):
491 return self._get_rate(data, "decode")
493 def data_time_decrypt(self, ctx, data):
494 return self.retrieve_status.timings.get("decrypt")
495 def data_rate_decrypt(self, ctx, data):
496 return self._get_rate(data, "decrypt")
498 def render_server_timings(self, ctx, data):
499 per_server = self.retrieve_status.timings.get("fetch_per_server")
503 for peerid in sorted(per_server.keys()):
504 peerid_s = idlib.shortnodeid_b2a(peerid)
505 times_s = ", ".join([self.render_time(None, t)
506 for t in per_server[peerid]])
507 l[T.li["[%s]: %s" % (peerid_s, times_s)]]
508 return T.li["Per-Server Fetch Response Times: ", l]
511 class PublishStatusPage(rend.Page, RateAndTimeMixin):
512 docFactory = getxmlfile("publish-status.xhtml")
514 def __init__(self, data):
515 rend.Page.__init__(self, data)
516 self.publish_status = data
518 def render_started(self, ctx, data):
519 TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
520 started_s = time.strftime(TIME_FORMAT,
521 time.localtime(data.get_started()))
524 def render_si(self, ctx, data):
525 si_s = base32.b2a_or_none(data.get_storage_index())
530 def render_helper(self, ctx, data):
532 False: "No"}[data.using_helper()]
534 def render_current_size(self, ctx, data):
535 size = data.get_size()
540 def render_progress(self, ctx, data):
541 progress = data.get_progress()
542 # TODO: make an ascii-art bar
543 return "%.1f%%" % (100.0 * progress)
545 def render_status(self, ctx, data):
546 return data.get_status()
548 def render_encoding(self, ctx, data):
549 k, n = data.get_encoding()
550 return ctx.tag["Encoding: %s of %s" % (k, n)]
552 def render_sharemap(self, ctx, data):
553 servermap = data.get_servermap()
554 if servermap is None:
555 return ctx.tag["None"]
557 sharemap = servermap.make_sharemap()
558 for shnum in sorted(sharemap.keys()):
559 l[T.li["%d -> Placed on " % shnum,
560 ", ".join(["[%s]" % idlib.shortnodeid_b2a(peerid)
561 for peerid in sharemap[shnum]])]]
562 return ctx.tag["Sharemap:", l]
564 def render_problems(self, ctx, data):
565 problems = data.problems
569 for peerid in sorted(problems.keys()):
570 peerid_s = idlib.shortnodeid_b2a(peerid)
571 l[T.li["[%s]: %s" % (peerid_s, problems[peerid])]]
572 return ctx.tag["Server Problems:", l]
574 def _get_rate(self, data, name):
575 file_size = self.publish_status.get_size()
576 time = self.publish_status.timings.get(name)
580 return 1.0 * file_size / time
581 except ZeroDivisionError:
584 def data_time_total(self, ctx, data):
585 return self.publish_status.timings.get("total")
586 def data_rate_total(self, ctx, data):
587 return self._get_rate(data, "total")
589 def data_time_setup(self, ctx, data):
590 return self.publish_status.timings.get("setup")
592 def data_time_encrypt(self, ctx, data):
593 return self.publish_status.timings.get("encrypt")
594 def data_rate_encrypt(self, ctx, data):
595 return self._get_rate(data, "encrypt")
597 def data_time_encode(self, ctx, data):
598 return self.publish_status.timings.get("encode")
599 def data_rate_encode(self, ctx, data):
600 return self._get_rate(data, "encode")
602 def data_time_pack(self, ctx, data):
603 return self.publish_status.timings.get("pack")
604 def data_rate_pack(self, ctx, data):
605 return self._get_rate(data, "pack")
606 def data_time_sign(self, ctx, data):
607 return self.publish_status.timings.get("sign")
609 def data_time_push(self, ctx, data):
610 return self.publish_status.timings.get("push")
611 def data_rate_push(self, ctx, data):
612 return self._get_rate(data, "push")
614 def render_server_timings(self, ctx, data):
615 per_server = self.publish_status.timings.get("send_per_server")
619 for peerid in sorted(per_server.keys()):
620 peerid_s = idlib.shortnodeid_b2a(peerid)
621 times_s = ", ".join([self.render_time(None, t)
622 for t in per_server[peerid]])
623 l[T.li["[%s]: %s" % (peerid_s, times_s)]]
624 return T.li["Per-Server Response Times: ", l]
626 class MapupdateStatusPage(rend.Page, RateAndTimeMixin):
627 docFactory = getxmlfile("map-update-status.xhtml")
629 def __init__(self, data):
630 rend.Page.__init__(self, data)
631 self.update_status = data
633 def render_started(self, ctx, data):
634 TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
635 started_s = time.strftime(TIME_FORMAT,
636 time.localtime(data.get_started()))
639 def render_si(self, ctx, data):
640 si_s = base32.b2a_or_none(data.get_storage_index())
645 def render_helper(self, ctx, data):
647 False: "No"}[data.using_helper()]
649 def render_progress(self, ctx, data):
650 progress = data.get_progress()
651 # TODO: make an ascii-art bar
652 return "%.1f%%" % (100.0 * progress)
654 def render_status(self, ctx, data):
655 return data.get_status()
657 def render_problems(self, ctx, data):
658 problems = data.problems
662 for peerid in sorted(problems.keys()):
663 peerid_s = idlib.shortnodeid_b2a(peerid)
664 l[T.li["[%s]: %s" % (peerid_s, problems[peerid])]]
665 return ctx.tag["Server Problems:", l]
667 def render_privkey_from(self, ctx, data):
668 peerid = data.get_privkey_from()
670 return ctx.tag["Got privkey from: [%s]"
671 % idlib.shortnodeid_b2a(peerid)]
675 def data_time_total(self, ctx, data):
676 return self.update_status.timings.get("total")
678 def data_time_setup(self, ctx, data):
679 return self.update_status.timings.get("setup")
681 def data_time_cumulative_verify(self, ctx, data):
682 return self.update_status.timings.get("cumulative_verify")
684 def render_server_timings(self, ctx, data):
685 per_server = self.update_status.timings.get("per_server")
689 for peerid in sorted(per_server.keys()):
690 peerid_s = idlib.shortnodeid_b2a(peerid)
692 for op,t in per_server[peerid]:
694 times.append( self.render_time(None, t) )
696 times.append( "(" + self.render_time(None, t) + ")" )
697 times_s = ", ".join(times)
698 l[T.li["[%s]: %s" % (peerid_s, times_s)]]
699 return T.li["Per-Server Response Times: ", l]
702 class Status(rend.Page):
703 docFactory = getxmlfile("status.xhtml")
706 def data_active_operations(self, ctx, data):
707 client = IClient(ctx)
708 active = (client.list_active_uploads() +
709 client.list_active_downloads() +
710 client.list_active_mapupdate() +
711 client.list_active_publish() +
712 client.list_active_retrieve() +
713 client.list_active_helper_statuses())
716 def data_recent_operations(self, ctx, data):
717 client = IClient(ctx)
718 recent = [o for o in (client.list_recent_uploads() +
719 client.list_recent_downloads() +
720 client.list_recent_mapupdate() +
721 client.list_recent_publish() +
722 client.list_recent_retrieve() +
723 client.list_recent_helper_statuses())
724 if not o.get_active()]
725 recent.sort(lambda a,b: cmp(a.get_started(), b.get_started()))
729 def render_row(self, ctx, data):
732 TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
733 started_s = time.strftime(TIME_FORMAT,
734 time.localtime(s.get_started()))
735 ctx.fillSlots("started", started_s)
737 si_s = base32.b2a_or_none(s.get_storage_index())
740 ctx.fillSlots("si", si_s)
741 ctx.fillSlots("helper", {True: "Yes",
742 False: "No"}[s.using_helper()])
747 ctx.fillSlots("total_size", size)
749 progress = data.get_progress()
750 if IUploadStatus.providedBy(data):
751 link = "up-%d" % data.get_counter()
752 ctx.fillSlots("type", "upload")
753 # TODO: make an ascii-art bar
754 (chk, ciphertext, encandpush) = progress
755 progress_s = ("hash: %.1f%%, ciphertext: %.1f%%, encode: %.1f%%" %
757 (100.0 * ciphertext),
758 (100.0 * encandpush) ))
759 ctx.fillSlots("progress", progress_s)
760 elif IDownloadStatus.providedBy(data):
761 link = "down-%d" % data.get_counter()
762 ctx.fillSlots("type", "download")
763 ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
764 elif IPublishStatus.providedBy(data):
765 link = "publish-%d" % data.get_counter()
766 ctx.fillSlots("type", "publish")
767 ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
768 elif IRetrieveStatus.providedBy(data):
769 ctx.fillSlots("type", "retrieve")
770 link = "retrieve-%d" % data.get_counter()
771 ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
773 assert IServermapUpdaterStatus.providedBy(data)
774 ctx.fillSlots("type", "mapupdate %s" % data.get_mode())
775 link = "mapupdate-%d" % data.get_counter()
776 ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
777 ctx.fillSlots("status", T.a(href=link)[s.get_status()])
780 def childFactory(self, ctx, name):
781 client = IClient(ctx)
782 stype,count_s = name.split("-")
785 for s in client.list_recent_uploads():
786 if s.get_counter() == count:
787 return UploadStatusPage(s)
788 for u in client.list_all_uploads():
789 # u is an uploader object
790 s = u.get_upload_status()
791 if s.get_counter() == count:
792 return UploadStatusPage(s)
793 for s in (client.list_active_helper_statuses() +
794 client.list_recent_helper_statuses()):
795 if s.get_counter() == count:
796 # immutable-upload helpers use the same status object as
797 # a regular immutable-upload
798 return UploadStatusPage(s)
800 for s in client.list_recent_downloads():
801 if s.get_counter() == count:
802 return DownloadStatusPage(s)
803 for d in client.list_all_downloads():
804 s = d.get_download_status()
805 if s.get_counter() == count:
806 return DownloadStatusPage(s)
807 if stype == "mapupdate":
808 for s in client.list_recent_mapupdate():
809 if s.get_counter() == count:
810 return MapupdateStatusPage(s)
811 for p in client.list_all_mapupdate():
813 if s.get_counter() == count:
814 return MapupdateStatusPage(s)
815 if stype == "publish":
816 for s in client.list_recent_publish():
817 if s.get_counter() == count:
818 return PublishStatusPage(s)
819 for p in client.list_all_publish():
821 if s.get_counter() == count:
822 return PublishStatusPage(s)
823 if stype == "retrieve":
824 for s in client.list_recent_retrieve():
825 if s.get_counter() == count:
826 return RetrieveStatusPage(s)
827 for r in client.list_all_retrieve():
829 if s.get_counter() == count:
830 return RetrieveStatusPage(s)
833 class HelperStatus(rend.Page):
834 docFactory = getxmlfile("helper.xhtml")
836 def renderHTTP(self, ctx):
837 t = get_arg(inevow.IRequest(ctx), "t")
839 return self.render_JSON(ctx)
840 # is there a better way to provide 'data' to all rendering methods?
841 helper = IClient(ctx).getServiceNamed("helper")
842 self.original = helper.get_stats()
843 return rend.Page.renderHTTP(self, ctx)
845 def render_JSON(self, ctx):
847 h = IClient(ctx).getServiceNamed("helper")
849 return simplejson.dumps({})
851 stats = h.get_stats()
852 return simplejson.dumps(stats, indent=1)
854 def render_active_uploads(self, ctx, data):
855 return data["chk_upload_helper.active_uploads"]
857 def render_incoming(self, ctx, data):
858 return "%d bytes in %d files" % (data["chk_upload_helper.incoming_size"],
859 data["chk_upload_helper.incoming_count"])
861 def render_encoding(self, ctx, data):
862 return "%d bytes in %d files" % (data["chk_upload_helper.encoding_size"],
863 data["chk_upload_helper.encoding_count"])
865 def render_upload_requests(self, ctx, data):
866 return str(data["chk_upload_helper.upload_requests"])
868 def render_upload_already_present(self, ctx, data):
869 return str(data["chk_upload_helper.upload_already_present"])
871 def render_upload_need_upload(self, ctx, data):
872 return str(data["chk_upload_helper.upload_need_upload"])
874 def render_upload_bytes_fetched(self, ctx, data):
875 return str(data["chk_upload_helper.fetched_bytes"])
877 def render_upload_bytes_encoded(self, ctx, data):
878 return str(data["chk_upload_helper.encoded_bytes"])
881 class Statistics(rend.Page):
882 docFactory = getxmlfile("statistics.xhtml")
884 def renderHTTP(self, ctx):
885 provider = IClient(ctx).stats_provider
886 stats = {'stats': {}, 'counters': {}}
888 stats = provider.get_stats()
889 t = get_arg(inevow.IRequest(ctx), "t")
891 return simplejson.dumps(stats, indent=1)
892 # is there a better way to provide 'data' to all rendering methods?
893 self.original = stats
894 return rend.Page.renderHTTP(self, ctx)
896 def render_load_average(self, ctx, data):
897 return str(data["stats"].get("load_monitor.avg_load"))
899 def render_peak_load(self, ctx, data):
900 return str(data["stats"].get("load_monitor.max_load"))
902 def render_uploads(self, ctx, data):
903 files = data["counters"].get("uploader.files_uploaded")
904 bytes = data["counters"].get("uploader.bytes_uploaded")
905 return ("%s files / %s bytes (%s)" %
906 (files, bytes, abbreviate_size(bytes)))
908 def render_downloads(self, ctx, data):
909 files = data["counters"].get("downloader.files_downloaded")
910 bytes = data["counters"].get("downloader.bytes_downloaded")
911 return ("%s files / %s bytes (%s)" %
912 (files, bytes, abbreviate_size(bytes)))
914 def render_publishes(self, ctx, data):
915 files = data["counters"].get("mutable.files_published")
916 return "%s files" % (files,)
918 def render_retrieves(self, ctx, data):
919 files = data["counters"].get("mutable.files_retrieved")
920 return "%s files" % (files,)
922 def render_raw(self, ctx, data):
923 raw = pprint.pformat(data)