William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 1 | /* |
| 2 | * include/proto/stats.h |
| 3 | * This file contains definitions of some primitives to dedicated to |
| 4 | * statistics output. |
| 5 | * |
| 6 | * Copyright (C) 2000-2011 Willy Tarreau - w@1wt.eu |
| 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation, version 2.1 |
| 11 | * exclusively. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | */ |
| 22 | |
| 23 | #ifndef _PROTO_STATS_H |
| 24 | #define _PROTO_STATS_H |
| 25 | |
Willy Tarreau | 48fbcae | 2020-06-03 18:09:46 +0200 | [diff] [blame] | 26 | #include <haproxy/tools.h> |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 27 | #include <haproxy/api.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 28 | #include <types/applet.h> |
| 29 | #include <types/stream_interface.h> |
Christopher Faulet | 702226c | 2018-10-03 16:11:20 +0200 | [diff] [blame] | 30 | #include <types/stats.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 31 | |
| 32 | |
| 33 | static inline enum field_format field_format(const struct field *f, int e) |
| 34 | { |
| 35 | return f[e].type & FF_MASK; |
| 36 | } |
| 37 | |
| 38 | static inline enum field_origin field_origin(const struct field *f, int e) |
| 39 | { |
| 40 | return f[e].type & FO_MASK; |
| 41 | } |
| 42 | |
| 43 | static inline enum field_scope field_scope(const struct field *f, int e) |
| 44 | { |
| 45 | return f[e].type & FS_MASK; |
| 46 | } |
| 47 | |
| 48 | static inline enum field_nature field_nature(const struct field *f, int e) |
| 49 | { |
| 50 | return f[e].type & FN_MASK; |
| 51 | } |
| 52 | |
| 53 | static inline const char *field_str(const struct field *f, int e) |
| 54 | { |
Willy Tarreau | ddc3e9e | 2016-11-26 15:55:59 +0100 | [diff] [blame] | 55 | return (field_format(f, e) == FF_STR && f[e].u.str) ? f[e].u.str : ""; |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static inline struct field mkf_s32(uint32_t type, int32_t value) |
| 59 | { |
| 60 | struct field f = { .type = FF_S32 | type, .u.s32 = value }; |
| 61 | return f; |
| 62 | } |
| 63 | |
| 64 | static inline struct field mkf_u32(uint32_t type, uint32_t value) |
| 65 | { |
| 66 | struct field f = { .type = FF_U32 | type, .u.u32 = value }; |
| 67 | return f; |
| 68 | } |
| 69 | |
| 70 | static inline struct field mkf_s64(uint32_t type, int64_t value) |
| 71 | { |
| 72 | struct field f = { .type = FF_S64 | type, .u.s64 = value }; |
| 73 | return f; |
| 74 | } |
| 75 | |
| 76 | static inline struct field mkf_u64(uint32_t type, uint64_t value) |
| 77 | { |
| 78 | struct field f = { .type = FF_U64 | type, .u.u64 = value }; |
| 79 | return f; |
| 80 | } |
| 81 | |
| 82 | static inline struct field mkf_str(uint32_t type, const char *value) |
| 83 | { |
| 84 | struct field f = { .type = FF_STR | type, .u.str = value }; |
| 85 | return f; |
| 86 | } |
| 87 | |
Christopher Faulet | 88a0db2 | 2019-09-24 16:35:10 +0200 | [diff] [blame] | 88 | static inline struct field mkf_flt(uint32_t type, double value) |
| 89 | { |
| 90 | struct field f = { .type = FF_FLT | type, .u.flt = value }; |
| 91 | return f; |
| 92 | } |
| 93 | |
Christopher Faulet | 2b9b678 | 2019-02-27 16:42:58 +0100 | [diff] [blame] | 94 | extern const char *stat_status_codes[]; |
| 95 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 96 | /* These two structs contains all field names and descriptions according to |
| 97 | * the the number of entries in "enum stat_field" and "enum info_field" |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 98 | */ |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 99 | extern const struct name_desc stat_fields[]; |
| 100 | extern const struct name_desc info_fields[]; |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 101 | |
| 102 | int stats_fill_info(struct field *info, int len); |
| 103 | int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len); |
| 104 | int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags, |
| 105 | struct field *stats, int len); |
| 106 | int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags, |
| 107 | struct field *stats, int len); |
| 108 | int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len); |
| 109 | |
| 110 | extern struct applet http_stats_applet; |
| 111 | |
| 112 | void stats_io_handler(struct stream_interface *si); |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 113 | int stats_emit_raw_data_field(struct buffer *out, const struct field *f); |
| 114 | int stats_emit_typed_data_field(struct buffer *out, const struct field *f); |
| 115 | int stats_emit_field_tags(struct buffer *out, const struct field *f, |
| 116 | char delim); |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 117 | |
| 118 | #endif /* _PROTO_STATS_H */ |
| 119 | |
| 120 | /* |
| 121 | * Local variables: |
| 122 | * c-indent-level: 8 |
| 123 | * c-basic-offset: 8 |
| 124 | * End: |
| 125 | */ |