Commit Graph

33 Commits

Author SHA1 Message Date
Alexander Chemeris f5bdef4efd stats: Change timer to timerfd to make it a true interval timer.
Previously the interval between stats flushes would slowly increase
which would lead to reporting time jitter and confuse a timescale
database.

Change-Id: I23d8b5157ef8a9833ba16a81d9b28a126f303c30
2020-05-09 16:25:48 +03:00
Alexander Chemeris dfebf405e5 stats: Support regular stats flush
Reliable monitoring requires regular flush of all stat values, even
if they have not changed. Otherwise (1) the monitoring app has to
maintain state and (2) can go out of sync if it's restarted while
the app is still running.

Change-Id: I04f1e7bdf0d6f20e4f15571e94191de61c47ddad
2020-05-09 08:08:53 +00:00
Alexander Chemeris f203ed3add stats: Fix documentation for osmo_stats_set_interval()
Change-Id: Ie07a03251d6fe9d40b62815feb51ec8af9ed7c95
2020-05-09 08:08:53 +00:00
Harald Welte e08da97570 Fix/Update copyright notices; Add SPDX annotation
Let's fix some erroneous/accidential references to wrong license,
update copyright information where applicable and introduce a
SPDX-License-Identifier to all files.

Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
2017-11-13 01:35:12 +09:00
Harald Welte eb5b6ce444 [doc] Add Doxygen API documentation for stats.c and stats_statsd.c
Change-Id: I8e49505f5c19beac90290fdba8821714e8eecd97
2017-10-16 14:18:56 +02:00
Harald Welte 216338c369 Rename 'statistics.c' to 'counter.c'
With stat_item, stats.c and stats_statsd.c, it is becoming a bit
difficult to understand file naming.  Also, the 'statistics.c' file
actually only contained osmo_counter handling, so let's rename it to
counter.c altogether.

Change-Id: I2cfb2310543902b7da46cb15a76e2da317eaed7d
2017-10-15 19:51:35 +02:00
Neels Hofmeyr 17518fe393 doxygen: unify use of \file across the board
Considering the various styles and implications found in the sources, edit
scores of files to follow the same API doc guidelines around the doxygen
grouping and the \file tag.

Many files now show a short description in the generated API doc that was so
far only available as C comment.

The guidelines and reasoning behind it is documented at
https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation

In some instances, remove file comments and add to the corresponding group
instead, to be shared among several files (e.g. bitvec).

Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23 00:18:23 +00:00
Harald Welte 67bdd80a96 stats: Disable stats*.c on embedded targets
Change-Id: I6beb4fcc394ed7d3f8dd7a097b6e998245ecf401
2017-05-15 19:00:40 +02:00
Harald Welte 95871dadbd use osmo_{htonl,htons,ntohl,ntohs}() functions all over libosmocore
This gets us one step closer to fixing the embedded build

Change-Id: I3fc2639b6ade9ab138766987eceab7ec9498fdc7
2017-05-15 13:42:03 +02:00
Pablo Neira Ayuso 44f423f117 timer: add osmo_timer_setup()
Add a new function timer function to set up the timer, similar to what
we have in the Linux kernel. This patch also converts existing opencoded
timer setup in the libosmocore tree as initial client of this new
function.

This patch implicitly removes function callback passed by reference that
defeat compile time type validation.

Compile-tested only, but I ran make check that reports success when
testing timer infrastructure.

Change-Id: I2fa49972ecaab3748b25168b26d92034e9145666
2017-05-09 12:10:51 +02:00
Harald Welte 1554f80f5e statsd: Fix compiler warning (int32_t vs. int64_t)
Fixes the following compiler warning:

stats_statsd.c: In function ‘osmo_stats_reporter_create_statsd’: stats_statsd.c:54:18: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
  srep->send_item = osmo_stats_reporter_statsd_send_item;

Change-Id: Id36914906e0982f6ac092a311210727de66b343a
2016-11-11 15:24:24 +01:00
Arran Cudbard-Bell cc3694b650 Fix build for OSX
Change-Id: I580a500edcf4812e570be586890abef746083a8c
Reviewed-on: https://gerrit.osmocom.org/74
Tested-by: Jenkins Builder
Reviewed-by: Holger Freyther <holger@freyther.de>
2016-05-20 16:32:58 +00:00
Jacob Erlbeck 2e8f9ed556 stats: Reorder functions in stats.c
Due to prior refactoring, the functions do not have an sensible order
in the file. This commit tries to improve that a little bit.

Sponsored-by: On-Waves ehf
2015-11-26 12:52:24 +01:00
Jacob Erlbeck b6e6bea4ec stats: Move statsd related code into a separate file
This commit moves the stats specific code parts into stats_statsd.c
while keeping the generic parts in stats.c. The code in stats.c no
longer contains references to statsd symbols.

Note that the VTY code still needs to know about every stats reporter
backend.

Sponsored-by: On-Waves ehf
2015-11-26 12:52:24 +01:00
Jacob Erlbeck 01e8c91df5 stats: Fix not reported stat item values
Currently the global stat item index is being advanced in
osmo_stat_item_group_handler, so that the second and further groups
in the list will skip new item values.

This commit moves the call to osmo_stat_item_discard_all into
osmo_stats_report to a place where all groups have been processed
already.

Sponsored-by: On-Waves ehf
2015-11-09 14:49:52 +01:00
Jacob Erlbeck 8a97cb9111 stats: Fix handling of multiple resporters
Currently the reporter loop is aborted, if the event would be ignored
due to an insufficient max_level. Thus the reporters that happen to
be stored afterwards would be skipped even if their level were
sufficient.

This commit replaces the conditional 'return' statement by a
considtional 'continue' statement to ensure the processing of the
list tail.

Sponsored-by: On-Waves ehf
2015-11-09 14:49:52 +01:00
Jacob Erlbeck aed7c125fd stats: Send all values on reporter update
Currently only counter changes and new item values are being
reported. This makes it cumbersome to configure reporting clients,
since there is nothing like a list of all parameters.

This commit changes this behaviour such that all currently existing
counters and items that would be reported eventually, are passed to
the reporter when it has been reconfigured or enabled. If a counter
has not been incremented, 0 is sent. If a stat item value has not
been added, the last item value (or the default value if there is
none) is resent again.

Note that this will not catch transient counters/items that will be
created later on, e.g. triggered by new peers or subscribers.

To just force this kind of dump on a running reporter, it is
sufficient to invoke the 'enable' command in its configuration node.

Sponsored-by: On-Waves ehf
2015-11-09 14:49:49 +01:00
Jacob Erlbeck 916423ef95 stats: Fix name prefix handling
Currently the having an unset prefix leads to an abort() in the
statsd reporter due to an fprintf format string error. In addition
the prefix cannot be reset to its initial state (NULL) by using 'no
prefix', which just sets the prefix to the empty string, causing a
single leading dot to appear in front of the name.

This commit changes the implemenation to consistly use NULL for
the unset name prefix ('no prefix') and to handle this case correctly
in the statsd reporter.

Sponsored-by: On-Waves ehf
2015-11-09 10:52:19 +01:00
Holger Hans Peter Freyther c337693c4c stats: Fix build on FreeBSD
include stdint.h for int64_t and use netinet/in.h and not
netinet/ip.h for getting sockaddr_in and such.
2015-08-21 19:56:54 +00:00
Holger Hans Peter Freyther 7921975989 stats: Do not assign the wrong addresss
we need to put the default value into inaddr and not put a
32bit value into the addr pointer.

Spotted by cppcheck:
[src/stats.c:231]: (error) Uninitialized variable: inaddr
2015-11-02 15:50:32 +01:00
Holger Hans Peter Freyther 837e940627 stats: Remove warnings about never read variables
Nothing is being done with these return values. Remove them
for now and update the TODO entry that is present at two of
the three places.

stats.c: In function ‘rate_ctr_handler’:
stats.c:570:6: warning: variable ‘rc’ set but not used [-Wunused-but-set-variable]
  int rc;
      ^
stats.c: In function ‘osmo_stat_item_handler’:
stats.c:617:6: warning: variable ‘rc’ set but not used [-Wunused-but-set-variable]
  int rc;
      ^
stats.c: In function ‘handle_counter’:
stats.c:651:6: warning: variable ‘rc’ set but not used [-Wunused-but-set-variable]
  int rc;
2015-11-02 15:44:26 +01:00
Jacob Erlbeck 79125ecf7d log: Add new DLSTATS log level
This log level is used by the stats subsystem log reporter to report
statistics to level INFO. Note that the default level of DLSTATS is
NOTICE.

Sponsored-by: On-Waves ehf
2015-11-02 15:39:31 +01:00
Jacob Erlbeck bc9d9aced8 stats: Limit reporting by class id
This commit adds class_id fields to the rate_ctr and stat_item group
descriptions. The stats reporter code is extended to only process
groups whose class_id does not exceed a per reporter max_class level.

If the class_id is not set, the code assumes 'global' for groups with
idx == 0 and 'subscriber' otherwise.

The following vty command is added to config-stats:

  level (global|peer|subscriber)  Set the maximum group level

Sponsored-by: On-Waves ehf
2015-11-02 15:39:31 +01:00
Jacob Erlbeck 16fe8dab7c stats: Report group indices as unsigned int
Currently the unsigned group index value is silently being cast to
(signed) int in the log and statsd reporter code. If the resulting
value is negative (which can happen for instance with MMCTX
counters), the index is assumed to be unset.

This commit changes the affected types to unsigned. The index value 0
is then the only value indicating an unset group.

Sponsored-by: On-Waves ehf
2015-11-02 15:39:31 +01:00
Jacob Erlbeck fc9533d6c4 stats: Add osmo_ name prefix to identifiers
Since the the stat_item and stats functions and data types are meant
to be exported, they get an osmo_ prefix.

Sponsored-by: On-Waves ehf

[hfreyther: Prepended the enum values too. This was requested by
Jacob]
2015-11-02 15:39:01 +01:00
Jacob Erlbeck bc4f7ae512 stats: Add log reporter
This reporter passes the measurement values to the logging subsystem
as DSTATS (which is currently DLGLOBAL) level INFO messages.

Sponsored-by: On-Waves ehf
2015-10-29 01:10:07 +01:00
Jacob Erlbeck 490b38f57a stats: Use function pointers in reporter objects
Currently case statements are used to select the right reporter
functions. This makes it difficult to add new reporter types,
especially if they are not going to reside in the same file.

This commit introduces per reporter function pointer for
open, close, send_count, and send_item. They are checked for
non-NULL before being called or skipped.

Sponsored-by: On-Waves ehf
2015-10-29 01:10:07 +01:00
Jacob Erlbeck ed197fd4f9 stats: Make net config optional
To support reporters without network configuration, this commit
introduces the have_net_config flag to provide corresponding error
messages.

Sponsored-by: On-Waves ehf
2015-10-29 01:10:06 +01:00
Jacob Erlbeck d01acfcc75 stats: Support statsd Multi-Metric Packets
If the MTU is given, combine several messages into a single UDP
packet until the limit is reached. Flush all reporters after the
values have been scanned.

New vty commands (node config-stats):
  mtu <100-65535>     Enable multi-metric packets and set the maximum
                      packet size (in byte)
  no mtu              Disable multi-metric packets

Note that single messages that are longer than the given MTU (minus
28 octets protocol overhead) will be dropped.

Sponsored-by: On-Waves ehf
2015-10-29 01:10:06 +01:00
Jacob Erlbeck c8f47b600f stats: Add support for osmo_counters
This commit changes the reporting code to also show all modified
osmo_counter values. Since there is no grouping of these values, the
name string just consists of the optional prefix and the counter
name.

Sponsored-by: On-Waves ehf
2015-10-29 01:10:06 +01:00
Jacob Erlbeck c27671c109 stats: Report stat item values
Currently only rate counter are being supported.

This commit adds support for stat items. All groups are polled for
changed values.

Sponsored-by: On-Waves ehf
2015-10-29 01:10:06 +01:00
Jacob Erlbeck b1dbfb4c41 stats: Implement timer based reporting
This calls stats_flush in regular intervals which polls the
statistical values and calls the active reporters when values have
changed.

Sponsored-by: On-Waves ehf
2015-10-29 01:10:06 +01:00
Jacob Erlbeck 95bf828003 stats: Add the reporting framework
This commit provides the stats reporting framework that can manage
several types of measurement reporters. Initially support for
rate_ctr and the statsd protocol is included.

Sponsored-by: On-Waves ehf
2015-10-29 01:10:03 +01:00