/
stats.R
90 lines (88 loc) · 3.54 KB
/
stats.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright (C) 2023 Hibiki AI Limited <info@hibiki-ai.com>
#
# This file is part of nanonext.
#
# nanonext 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 3 of the License, or (at your option) any later
# version.
#
# nanonext 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.
#
# You should have received a copy of the GNU General Public License along with
# nanonext. If not, see <https://www.gnu.org/licenses/>.
# nanonext - Stats -------------------------------------------------------------
#' Get Statistic for a Socket, Listener or Dialer
#'
#' Obtain value of a statistic for a Socket, Listener or Dialer. This function
#' exposes the stats interface of NNG.
#'
#' @param object a Socket, Listener or Dialer.
#' @param name character name of statistic to return.
#'
#' @return The value of the statistic (character or double depending on the type
#' of statistic requested) if available, or else NULL.
#'
#' @details Note: the values of individual statistics are guaranteed to be
#' atomic, but due to the way statistics are collected there may be
#' discrepancies between them at times. For example, statistics counting
#' bytes and messages received may not reflect the same number of messages,
#' depending on when the snapshot is taken. This potential inconsistency
#' arises as a result of optimisations to minimise the impact of statistics
#' on actual operations.
#'
#' @section Stats:
#'
#' The following stats may be requested for a Socket:
#' \itemize{
#' \item 'id' - numeric id of the socket.
#' \item 'name' - character socket name.
#' \item 'protocol' - character protocol type e.g. 'bus'.
#' \item 'pipes' - numeric number of pipes (active connections).
#' \item 'dialers' - numeric number of listeners attached to the socket.
#' \item 'listeners' - numeric number of dialers attached to the socket.
#' }
#'
#' The following stats may be requested for a Listener / Dialer:
#' \itemize{
#' \item 'id' - numeric id of the listener / dialer.
#' \item 'socket' - numeric id of the socket of the listener / dialer.
#' \item 'url' - character URL address.
#' \item 'pipes' - numeric number of pipes (active connections).
#' }
#'
#' The following additional stats may be requested for a Listener:
#' \itemize{
#' \item 'accept' - numeric total number of connection attempts, whether
#' successful or not.
#' \item 'reject' - numeric total number of rejected connection attempts
#' e.g. due to incompatible protocols.
#' }
#'
#' The following additional stats may be requested for a Dialer:
#' \itemize{
#' \item 'connect' - numeric total number of connection attempts, whether
#' successful or not.
#' \item 'reject' - numeric total number of rejected connection attempts
#' e.g. due to incompatible protocols.
#' \item 'refused' - numeric total number of refused connections e.g. when
#' starting synchronously with no listener on the other side.
#' }
#'
#' @examples
#' s <- socket("bus", listen = "inproc://stats")
#' stat(s, "pipes")
#'
#' s1 <- socket("bus", dial = "inproc://stats")
#' stat(s, "pipes")
#'
#' close(s1)
#' stat(s, "pipes")
#'
#' close(s)
#'
#' @export
#'
stat <- function(object, name) .Call(rnng_stats_get, object, name)