0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-13 22:58:42 +00:00
This commit is contained in:
Vojtech Vilimek 2022-07-20 10:29:46 +02:00
parent f3b9b30693
commit 31de4be2bc

View File

@ -33,36 +33,19 @@ static void
stats_rt_notify(struct proto *P UNUSED, struct channel *src_ch, const net_addr *n UNUSED, rte *new, const rte *old) stats_rt_notify(struct proto *P UNUSED, struct channel *src_ch, const net_addr *n UNUSED, rte *new, const rte *old)
{ {
struct stats_channel *ch = (void *) src_ch; struct stats_channel *ch = (void *) src_ch;
log(L_INFO "stats_rt_notify() %u", ch->max_generation);
if (old) if (old)
{
if (old->generation < ch->max_generation)
{ {
ch->counters[old->generation]--; ch->counters[old->generation]--;
log(L_INFO "channel %s counter %u was decreased", src_ch->name, old->generation); if (old->generation < ch->max_generation)
} ch->sum--;
else
{
log(L_WARN "Stats: Maximum generation reached in channel %s, route is dropped.",
src_ch->name
);
}
} }
if (new) if (new)
{
if (new->generation < ch->max_generation)
{ {
ch->counters[new->generation]++; ch->counters[new->generation]++;
log(L_INFO "channel %s counter %u was increased", src_ch->name, new->generation); if (new->generation < ch->max_generation)
} ch->sum++;
else
{
log(L_WARN "Stats: Maximum generation reached in channel %s, route is dropped.",
src_ch->name
);
}
} }
} }
@ -76,8 +59,6 @@ stats_reload_routes(struct channel *C UNUSED)
static void static void
stats_configure_channels(struct proto *P, struct proto_config *CF) stats_configure_channels(struct proto *P, struct proto_config *CF)
{ {
log(L_INFO "stats_configure_channels()");
struct channel_config *cc; struct channel_config *cc;
WALK_LIST(cc, CF->channels) WALK_LIST(cc, CF->channels)
{ {
@ -96,7 +77,6 @@ stats_init(struct proto_config *CF)
{ {
struct proto *P = proto_new(CF); struct proto *P = proto_new(CF);
struct stats_proto *p = (void *) P; struct stats_proto *p = (void *) P;
log(L_INFO "stats_init()");
P->rt_notify = stats_rt_notify; P->rt_notify = stats_rt_notify;
P->reload_routes = stats_reload_routes; P->reload_routes = stats_reload_routes;
@ -122,8 +102,6 @@ stats_find_channel(struct stats_proto *p, const char *name)
static int static int
stats_start(struct proto *P UNUSED) stats_start(struct proto *P UNUSED)
{ {
log(L_INFO "stats_start()");
return PS_UP; return PS_UP;
} }
@ -132,7 +110,6 @@ stats_reconfigure(struct proto *P, struct proto_config *CF)
{ {
struct stats_proto *p = (void *) P; struct stats_proto *p = (void *) P;
struct stats_config *new = (void *) CF; struct stats_config *new = (void *) CF;
log(L_INFO "stats_reconfigure()");
struct channel *c; struct channel *c;
WALK_LIST(c, p->p.channels) WALK_LIST(c, p->p.channels)
@ -150,13 +127,13 @@ stats_reconfigure(struct proto *P, struct proto_config *CF)
struct stats_channel *sc = (void *) c; struct stats_channel *sc = (void *) c;
struct stats_channel_config *scc = (void *) cc; struct stats_channel_config *scc = (void *) cc;
sc->counters = mb_realloc(sc->counters, scc->max_generation);
if (sc->max_generation < scc->max_generation)
/* zero newly created counters */
memset(sc->counters + sc->max_generation, 0, scc->max_generation - sc->max_generation);
sc->max_generation = scc->max_generation; sc->max_generation = scc->max_generation;
/* recalculate sum */
sc->sum = 0;
for (u8 i = 0; i < sc->max_generation; i++)
sc->sum += sc->counters[i];
c->stale = 0; c->stale = 0;
} }
} }
@ -169,29 +146,12 @@ stats_reconfigure(struct proto *P, struct proto_config *CF)
return 1; return 1;
} }
static void
stats_copy_config(struct proto_config *dest UNUSED, struct proto_config *src UNUSED)
{
/* Just a shallow copy, not many items here */
}
/* NO NEED TO PRINT ANYTHING BEFORE protocol header
static void
stats_get_status(struct proto *P, byte *buf)
{
struct stats_proto *p = (void *) P;
cli_msg(-1006, " another super informative message ");
}
*/
static void static void
stats_show_proto_info(struct proto *P) stats_show_proto_info(struct proto *P)
{ {
struct stats_proto *p = (void *) P; struct stats_proto *p = (void *) P;
log(L_INFO "stats_show_proto_info() ");
/* indexes of non-zero counters */
u32 *arr = mb_alloc(p->p.pool, 256 * sizeof(u32)); u32 *arr = mb_alloc(p->p.pool, 256 * sizeof(u32));
struct stats_channel *sc; struct stats_channel *sc;
@ -206,13 +166,13 @@ stats_show_proto_info(struct proto *P)
for (u8 i = 0; i < sc->max_generation; i++) for (u8 i = 0; i < sc->max_generation; i++)
if (sc->counters[i]) if (sc->counters[i])
{ {
log(L_INFO "found non-zero %u in counter %u", sc->counters[i], i);
arr[len] = i; arr[len] = i;
len++; len++;
} }
cli_msg(-1006, " Channel %s", sc->c.name); cli_msg(-1006, " Channel %s", sc->c.name);
cli_msg(-1006, " Max generation: %3u", sc->max_generation); cli_msg(-1006, " Max generation: %3u", sc->max_generation);
cli_msg(-1006, " Exports: %10u", sc->sum);
cli_msg(-1006, " Counter exported"); cli_msg(-1006, " Counter exported");
for (u8 i = 0; i < len; i++) for (u8 i = 0; i < len; i++)
@ -228,10 +188,13 @@ stats_show_proto_info(struct proto *P)
} }
void void
stats_update_debug(struct proto *P UNUSED) stats_update_debug(struct proto *P)
{ {
struct channel *c;
//p->c->debug = p->p.debug; WALK_LIST(c, P->channels)
{
c->debug = P->debug;
}
} }
static int static int
@ -239,11 +202,11 @@ stats_channel_start(struct channel *C)
{ {
struct stats_channel *c = (void *) C; struct stats_channel *c = (void *) C;
struct stats_proto *p = (void *) C->proto; struct stats_proto *p = (void *) C->proto;
log(L_INFO "stats_channel_start() %s", C->name);
c->pool = p->p.pool; c->pool = p->p.pool;
c->counters = mb_allocz(c->pool, c->max_generation * sizeof(u32)); c->counters = mb_allocz(c->pool, 256 * sizeof(u32));
c->sum = 0;
return 0; return 0;
} }
@ -252,7 +215,6 @@ static void
stats_channel_shutdown(struct channel *C) stats_channel_shutdown(struct channel *C)
{ {
struct stats_channel *c = (void *) C; struct stats_channel *c = (void *) C;
log(L_INFO "stats_channel_shutdown() %s", C->name);
mb_free(c->counters); mb_free(c->counters);
@ -277,8 +239,6 @@ struct protocol proto_stats = {
.init = stats_init, .init = stats_init,
.start = stats_start, .start = stats_start,
.reconfigure = stats_reconfigure, .reconfigure = stats_reconfigure,
.copy_config = stats_copy_config,
//.get_status = stats_get_status,
.show_proto_info = stats_show_proto_info .show_proto_info = stats_show_proto_info
}; };