2
* Copyright (C) Tildeslash Ltd. All rights reserved.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Affero General Public License version 3.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU Affero General Public License for more details.
12
* You should have received a copy of the GNU Affero General Public License
13
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
* In addition, as a special exception, the copyright holders give
16
* permission to link the code of portions of this program with the
17
* OpenSSL library under certain conditions as described in each
18
* individual source file, and distribute linked combinations
21
* You must obey the GNU Affero General Public License in all respects
22
* for all of the code used other than OpenSSL.
26
#ifndef NETSTATISTICS_INCLUDED
27
#define NETSTATISTICS_INCLUDED
31
* Facade for system specific network statistics.
33
* @author http://www.tildeslash.com/
34
* @see http://www.mmonit.com/
39
#define T NetStatistics_T
44
* Test if network statistics by IP address is supported.
45
* @return true if supported, false if not
47
int NetStatistics_isGetByAddressSupported();
51
* Get network statistics object for IP address. The object must be destroyed
52
* with NetStatistics_free() if no longer necessary.
53
* @param address IP address (e.g. "127.0.0.1" or "::1")
54
* @return Network statistics object. Use NetStatistics_update() to get the data.
56
T NetStatistics_createForAddress(const char *address);
60
* Get network statistics object for interface name. The object must be destroyed
61
* with NetStatistics_free() if no longer necessary.
62
* @param interface Network interface name (e.g. "eth0")
63
* @return Network statistics object. Use NetStatistics_update() to get the data.
65
T NetStatistics_createForInterface(const char *interface);
69
* Destroy a network statistics object and release allocated resources.
70
* @param S A network statistics object reference
72
void NetStatistics_free(T *S);
76
* Reset a network statistics object data.
77
* @param S A network statistics object
79
void NetStatistics_reset(T S);
83
* Update network statistics for object.
84
* @param S A network statistics object
85
* @exception AssertException If statistics cannot be fetched or the address/interface
88
void NetStatistics_update(T S);
92
* Get incoming bytes per second statistics.
93
* @param S A network statistics object
94
* @return Incoming bytes per second statistics.
96
long long NetStatistics_getBytesInPerSecond(T S);
100
* Get incoming bytes per minute statistics.
101
* @param S A network statistics object
102
* @param count Number of minutes, the returned statistics will be for range given by 'now - count' (count max = 60m)
103
* @return Incoming bytes per minute statistics.
105
long long NetStatistics_getBytesInPerMinute(T S, int count);
109
* Get total incoming bytes statistics.
110
* @param S A network statistics object
111
* @return Incoming bytes total.
113
long long NetStatistics_getBytesInTotal(T S);
117
* Get incoming link saturation.
118
* @param S A network statistics object
119
* @return Incoming link saturation percent or -1 the link has unknown speed.
121
double NetStatistics_getSaturationInPerSecond(T S);
125
* Get incoming bytes per hour statistics.
126
* @param S A network statistics object
127
* @param count Number of hours, the returned statistics will be for range given by 'now - count' (count max = 24h)
128
* @return Incoming bytes per hour statistics.
130
long long NetStatistics_getBytesInPerHour(T S, int count);
134
* Get incoming packets per second statistics.
135
* @param S A network statistics object
136
* @return Incoming packets per second statistics.
138
long long NetStatistics_getPacketsInPerSecond(T S);
142
* Get incoming packets per minute statistics.
143
* @param S A network statistics object
144
* @param count Number of minutes, the returned statistics will be for range given by 'now - count' (count max = 60m)
145
* @return Incoming packets per minute statistics.
147
long long NetStatistics_getPacketsInPerMinute(T S, int count);
151
* Get incoming packets per hour statistics.
152
* @param S A network statistics object
153
* @param count Number of hours, the returned statistics will be for range given by 'now - count' (count max = 24h)
154
* @return Incoming packets per hour statistics.
156
long long NetStatistics_getPacketsInPerHour(T S, int count);
160
* Get total incoming packets statistics.
161
* @param S A network statistics object
162
* @return Incoming packets total.
164
long long NetStatistics_getPacketsInTotal(T S);
168
* Get incoming errors per second statistics.
169
* @param S A network statistics object
170
* @return Incoming errors per second statistics.
172
long long NetStatistics_getErrorsInPerSecond(T S);
176
* Get incoming errors per minute statistics.
177
* @param S A network statistics object
178
* @param count Number of minutes, the returned statistics will be for range given by 'now - count' (count max = 60m)
179
* @return Incoming errors per minute statistics.
181
long long NetStatistics_getErrorsInPerMinute(T S, int count);
185
* Get incoming errors per hour statistics.
186
* @param S A network statistics object
187
* @param count Number of hours, the returned statistics will be for range given by 'now - count' (count max = 24h)
188
* @return Incoming errors per hour statistics.
190
long long NetStatistics_getErrorsInPerHour(T S, int count);
194
* Get total incoming errors statistics.
195
* @param S A network statistics object
196
* @return Incoming errors total.
198
long long NetStatistics_getErrorsInTotal(T S);
202
* Get outgoing bytes per second statistics.
203
* @param S A network statistics object
204
* @return Outgoing bytes per second statistics.
206
long long NetStatistics_getBytesOutPerSecond(T S);
210
* Get outgoing bytes per minute statistics.
211
* @param S A network statistics object
212
* @param count Number of minutes, the returned statistics will be for range given by 'now - count' (count max = 60m)
213
* @return Outgoing bytes per minute statistics.
215
long long NetStatistics_getBytesOutPerMinute(T S, int count);
219
* Get outgoing bytes per hour statistics.
220
* @param S A network statistics object
221
* @param count Number of hours, the returned statistics will be for range given by 'now - count' (count max = 24h)
222
* @return Outgoing bytes per hour statistics.
224
long long NetStatistics_getBytesOutPerHour(T S, int count);
228
* Get total outgoing bytes statistics.
229
* @param S A network statistics object
230
* @return Outgoing bytes total.
232
long long NetStatistics_getBytesOutTotal(T S);
236
* Get outgoing link saturation.
237
* @param S A network statistics object
238
* @return Outgoing link saturation percent or -1 the link has unknown speed.
240
double NetStatistics_getSaturationOutPerSecond(T S);
244
* Get outgoing packets per second statistics.
245
* @param S A network statistics object
246
* @return Outgoing packets per second statistics.
248
long long NetStatistics_getPacketsOutPerSecond(T S);
252
* Get outgoing packets per minute statistics.
253
* @param S A network statistics object
254
* @param count Number of minutes, the returned statistics will be for range given by 'now - count' (count max = 60m)
255
* @return Outgoing packets per minute statistics.
257
long long NetStatistics_getPacketsOutPerMinute(T S, int count);
261
* Get outgoing packets per hour statistics.
262
* @param S A network statistics object
263
* @param count Number of hours, the returned statistics will be for range given by 'now - count' (count max = 24h)
264
* @return Outgoing packets per hour statistics.
266
long long NetStatistics_getPacketsOutPerHour(T S, int count);
270
* Get total outgoing packets statistics.
271
* @param S A network statistics object
272
* @return Outgoing packets total.
274
long long NetStatistics_getPacketsOutTotal(T S);
278
* Get outgoing errors per second statistics.
279
* @param S A network statistics object
280
* @return Outgoing errors per second.
282
long long NetStatistics_getErrorsOutPerSecond(T S);
286
* Get outgoing errors per minute statistics.
287
* @param S A network statistics object
288
* @param count Number of minutes, the returned statistics will be for range given by 'now - count' (count max = 60m)
289
* @return Outgoing errors per minute.
291
long long NetStatistics_getErrorsOutPerMinute(T S, int count);
295
* Get outgoing errors per hour statistics.
296
* @param S A network statistics object
297
* @param count Number of hours, the returned statistics will be for range given by 'now - count' (count max = 24h)
298
* @return Outgoing errors per hour.
300
long long NetStatistics_getErrorsOutPerHour(T S, int count);
304
* Get total outgoing errors statistics.
305
* @param S A network statistics object
306
* @return Outgoing errors total
308
long long NetStatistics_getErrorsOutTotal(T S);
312
* Get interface state.
313
* @param S A network statistics object
314
* @return Interface state (0 = down, 1 = up)
316
int NetStatistics_getState(T S);
320
* Get interface speed (note: not all interface types support speed)
321
* @param S A network statistics object
322
* @return Interface speed [bps] (-1 = N/A)
324
long long NetStatistics_getSpeed(T S);
328
* Get interface duplex state (note: not all interface types support duplex)
329
* @param S A network statistics object
330
* @return Duplex state (-1 = N/A, 0 = half, 1 = full)
332
int NetStatistics_getDuplex(T S);