MINOR: dumpstats: split stats_dump_sv_stats() in two parts
This patch splits the function stats_dump_sv_stats() in two parts. The extracted part is called stats_fill_sv_stats(), and just fill the stats buffer. This split allows the usage of preformated stats in other parts of HAProxy like the Lua.
This commit is contained in:
parent
c4456856b0
commit
61fe6c0adb
@ -395,6 +395,8 @@ int stats_fill_info(struct field *info, int len);
|
|||||||
int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len);
|
int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len);
|
||||||
int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
|
int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
|
||||||
struct field *stats, int len);
|
struct field *stats, int len);
|
||||||
|
int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
|
||||||
|
struct field *stats, int len);
|
||||||
|
|
||||||
extern struct applet http_stats_applet;
|
extern struct applet http_stats_applet;
|
||||||
|
|
||||||
|
@ -4088,19 +4088,26 @@ static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = {
|
|||||||
[SRV_STATS_STATE_NO_CHECK] = "no check"
|
[SRV_STATS_STATE_NO_CHECK] = "no check"
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Dumps a line for server <sv> and proxy <px> to the trash and uses the state
|
/* Fill <stats> with the server statistics. <stats> is
|
||||||
* from stream interface <si>, stats flags <flags>, and server state <state>.
|
* preallocated array of length <len>. The length of the array
|
||||||
* The caller is responsible for clearing the trash if needed. Returns non-zero
|
* must be at least ST_F_TOTAL_FIELDS. If this length is less
|
||||||
* if it emits anything, zero otherwise.
|
* then this value, the function returns 0, otherwise, it
|
||||||
|
* returns 1. <flags> can take the value ST_SHLGNDS.
|
||||||
*/
|
*/
|
||||||
static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv)
|
int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
|
||||||
|
struct field *stats, int len)
|
||||||
{
|
{
|
||||||
struct appctx *appctx = __objt_appctx(si->end);
|
|
||||||
struct server *via, *ref;
|
struct server *via, *ref;
|
||||||
char str[INET6_ADDRSTRLEN];
|
char str[INET6_ADDRSTRLEN];
|
||||||
struct chunk *out = get_trash_chunk();
|
struct chunk *out = get_trash_chunk();
|
||||||
enum srv_stats_state state;
|
enum srv_stats_state state;
|
||||||
char *fld_status;
|
char *fld_status;
|
||||||
|
|
||||||
|
if (len < ST_F_TOTAL_FIELDS)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
memset(stats, 0, sizeof(*stats) * len);
|
||||||
|
|
||||||
/* we have "via" which is the tracked server as described in the configuration,
|
/* we have "via" which is the tracked server as described in the configuration,
|
||||||
* and "ref" which is the checked server and the end of the chain.
|
* and "ref" which is the checked server and the end of the chain.
|
||||||
*/
|
*/
|
||||||
@ -4151,7 +4158,6 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
chunk_reset(out);
|
chunk_reset(out);
|
||||||
memset(&stats, 0, sizeof(stats));
|
|
||||||
|
|
||||||
stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
|
stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
|
||||||
stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id);
|
stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id);
|
||||||
@ -4314,6 +4320,21 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in
|
|||||||
stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie);
|
stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dumps a line for server <sv> and proxy <px> to the trash and uses the state
|
||||||
|
* from stream interface <si>, stats flags <flags>, and server state <state>.
|
||||||
|
* The caller is responsible for clearing the trash if needed. Returns non-zero
|
||||||
|
* if it emits anything, zero otherwise.
|
||||||
|
*/
|
||||||
|
static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv)
|
||||||
|
{
|
||||||
|
struct appctx *appctx = __objt_appctx(si->end);
|
||||||
|
|
||||||
|
if (!stats_fill_sv_stats(px, sv, flags, stats, ST_F_TOTAL_FIELDS))
|
||||||
|
return 0;
|
||||||
|
|
||||||
return stats_dump_one_line(stats, flags, px, appctx);
|
return stats_dump_one_line(stats, flags, px, appctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user