haproxy/include/haproxy/stats-file.h
Aurelien DARRAGON 585ece4c92 MEDIUM: stats-file/counters: store and preload stats counters as shm file objects
This is the last patch of the shm stats file series, in this patch we
implement the logic to store and fetch shm stats objects and associate
them to existing shared counters on the current process.

Shm objects are stored in the same memory location as the shm stats file
header. In fact they are stored right after it. All objects (struct
shm_stats_file_object) have the same size (no matter their type), which
allows for easy object traversal without having to check the object's
type, and could permit the use of external tools to scan the SHM in the
future. Each object stores a guid (of GUID_MAX_LEN+1 size) and tgid
which allows to match corresponding shared counters indexes. Also,
as stated before, each object stores the list of users making use of
it. Objects are never released (the map can only grow), but unused
objects (when no more users or active users are found in objects->users),
the object is automatically recycled. Also, each object stores its
type which defines how the object generic data member should be handled.

Upon startup (or reload), haproxy first tries to scan existing shm to
find objects that could be associated to frontends, backends, listeners
or servers in the current config based on GUID. For associations that
couldn't be made, haproxy will automatically create missing objects in
the SHM during late startup. When haproxy matches with an existing object,
it means the counter from an older process is preserved in the new
process, so multiple processes temporarily share the same counter for as
long as required for older processes to eventually exit.
2025-09-03 15:59:37 +02:00

32 lines
940 B
C

#ifndef _HAPROXY_STATS_FILE_H
#define _HAPROXY_STATS_FILE_H
#include <haproxy/stats-file-t.h>
#include <sys/types.h>
#include <haproxy/buf-t.h>
#include <haproxy/stats-t.h>
extern struct shm_stats_file_hdr *shm_stats_file_hdr;
extern int shm_stats_file_max_objects;
extern int shm_stats_file_slot;
int stats_dump_fields_file(struct buffer *out,
const struct field *stats, size_t stats_count,
struct show_stat_ctx *ctx);
void stats_dump_file_header(int type, struct buffer *out);
/* Maximum number of parsed stat column in a header line.
* Directly based on ST_I_PX_MAX, with value doubled to obtain compatibility
* between haproxy adjacent versions.
*/
#define STAT_FILE_MAX_COL_COUNT (ST_I_PX_MAX*2)
void apply_stats_file(void);
int shm_stats_file_prepare(void);
struct shm_stats_file_object *shm_stats_file_add_object(char **errmsg);
#endif /* _HAPROXY_STATS_FILE_H */