Loading...
Searching...
No Matches
stats.h
Go to the documentation of this file.
/*
* (C) 2015 by sysmocom - s.f.m.c. GmbH
*
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#pragma once
/* a bit of a crude way to disable building/using this on (bare iron)
* embedded systems. We cannot use the autoconf-defined HAVE_... macros
* here, as that only works at library compile time, not at application
* compile time */
#if defined(unix) || defined(__APPLE__)
#include <sys/socket.h>
#include <arpa/inet.h>
#include <osmocom/core/linuxlist.h>
#include <stdint.h>
struct msgb;
struct osmo_stat_item_group;
struct osmo_stat_item_desc;
struct rate_ctr_group;
struct rate_ctr_desc;
enum osmo_stats_class {
OSMO_STATS_CLASS_UNKNOWN,
OSMO_STATS_CLASS_GLOBAL,
OSMO_STATS_CLASS_PEER,
OSMO_STATS_CLASS_SUBSCRIBER,
};
enum osmo_stats_reporter_type {
OSMO_STATS_REPORTER_LOG,
OSMO_STATS_REPORTER_STATSD,
};
struct osmo_stats_reporter {
enum osmo_stats_reporter_type type;
char *name;
unsigned int have_net_config : 1;
/* config */
int enabled;
char *name_prefix;
char *dest_addr_str;
char *bind_addr_str;
int dest_port;
int mtu;
unsigned int flush_period;
enum osmo_stats_class max_class;
/* state */
int running;
struct sockaddr dest_addr;
int dest_addr_len;
struct sockaddr bind_addr;
int bind_addr_len;
int fd;
struct msgb *buffer;
int agg_enabled;
int force_single_flush;
unsigned int flush_period_counter;
struct llist_head list;
int (*open)(struct osmo_stats_reporter *srep);
int (*close)(struct osmo_stats_reporter *srep);
int (*send_counter)(struct osmo_stats_reporter *srep,
const struct rate_ctr_group *ctrg,
const struct rate_ctr_desc *desc,
int64_t value, int64_t delta);
int (*send_item)(struct osmo_stats_reporter *srep,
const struct osmo_stat_item_group *statg,
const struct osmo_stat_item_desc *desc,
int64_t value);
};
struct osmo_stats_config {
int interval;
};
extern struct llist_head osmo_stats_reporter_list;
extern struct osmo_stats_config *osmo_stats_config;
void osmo_stats_init(void *ctx);
int osmo_stats_report(void);
int osmo_stats_set_interval(int interval);
struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type,
const char *name);
void osmo_stats_reporter_free(struct osmo_stats_reporter *srep);
struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type,
const char *name);
int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr);
int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port);
int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr);
int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu);
int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep,
enum osmo_stats_class class_id);
int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix);
int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep);
int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep);
int osmo_stats_reporter_set_flush_period(struct osmo_stats_reporter *srep, unsigned int period);
/* reporter creation */
struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name);
struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name);
/* helper functions for reporter implementations */
int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data,
int data_len);
int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep);
int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep);
int osmo_stats_reporter_udp_close(struct osmo_stats_reporter *srep);
#endif /* unix || __APPLE__ */
osmo_stats_reporter_alloc
struct osmo_stats_reporter * osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type, const char *name)
Definition stats.c:212
osmo_stats_reporter_udp_open
int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep)
osmo_stats_reporter_free
void osmo_stats_reporter_free(struct osmo_stats_reporter *srep)
Destroy a given stats_reporter.
Definition stats.c:232
osmo_stats_reporter_set_name_prefix
int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix)
Set the name prefix of a given stats_reporter.
Definition stats.c:419
osmo_stats_reporter_set_flush_period
int osmo_stats_reporter_set_flush_period(struct osmo_stats_reporter *srep, unsigned int period)
Set the regular flush period for a given stats_reporter.
Definition stats.c:404
osmo_stats_reporter_set_remote_port
int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port)
osmo_stats_reporter_disable
int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep)
Disable the given stats_reporter.
Definition stats.c:442
osmo_stats_reporter_set_max_class
int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep, enum osmo_stats_class class_id)
Definition stats.c:370
osmo_stats_reporter_set_mtu
int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu)
osmo_stats_set_interval
int osmo_stats_set_interval(int interval)
Set the reporting interval (common for all reporters).
Definition stats.c:384
osmo_stats_reporter_udp_close
int osmo_stats_reporter_udp_close(struct osmo_stats_reporter *srep)
osmo_stats_reporter_find
struct osmo_stats_reporter * osmo_stats_reporter_find(enum osmo_stats_reporter_type type, const char *name)
Find a stats_reporter of given type and name.
Definition stats.c:256
osmo_stats_report
int osmo_stats_report(void)
Definition stats.c:790
osmo_stats_reporter_create_statsd
struct osmo_stats_reporter * osmo_stats_reporter_create_statsd(const char *name)
Create a stats_reporter reporting to statsd.
Definition stats_statsd.c:53
osmo_stats_reporter_set_remote_addr
int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr)
osmo_stats_reporter_type
osmo_stats_reporter_type
Statistics Reporter Type.
Definition stats.h:51
osmo_stats_reporter_create_log
struct osmo_stats_reporter * osmo_stats_reporter_create_log(const char *name)
Create a stats_reporter that logs via libosmocore logging.
Definition stats.c:572
osmo_stats_init
void osmo_stats_init(void *ctx)
Initialize the stats reporting module; call this once in your program.
Definition stats.c:241
osmo_stats_reporter_set_local_addr
int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr)
osmo_stats_reporter_enable
int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep)
Enable the given stats_reporter.
Definition stats.c:432
osmo_stats_reporter_send_buffer
int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep)
osmo_stats_reporter_send
int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data, int data_len)
osmo_stats_reporter_list
struct llist_head osmo_stats_reporter_list
osmo_stats_class
osmo_stats_class
Statistics Class definitions.
Definition stats.h:43
OSMO_STATS_REPORTER_LOG
@ OSMO_STATS_REPORTER_LOG
libosmocore logging
Definition stats.h:52
OSMO_STATS_REPORTER_STATSD
@ OSMO_STATS_REPORTER_STATSD
statsd backend
Definition stats.h:53
OSMO_STATS_CLASS_UNKNOWN
@ OSMO_STATS_CLASS_UNKNOWN
unknown class
Definition stats.h:44
OSMO_STATS_CLASS_PEER
@ OSMO_STATS_CLASS_PEER
peer in a communications link
Definition stats.h:46
OSMO_STATS_CLASS_GLOBAL
@ OSMO_STATS_CLASS_GLOBAL
global counter/stat_item
Definition stats.h:45
OSMO_STATS_CLASS_SUBSCRIBER
@ OSMO_STATS_CLASS_SUBSCRIBER
subscriber
Definition stats.h:47
data
uint8_t data[0]
type
uint8_t type
name
char name[32]
source file name
Definition gsmtap.h:11
linuxlist.h
Simple doubly linked list implementation.
desc
llist_head
(double) linked list header structure
Definition linuxlist.h:46
msgb
Osmocom message buffer.
Definition msgb.h:31
osmo_stat_item_desc
Statistics item description.
Definition stat_item.h:22
osmo_stat_item_group
One instance of a counter group class.
Definition stat_item.h:45
osmo_stats_config
Definition stats.h:103
osmo_stats_config::interval
int interval
Definition stats.h:104
osmo_stats_reporter
One statistics reporter instance.
Definition stats.h:57
osmo_stats_reporter::flush_period_counter
unsigned int flush_period_counter
count sends between forced flushes
Definition stats.h:88
osmo_stats_reporter::dest_port
int dest_port
destination (UDP) port
Definition stats.h:70
osmo_stats_reporter::dest_addr_len
int dest_addr_len
length of dest_addr in bytes
Definition stats.h:81
osmo_stats_reporter::bind_addr
struct sockaddr bind_addr
local bind address of socket
Definition stats.h:82
osmo_stats_reporter::force_single_flush
int force_single_flush
set to 1 to force a flush (send even unchanged stats values)
Definition stats.h:87
osmo_stats_reporter::send_counter
int(* send_counter)(struct osmo_stats_reporter *srep, const struct rate_ctr_group *ctrg, const struct rate_ctr_desc *desc, int64_t value, int64_t delta)
Definition stats.h:93
osmo_stats_reporter::have_net_config
unsigned int have_net_config
Definition stats.h:63
osmo_stats_reporter::fd
int fd
file descriptor of socket
Definition stats.h:84
osmo_stats_reporter::enabled
int enabled
is this reporter enabled
Definition stats.h:66
osmo_stats_reporter::close
int(* close)(struct osmo_stats_reporter *srep)
Definition stats.h:92
osmo_stats_reporter::mtu
int mtu
Maximum Transmission Unit.
Definition stats.h:71
osmo_stats_reporter::bind_addr_len
int bind_addr_len
length of bind_addr in bytes
Definition stats.h:83
osmo_stats_reporter::type
enum osmo_stats_reporter_type type
Type of the reporter (log, statsd).
Definition stats.h:59
osmo_stats_reporter::send_item
int(* send_item)(struct osmo_stats_reporter *srep, const struct osmo_stat_item_group *statg, const struct osmo_stat_item_desc *desc, int64_t value)
Definition stats.h:97
osmo_stats_reporter::max_class
enum osmo_stats_class max_class
Maximum class/index to report.
Definition stats.h:75
osmo_stats_reporter::agg_enabled
int agg_enabled
is aggregation enabled?
Definition stats.h:86
osmo_stats_reporter::buffer
struct msgb * buffer
message buffer for log output
Definition stats.h:85
osmo_stats_reporter::open
int(* open)(struct osmo_stats_reporter *srep)
Definition stats.h:91
osmo_stats_reporter::running
int running
is this reporter running
Definition stats.h:79
osmo_stats_reporter::name_prefix
char * name_prefix
prefix for counter names
Definition stats.h:67
osmo_stats_reporter::dest_addr_str
char * dest_addr_str
destination IP address
Definition stats.h:68
osmo_stats_reporter::list
struct llist_head list
Definition stats.h:90
osmo_stats_reporter::name
char * name
Human-readable name of this reporter.
Definition stats.h:61
osmo_stats_reporter::flush_period
unsigned int flush_period
period between regular flushes
Definition stats.h:72
osmo_stats_reporter::dest_addr
struct sockaddr dest_addr
destination address of socket
Definition stats.h:80
osmo_stats_reporter::bind_addr_str
char * bind_addr_str
local bind IP address
Definition stats.h:69
rate_ctr_desc
rate counter description
Definition rate_ctr.h:37
rate_ctr_group
One instance of a counter group class.
Definition rate_ctr.h:57