webapi: introducer stats: add 'announcement_distinct_hosts' to the t=json form, to show how many distinct hosts are providing e.g. storage services

This commit is contained in:
Brian Warner 2008-11-18 15:30:15 -07:00
parent 918970b63a
commit 994d97c644
3 changed files with 38 additions and 1 deletions

View File

@ -1162,7 +1162,22 @@ GET / (introducer status)
By adding "?t=json" to the URL, the node will return a JSON-formatted
dictionary of stats values, which can be used to produce graphs of connected
clients over time.
clients over time. This dictionary has the following keys:
["subscription_summary"] : a dictionary mapping service name (like
"storage") to an integer with the number of
clients that have subscribed to hear about that
service
["announcement_summary"] : a dictionary mapping service name to an integer
with the number of servers which are announcing
that service
["announcement_distinct_hosts"] : a dictionary mapping service name to an
integer which represents the number of
distinct hosts that are providing that
service. If two servers have announced
FURLs which use the same hostnames (but
different ports and tubids), they are
considered to be on the same host.
== Static Files in /public_html ==

View File

@ -802,6 +802,8 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
{"storage": 5})
self.failUnlessEqual(data["announcement_summary"],
{"storage": 5, "stub_client": 5})
self.failUnlessEqual(data["announcement_distinct_hosts"],
{"storage": 1, "stub_client": 1})
except unittest.FailTest:
print
print "GET %s?t=json output was:" % self.introweb_url

View File

@ -31,12 +31,32 @@ class IntroducerRoot(rend.Page):
res["subscription_summary"] = subscription_summary
announcement_summary = {}
service_hosts = {}
for (ann,when) in i.get_announcements().values():
(furl, service_name, ri_name, nickname, ver, oldest) = ann
if service_name not in announcement_summary:
announcement_summary[service_name] = 0
announcement_summary[service_name] += 1
if service_name not in service_hosts:
service_hosts[service_name] = set()
# it's nice to know how many distinct hosts are available for
# each service. We define a "host" by a set of addresses
# (hostnames or ipv4 addresses), which we extract from the
# connection hints. In practice, this is usually close
# enough: when multiple services are run on a single host,
# they're usually either configured with the same addresses,
# or setLocationAutomatically picks up the same interfaces.
locations = SturdyRef(furl).getTubRef().getLocations()
# list of tuples, ("ipv4", host, port)
host = frozenset([hint[1]
for hint in locations
if hint[0] == "ipv4"])
service_hosts[service_name].add(host)
res["announcement_summary"] = announcement_summary
distinct_hosts = dict([(name, len(hosts))
for (name, hosts)
in service_hosts.iteritems()])
res["announcement_distinct_hosts"] = distinct_hosts
return simplejson.dumps(res, indent=1) + "\n"