Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 1 | /* (C) 2015 by Sysmocom s.f.m.c. GmbH |
| 2 | * |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | */ |
| 20 | #pragma once |
| 21 | |
| 22 | #include <sys/socket.h> |
| 23 | #include <osmocom/core/linuxlist.h> |
| 24 | |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 25 | struct msgb; |
Jacob Erlbeck | 490b38f | 2015-10-27 15:10:28 +0100 | [diff] [blame^] | 26 | struct stat_item_group; |
| 27 | struct stat_item_desc; |
| 28 | struct rate_ctr_group; |
| 29 | struct rate_ctr_desc; |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 30 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 31 | enum stats_reporter_type { |
| 32 | STATS_REPORTER_STATSD, |
| 33 | }; |
| 34 | |
| 35 | struct stats_reporter { |
| 36 | enum stats_reporter_type type; |
| 37 | char *name; |
| 38 | |
Jacob Erlbeck | ed197fd | 2015-10-27 14:43:24 +0100 | [diff] [blame] | 39 | unsigned int have_net_config : 1; |
| 40 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 41 | /* config */ |
| 42 | int enabled; |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 43 | char *name_prefix; |
| 44 | char *dest_addr_str; |
| 45 | char *bind_addr_str; |
| 46 | int dest_port; |
| 47 | int mtu; |
| 48 | |
| 49 | /* state */ |
| 50 | int running; |
| 51 | struct sockaddr dest_addr; |
| 52 | int dest_addr_len; |
| 53 | struct sockaddr bind_addr; |
| 54 | int bind_addr_len; |
| 55 | int fd; |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 56 | struct msgb *buffer; |
| 57 | int agg_enabled; |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 58 | |
| 59 | struct llist_head list; |
Jacob Erlbeck | 490b38f | 2015-10-27 15:10:28 +0100 | [diff] [blame^] | 60 | int (*open)(struct stats_reporter *srep); |
| 61 | int (*close)(struct stats_reporter *srep); |
| 62 | int (*send_counter)(struct stats_reporter *srep, |
| 63 | const struct rate_ctr_group *ctrg, |
| 64 | const struct rate_ctr_desc *desc, |
| 65 | int64_t value, int64_t delta); |
| 66 | int (*send_item)(struct stats_reporter *srep, |
| 67 | const struct stat_item_group *statg, |
| 68 | const struct stat_item_desc *desc, |
| 69 | int32_t value); |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 70 | }; |
| 71 | |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 72 | struct stats_config { |
| 73 | int interval; |
| 74 | }; |
| 75 | |
| 76 | extern struct stats_config *stats_config; |
| 77 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 78 | void stats_init(void *ctx); |
| 79 | int stats_report(); |
| 80 | |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 81 | int stats_set_interval(int interval); |
| 82 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 83 | struct stats_reporter *stats_reporter_alloc(enum stats_reporter_type type, |
| 84 | const char *name); |
| 85 | void stats_reporter_free(struct stats_reporter *srep); |
| 86 | struct stats_reporter *stats_reporter_create_statsd(const char *name); |
| 87 | |
| 88 | struct stats_reporter *stats_reporter_find(enum stats_reporter_type type, |
| 89 | const char *name); |
| 90 | |
| 91 | int stats_reporter_set_remote_addr(struct stats_reporter *srep, const char *addr); |
| 92 | int stats_reporter_set_remote_port(struct stats_reporter *srep, int port); |
| 93 | int stats_reporter_set_local_addr(struct stats_reporter *srep, const char *addr); |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 94 | int stats_reporter_set_mtu(struct stats_reporter *srep, int mtu); |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 95 | int stats_reporter_set_name_prefix(struct stats_reporter *srep, const char *prefix); |
| 96 | int stats_reporter_enable(struct stats_reporter *srep); |
| 97 | int stats_reporter_disable(struct stats_reporter *srep); |