0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 18:18:56 +02:00

ircd::stats: Start a preliminary stats system.

This commit is contained in:
Jason Volk 2019-03-12 15:00:14 -07:00
parent f745787ce4
commit 72fe68bb29
4 changed files with 111 additions and 0 deletions

View file

@ -45,6 +45,7 @@
#include "http.h"
#include "magics.h"
#include "conf.h"
#include "stats.h"
#include "fs/fs.h"
#include "ios.h"
#include "ctx/ctx.h"

40
include/ircd/stats.h Normal file
View file

@ -0,0 +1,40 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 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.
#pragma once
#define HAVE_IRCD_STATS_H
namespace ircd::stats
{
struct item;
IRCD_EXCEPTION(ircd::error, error)
IRCD_EXCEPTION(error, not_found)
extern std::map<string_view, item *> items;
}
struct ircd::stats::item
{
using callback = std::function<string_view (const mutable_buffer &)>;
static const size_t NAME_MAX_LEN;
json::strung feature_;
json::object feature;
string_view name;
callback cb;
public:
item(const json::members &, callback);
item(item &&) = delete;
item(const item &) = delete;
~item() noexcept;
};

View file

@ -110,6 +110,7 @@ libircd_la_SOURCES = \
json.cc \
locale.cc \
conf.cc \
stats.cc \
logger.cc \
sodium.cc \
rfc1459.cc \

69
ircd/stats.cc Normal file
View file

@ -0,0 +1,69 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 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.
decltype(ircd::stats::items)
ircd::stats::items
{};
//
// item
//
decltype(ircd::stats::item::NAME_MAX_LEN)
ircd::stats::item::NAME_MAX_LEN
{
127
};
ircd::stats::item::item(const json::members &opts,
callback cb)
:feature_
{
opts
}
,feature
{
feature_
}
,name
{
unquote(feature.at("name"))
}
,cb
{
std::move(cb)
}
{
if(name.size() > NAME_MAX_LEN)
throw error
{
"Stats item '%s' name length:%zu exceeds max:%zu",
name,
name.size(),
NAME_MAX_LEN
};
if(!items.emplace(name, this).second)
throw error
{
"Conf item named '%s' already exists", name
};
}
ircd::stats::item::~item()
noexcept
{
if(name)
{
const auto it{items.find(name)};
assert(data(it->first) == data(name));
items.erase(it);
}
}