0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 08:12:37 +01:00

ircd::resource: Integrate method stats into ircd::stats.

This commit is contained in:
Jason Volk 2020-12-17 21:22:43 -08:00
parent 1f2abfb64a
commit 5ee8405117
2 changed files with 62 additions and 8 deletions

View file

@ -70,9 +70,13 @@ struct ircd::resource::method::opts
struct ircd::resource::method::stats
{
uint64_t pending {0}; // Clients currently inside the method
uint64_t requests {0}; // The method was found and called.
uint64_t timeouts {0}; // The method's timeout was exceeded.
uint64_t completions {0}; // The handler returned without throwing.
uint64_t internal_errors {0}; // The handler threw a very bad exception.
using item = ircd::stats::item<uint64_t>;
item pending; ///< Clients currently inside the method
item requests; ///< The method was found and called.
item timeouts; ///< The method's timeout was exceeded.
item completions; ///< The handler returned without throwing.
item internal_errors; ///< The handler threw a very bad exception.
stats(method &);
};

View file

@ -349,6 +349,56 @@ ircd::resource::method::default_payload_max
{ "default", long(128_KiB) },
};
//
// method::stats
//
namespace ircd
{
static thread_local char method_stats_name_buf[128];
static string_view method_stats_name(resource::method &, const string_view &);
}
ircd::resource::method::stats::stats(method &m)
:pending
{
{ "name", method_stats_name(m, "pending") }
}
,requests
{
{ "name", method_stats_name(m, "requests") }
}
,timeouts
{
{ "name", method_stats_name(m, "timeouts") }
}
,completions
{
{ "name", method_stats_name(m, "completed") }
}
,internal_errors
{
{ "name", method_stats_name(m, "internal_errors") }
}
{
}
ircd::string_view
ircd::method_stats_name(resource::method &m,
const string_view &key)
{
assert(m.resource);
assert(m.resource->path);
assert(m.name);
assert(key);
return fmt::sprintf
{
method_stats_name_buf, "ircd.resource.%s.%s.%s",
m.resource->path,
m.name,
key,
};
}
//
// method::method
//
@ -385,7 +435,7 @@ ircd::resource::method::method(struct resource &resource,
}
,stats
{
std::make_unique<struct stats>()
std::make_unique<struct stats>(*this)
}
,methods_it{[this, &name]
{
@ -420,7 +470,7 @@ noexcept
"Resource '%s' method '%s' still waiting for %zu pending requests",
resource->path,
name,
stats->pending
uint64_t(stats->pending),
};
const ctx::uninterruptible::nothrow ui;
@ -445,7 +495,7 @@ try
++stats->requests;
const scope_count pending
{
stats->pending
static_cast<uint64_t &>(stats->pending)
};
// Bail out if the method limited the amount of content and it was exceeded.