mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
MINOR: stats: add helper to get status string
move listen status to a helper, defining both status enum and string definition. this will be helpful to be reused in prometheus code. It also removes this hard-to-read nested ternary. Signed-off-by: William Dauchy <wdauchy@gmail.com>
This commit is contained in:
parent
655e14ef17
commit
3679d0c794
@ -84,6 +84,15 @@ enum li_state {
|
|||||||
* not rely on this state.
|
* not rely on this state.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* listener status for stats */
|
||||||
|
enum li_status {
|
||||||
|
LI_STATUS_WAITING = 0,
|
||||||
|
LI_STATUS_OPEN,
|
||||||
|
LI_STATUS_FULL,
|
||||||
|
|
||||||
|
LI_STATE_COUNT /* must be last */
|
||||||
|
};
|
||||||
|
|
||||||
/* listener socket options */
|
/* listener socket options */
|
||||||
#define LI_O_NONE 0x0000
|
#define LI_O_NONE 0x0000
|
||||||
#define LI_O_NOLINGER 0x0001 /* disable linger on this socket */
|
#define LI_O_NOLINGER 0x0001 /* disable linger on this socket */
|
||||||
|
@ -218,6 +218,9 @@ struct task *manage_global_listener_queue(struct task *t, void *context, unsigne
|
|||||||
|
|
||||||
extern struct accept_queue_ring accept_queue_rings[MAX_THREADS] __attribute__((aligned(64)));
|
extern struct accept_queue_ring accept_queue_rings[MAX_THREADS] __attribute__((aligned(64)));
|
||||||
|
|
||||||
|
extern const char* li_status_st[LI_STATE_COUNT];
|
||||||
|
enum li_status get_li_status(struct listener *l);
|
||||||
|
|
||||||
#endif /* _HAPROXY_LISTENER_H */
|
#endif /* _HAPROXY_LISTENER_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -46,6 +46,12 @@ static struct bind_kw_list bind_keywords = {
|
|||||||
static struct mt_list global_listener_queue = MT_LIST_HEAD_INIT(global_listener_queue);
|
static struct mt_list global_listener_queue = MT_LIST_HEAD_INIT(global_listener_queue);
|
||||||
static struct task *global_listener_queue_task;
|
static struct task *global_listener_queue_task;
|
||||||
|
|
||||||
|
/* listener status for stats */
|
||||||
|
const char* li_status_st[LI_STATE_COUNT] = {
|
||||||
|
[LI_STATUS_WAITING] = "WAITING",
|
||||||
|
[LI_STATUS_OPEN] = "OPEN",
|
||||||
|
[LI_STATUS_FULL] = "FULL",
|
||||||
|
};
|
||||||
|
|
||||||
#if defined(USE_THREAD)
|
#if defined(USE_THREAD)
|
||||||
|
|
||||||
@ -183,6 +189,18 @@ REGISTER_CONFIG_POSTPARSER("multi-threaded accept queue", accept_queue_init);
|
|||||||
|
|
||||||
#endif // USE_THREAD
|
#endif // USE_THREAD
|
||||||
|
|
||||||
|
/* helper to get listener status for stats */
|
||||||
|
enum li_status get_li_status(struct listener *l)
|
||||||
|
{
|
||||||
|
if (!l->maxconn || l->nbconn < l->maxconn) {
|
||||||
|
if (l->state == LI_LIMITED)
|
||||||
|
return LI_STATUS_WAITING;
|
||||||
|
else
|
||||||
|
return LI_STATUS_OPEN;
|
||||||
|
}
|
||||||
|
return LI_STATUS_FULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* adjust the listener's state and its proxy's listener counters if needed.
|
/* adjust the listener's state and its proxy's listener counters if needed.
|
||||||
* It must be called under the listener's lock, but uses atomic ops to change
|
* It must be called under the listener's lock, but uses atomic ops to change
|
||||||
* the proxy's counters so that the proxy lock is not needed.
|
* the proxy's counters so that the proxy lock is not needed.
|
||||||
|
@ -1898,7 +1898,7 @@ int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
|
|||||||
metric = mkf_u64(FN_COUNTER, l->counters->denied_sess);
|
metric = mkf_u64(FN_COUNTER, l->counters->denied_sess);
|
||||||
break;
|
break;
|
||||||
case ST_F_STATUS:
|
case ST_F_STATUS:
|
||||||
metric = mkf_str(FO_STATUS, (!l->maxconn || l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
|
metric = mkf_str(FO_STATUS, li_status_st[get_li_status(l)]);
|
||||||
break;
|
break;
|
||||||
case ST_F_PID:
|
case ST_F_PID:
|
||||||
metric = mkf_u32(FO_KEY, relative_pid);
|
metric = mkf_u32(FO_KEY, relative_pid);
|
||||||
|
Loading…
Reference in New Issue
Block a user