libosmocore  0.9.3
Osmocom core library
include/osmocom/core/stats.h
00001 /* (C) 2015 by Sysmocom s.f.m.c. GmbH
00002  *
00003  * All Rights Reserved
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  *
00019  */
00020 #pragma once
00021 
00022 #include <sys/socket.h>
00023 #include <osmocom/core/linuxlist.h>
00024 
00025 #include <stdint.h>
00026 
00027 struct msgb;
00028 struct osmo_stat_item_group;
00029 struct osmo_stat_item_desc;
00030 struct rate_ctr_group;
00031 struct rate_ctr_desc;
00032 
00033 enum osmo_stats_class {
00034         OSMO_STATS_CLASS_UNKNOWN,
00035         OSMO_STATS_CLASS_GLOBAL,
00036         OSMO_STATS_CLASS_PEER,
00037         OSMO_STATS_CLASS_SUBSCRIBER,
00038 };
00039 
00040 enum osmo_stats_reporter_type {
00041         OSMO_STATS_REPORTER_STATSD,
00042         OSMO_STATS_REPORTER_LOG,
00043 };
00044 
00045 struct osmo_stats_reporter {
00046         enum osmo_stats_reporter_type type;
00047         char *name;
00048 
00049         unsigned int have_net_config : 1;
00050 
00051         /* config */
00052         int enabled;
00053         char *name_prefix;
00054         char *dest_addr_str;
00055         char *bind_addr_str;
00056         int dest_port;
00057         int mtu;
00058         enum osmo_stats_class max_class;
00059 
00060         /* state */
00061         int running;
00062         struct sockaddr dest_addr;
00063         int dest_addr_len;
00064         struct sockaddr bind_addr;
00065         int bind_addr_len;
00066         int fd;
00067         struct msgb *buffer;
00068         int agg_enabled;
00069         int force_single_flush;
00070 
00071         struct llist_head list;
00072         int (*open)(struct osmo_stats_reporter *srep);
00073         int (*close)(struct osmo_stats_reporter *srep);
00074         int (*send_counter)(struct osmo_stats_reporter *srep,
00075                 const struct rate_ctr_group *ctrg,
00076                 const struct rate_ctr_desc *desc,
00077                 int64_t value, int64_t delta);
00078         int (*send_item)(struct osmo_stats_reporter *srep,
00079                 const struct osmo_stat_item_group *statg,
00080                 const struct osmo_stat_item_desc *desc,
00081                 int32_t value);
00082 };
00083 
00084 struct osmo_stats_config {
00085         int interval;
00086 };
00087 
00088 extern struct osmo_stats_config *osmo_stats_config;
00089 
00090 void osmo_stats_init(void *ctx);
00091 int osmo_stats_report();
00092 
00093 int osmo_stats_set_interval(int interval);
00094 
00095 struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type,
00096         const char *name);
00097 void osmo_stats_reporter_free(struct osmo_stats_reporter *srep);
00098 
00099 struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name);
00100 struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name);
00101 
00102 struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type,
00103         const char *name);
00104 
00105 int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr);
00106 int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port);
00107 int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr);
00108 int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu);
00109 int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep,
00110         enum osmo_stats_class class_id);
00111 int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix);
00112 int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep);
00113 int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep);