2019-03-08 21:31:08 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
2020-06-18 05:34:39 +02:00
|
|
|
namespace ircd::stats
|
|
|
|
{
|
|
|
|
static resource::response get_stats(client &, const resource::request &);
|
|
|
|
|
|
|
|
extern resource::method method_get;
|
|
|
|
extern resource stats_resource;
|
|
|
|
}
|
2019-03-08 21:31:08 +01:00
|
|
|
|
2020-06-18 05:34:39 +02:00
|
|
|
ircd::mapi::header
|
2019-03-08 21:31:08 +01:00
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Prometheus Metrics"
|
|
|
|
};
|
|
|
|
|
2020-06-18 05:34:39 +02:00
|
|
|
decltype(ircd::stats::stats_resource)
|
|
|
|
ircd::stats::stats_resource
|
2019-03-08 21:31:08 +01:00
|
|
|
{
|
2019-08-03 23:58:52 +02:00
|
|
|
"/stats",
|
2019-03-08 21:31:08 +01:00
|
|
|
{
|
|
|
|
"Prometheus Metrics"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-18 05:34:39 +02:00
|
|
|
decltype(ircd::stats::method_get)
|
|
|
|
ircd::stats::method_get
|
2019-03-08 21:31:08 +01:00
|
|
|
{
|
2020-06-18 05:34:39 +02:00
|
|
|
stats_resource, "GET", get_stats
|
2019-03-08 21:31:08 +01:00
|
|
|
};
|
|
|
|
|
2020-06-18 05:34:39 +02:00
|
|
|
ircd::resource::response
|
|
|
|
ircd::stats::get_stats(client &client,
|
|
|
|
const resource::request &request)
|
2019-03-08 21:31:08 +01:00
|
|
|
{
|
2020-06-18 05:34:39 +02:00
|
|
|
resource::response::chunked response
|
2019-03-08 21:31:08 +01:00
|
|
|
{
|
2020-06-18 05:34:39 +02:00
|
|
|
client, http::OK, "text/plain"
|
2019-03-08 21:31:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const time_t ts
|
|
|
|
{
|
|
|
|
ircd::time<milliseconds>()
|
|
|
|
};
|
|
|
|
|
2020-06-18 05:34:39 +02:00
|
|
|
for(const auto &[name_, item] : items)
|
|
|
|
{
|
|
|
|
char buf[256], name[2][128], val[64];
|
|
|
|
const string_view _name
|
|
|
|
{
|
|
|
|
replace(name[0], name_, '.', '_')
|
|
|
|
};
|
2019-03-08 21:31:08 +01:00
|
|
|
|
2020-06-18 05:34:39 +02:00
|
|
|
const string_view line
|
|
|
|
{
|
|
|
|
buf,
|
|
|
|
::snprintf
|
|
|
|
(
|
|
|
|
buf, sizeof(buf), "%s %s %lu\n",
|
|
|
|
data(strlcpy(name[1], _name)),
|
|
|
|
data(string(val, *item)),
|
|
|
|
ts
|
|
|
|
)
|
|
|
|
};
|
2019-03-08 21:31:08 +01:00
|
|
|
|
2020-06-18 05:34:39 +02:00
|
|
|
response.write(line);
|
|
|
|
}
|
2019-03-08 21:31:08 +01:00
|
|
|
|
2020-06-18 05:34:39 +02:00
|
|
|
return std::move(response);
|
2019-03-08 21:31:08 +01:00
|
|
|
}
|