mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-24 10:41:54 +00:00
BMP: TX stats in CLI
This commit is contained in:
parent
74566d3c85
commit
aac7f1d17e
43
lib/string.h
43
lib/string.h
@ -24,6 +24,8 @@ char *mb_sprintf(pool *p, const char *fmt, ...);
|
||||
char *mb_vsprintf(pool *p, const char *fmt, va_list args);
|
||||
char *lp_sprintf(linpool *p, const char *fmt, ...);
|
||||
char *lp_vsprintf(linpool *p, const char *fmt, va_list args);
|
||||
#define tmp_sprintf(...) lp_sprintf(tmp_linpool, __VA_ARGS__)
|
||||
#define tmp_vsprintf(...) lp_vsprintf(tmp_linpool, __VA_ARGS__)
|
||||
|
||||
int buffer_vprint(buffer *buf, const char *fmt, va_list args);
|
||||
int buffer_print(buffer *buf, const char *fmt, ...);
|
||||
@ -36,6 +38,47 @@ byte bstrtobyte16(const char *str);
|
||||
int bstrhextobin(const char *s, byte *b);
|
||||
int bstrbintohex(const byte *b, size_t len, char *buf, size_t size, char delim) ACCESS_READ(1, 2) ACCESS_WRITE(3, 4);
|
||||
|
||||
static inline const char *fmt_order(u64 value, int decimals, u64 kb_threshold)
|
||||
{
|
||||
bool too_big = (value + 512 < 512ULL);
|
||||
|
||||
u64 mv = value;
|
||||
int magnitude = 0;
|
||||
while (mv > kb_threshold)
|
||||
{
|
||||
magnitude++;
|
||||
mv = (mv + (too_big ? 0 : 512)) / 1024;
|
||||
}
|
||||
|
||||
ASSERT_DIE(magnitude < 7);
|
||||
char suffix = " kMGTEP"[magnitude];
|
||||
while ((magnitude - 1) * 3 > decimals)
|
||||
{
|
||||
magnitude--;
|
||||
value = (value + (too_big ? 0 : 512)) / 1024;
|
||||
too_big = false;
|
||||
}
|
||||
|
||||
if ((!decimals) || (suffix == ' '))
|
||||
return tmp_sprintf("%lu %c", value, suffix);
|
||||
|
||||
u64 divisor = 1;
|
||||
for (int i=0; i<decimals; i++)
|
||||
divisor *= 10;
|
||||
|
||||
u64 magdiv = 1;
|
||||
while (magnitude--)
|
||||
magdiv *= 1024;
|
||||
|
||||
magdiv += (divisor / 2);
|
||||
magdiv /= divisor;
|
||||
value /= magdiv;
|
||||
|
||||
return tmp_sprintf(
|
||||
tmp_sprintf("%%lu.%%0%ulu %%c", decimals),
|
||||
value / divisor, value % divisor, suffix);
|
||||
}
|
||||
|
||||
int patmatch(const byte *pat, const byte *str);
|
||||
|
||||
static inline char *xbasename(const char *str)
|
||||
|
@ -428,7 +428,10 @@ bmp_fire_tx(void *p_)
|
||||
|
||||
// log(L_INFO "btb send buf %p end %p", btb->buf, btb->end);
|
||||
|
||||
if (sk_send(p->sk, btb->end - btb->buf) <= 0)
|
||||
u64 sz = btb->end - btb->buf;
|
||||
p->tx_sent += sz;
|
||||
p->tx_sent_total += sz;
|
||||
if (sk_send(p->sk, sz) <= 0)
|
||||
return;
|
||||
|
||||
// log(L_INFO "btb free buf %p", btb->buf);
|
||||
@ -1174,6 +1177,7 @@ bmp_down(struct bmp_proto *p)
|
||||
{
|
||||
ASSERT(p->started);
|
||||
p->started = false;
|
||||
p->tx_sent = 0;
|
||||
|
||||
TRACE(D_EVENTS, "BMP session closed");
|
||||
|
||||
@ -1477,6 +1481,10 @@ bmp_show_proto_info(struct proto *P)
|
||||
|
||||
if (p->sock_err)
|
||||
cli_msg(-1006, " %-19s %M", "Last error:", p->sock_err);
|
||||
|
||||
cli_msg(-1006, " %-19s % 7u (limit %u)", "Pending buffers:", p->tx_pending_count, p->tx_pending_limit);
|
||||
cli_msg(-1006, " %-19s % 9sB", "Session TX:", fmt_order(p->tx_sent, 1, 10000));
|
||||
cli_msg(-1006, " %-19s % 9sB", "Total TX:", fmt_order(p->tx_sent_total, 1, 10000));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,8 @@ struct bmp_proto {
|
||||
struct bmp_tx_buffer_class *tx_pcls; // Class used for tx_pending allocations
|
||||
uint tx_pending_count; // How many buffers waiting for flush
|
||||
uint tx_pending_limit; // Maximum on buffer count
|
||||
u64 tx_sent; // Amount of data sent
|
||||
u64 tx_sent_total; // Amount of data sent accumulated over reconnections
|
||||
event *tx_overflow_event; // Too many buffers waiting for flush
|
||||
timer *connect_retry_timer; // Timer for retrying connection to the BMP collector
|
||||
bool started; // Flag that stores running status of BMP instance
|
||||
|
Loading…
Reference in New Issue
Block a user