1 // Copyright (C) 2009-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 #include <sipwitch-config.h>
18 #include <ucommon/ucommon.h>
19 #include <ucommon/export.h>
22
23 namespace sipwitch {
24
25 static unsigned used = 0, total = 7;
26 static stats *base = NULL;
27
29 {
30 public:
31 sta();
32
33 void init(void);
34 } shm;
35
37 {
38 }
39
40 void sta::init(void)
41 {
43 ::remove(statmap);
44 create(statmap, total);
45 }
46
48 {
49 shm.init();
56 return base;
57 }
58
60 {
61 assert(id && *id);
62
64 return NULL;
65
66 stats *node = shm(used++);
67 snprintf(node->
id,
sizeof(node->
id),
"%s",
id);
68 return node;
69 }
70
72 {
73 assert(count > 0);
74
76 }
77
79 {
80 return data[0].current +
data[1].current;
81 }
82
84 {
85 Mutex::protect(this);
88 ++
data[entry].current;
90 data[entry].peak =
data[entry].current;
92 data[entry].max =
data[entry].current;
93 Mutex::release(this);
94 if(this != base)
96 }
97
99 {
100 shm.release();
102 }
103
105 {
106 Mutex::protect(this);
109 --
data[entry].current;
111 data[entry].min =
data[entry].current;
112 Mutex::release(this);
113 if(this != base)
115 }
116
118 {
119 unsigned pos = 0;
120 char text[80];
121 size_t len;
122 time_t last;
123
125 stats *node = shm(pos++);
127 continue;
128
129 if(fp) {
130 snprintf(text,
sizeof(text),
" %-12s", node->
id);
131 len = strlen(text);
132 }
133 else
134 len = 0;
135
136 Mutex::protect(node);
137 for(unsigned entry = 0; entry < 2; ++entry) {
138 if(fp) {
139 snprintf(text + len, sizeof(text) - len, " %09lu %05hu %05hu",
141 len = strlen(text);
142 }
148 }
150 Mutex::release(node);
151 if(fp)
152 fprintf(fp, "%s %ld\n", text, (long)last);
153 }
154 }
155
156 } // end namespace
A stat element of call traffic.
static stats * create(void)
Create stats in shared memory pool.
void assign(stat_t element)
Assign a call to inbound or outbound statistic for this stat node.
Basic server call statistics.
unsigned active(void) const
Total number of active calls in the server at the moment.
static stats * request(const char *id)
Request a stat node from the memory pool by id.
void release(stat_t element)
Release a call from inbound or outbound stastic for this stat node.
static void release(void)
Release stat nodes shared memory segment.
Manage control interface.
struct sipwitch::stats::@9 data[2]
We have stats for both incoming and outgoing traffic of various kinds.
static void allocate(unsigned count)
Server allocate x number of stat nodes at startup.
static const char * env(const char *id)
Return the value of a server environment variable.