REORG: stats: extract HTML related functions

Extract functions related to HTML stats webpage from stats.c into a new
module named stats-html. This allows to reduce stats.c to roughly half
of its original size.
This commit is contained in:
Amaury Denoyelle 2024-04-16 11:21:06 +02:00
parent b3d5708adc
commit b8c1fdf24e
8 changed files with 2135 additions and 2071 deletions

View File

@ -975,7 +975,7 @@ OBJS += src/mux_h2.o src/mux_fcgi.o src/mux_h1.o src/tcpcheck.o \
src/dynbuf.o src/wdt.o src/pipe.o src/init.o src/http_acl.o \
src/hpack-huff.o src/hpack-enc.o src/dict.o src/freq_ctr.o \
src/ebtree.o src/hash.o src/dgram.o src/version.o src/proto_rhttp.o \
src/guid.o
src/guid.o src/stats-html.o
ifneq ($(TRACE),)
OBJS += src/calltrace.o

View File

@ -0,0 +1,21 @@
#ifndef _HAPROXY_STATS_HTML_T_H
#define _HAPROXY_STATS_HTML_T_H
/* HTTP stats : applet.st0 */
enum {
STAT_HTTP_INIT = 0, /* Initial state */
STAT_HTTP_HEAD, /* send headers before dump */
STAT_HTTP_DUMP, /* dumping stats */
STAT_HTTP_POST, /* waiting post data */
STAT_HTTP_LAST, /* sending last chunk of response */
STAT_HTTP_DONE, /* dump is finished */
STAT_HTTP_END, /* finished */
};
/* HTML form to limit output scope */
#define STAT_SCOPE_TXT_MAXLEN 20 /* max len for scope substring */
#define STAT_SCOPE_INPUT_NAME "scope" /* pattern form scope name <input> in html form */
#define STAT_SCOPE_PATTERN "?" STAT_SCOPE_INPUT_NAME "="
#endif /* _HAPROXY_STATS_HTML_T_H */

View File

@ -0,0 +1,22 @@
#ifndef _HAPROXY_STATS_HTML_H
#define _HAPROXY_STATS_HTML_H
#include <haproxy/stats-html-t.h>
#include <haproxy/applet-t.h>
#include <haproxy/buf-t.h>
#include <haproxy/proxy-t.h>
#include <haproxy/stats-t.h>
#include <haproxy/stconn-t.h>
void stats_dump_html_head(struct appctx *appctx);
void stats_dump_html_info(struct stconn *sc);
int stats_dump_fields_html(struct buffer *out, const struct field *stats,
struct show_stat_ctx *ctx);
void stats_dump_html_px_hdr(struct stconn *sc, struct proxy *px);
void stats_dump_html_px_end(struct stconn *sc, struct proxy *px);
void stats_dump_html_end();
extern struct applet http_stats_applet;
#endif /* _HAPROXY_STATS_HTML_H */

View File

@ -58,17 +58,6 @@
#define STATS_DOMAIN (0) /* used for bitshifting, type of statistics: proxy or dns */
#define STATS_PX_CAP (8) /* used for bitshifting, differentiate obj1 type for proxy statistics */
/* HTTP stats : applet.st0 */
enum {
STAT_HTTP_INIT = 0, /* Initial state */
STAT_HTTP_HEAD, /* send headers before dump */
STAT_HTTP_DUMP, /* dumping stats */
STAT_HTTP_POST, /* waiting post data */
STAT_HTTP_LAST, /* sending last chunk of response */
STAT_HTTP_DONE, /* dump is finished */
STAT_HTTP_END, /* finished */
};
/* status codes available for the stats admin page */
enum {
STAT_STATUS_INIT = 0,
@ -83,11 +72,6 @@ enum {
STAT_STATUS_SIZE
};
/* HTML form to limit output scope */
#define STAT_SCOPE_TXT_MAXLEN 20 /* max len for scope substring */
#define STAT_SCOPE_INPUT_NAME "scope" /* pattern form scope name <input> in html form */
#define STAT_SCOPE_PATTERN "?" STAT_SCOPE_INPUT_NAME "="
/* Actions available for the stats admin forms */
enum {
ST_ADM_ACTION_NONE = 0,

View File

@ -33,6 +33,7 @@ struct buffer;
struct proxy;
struct appctx;
struct htx;
struct stconn;
/* These two structs contains all field names and descriptions according to
* the the number of entries in "enum stat_field" and "enum info_field"
@ -48,6 +49,8 @@ extern THREAD_LOCAL struct field *stat_l[];
struct htx;
int stats_putchk(struct appctx *appctx, struct buffer *buf, struct htx *htx);
const char *stats_scope_ptr(struct appctx *appctx);
int stats_dump_one_line(const struct field *stats, size_t stats_count, struct appctx *appctx);
int stats_fill_info(struct field *info, int len, uint flags);
@ -60,6 +63,8 @@ int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len,
enum stat_field *selected_field);
int stats_dump_stat_to_buffer(struct stconn *sc, struct buffer *buf, struct htx *htx);
int stats_emit_raw_data_field(struct buffer *out, const struct field *f);
int stats_emit_typed_data_field(struct buffer *out, const struct field *f);
int stats_emit_field_tags(struct buffer *out, const struct field *f,

View File

@ -35,6 +35,7 @@
#include <haproxy/sc_strm.h>
#include <haproxy/server-t.h>
#include <haproxy/stats.h>
#include <haproxy/stats-html.h>
#include <haproxy/stconn.h>
#include <haproxy/stream.h>
#include <haproxy/trace.h>

2082
src/stats-html.c Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff