1 |
<?xml version="1.0"?> |
2 |
|
3 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" |
4 |
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> |
5 |
|
6 |
<refentry id="get_network_stats"> |
7 |
|
8 |
<refentryinfo> |
9 |
<date>$Date: 2003/10/02 16:01:52 $</date> |
10 |
<releaseinfo>$Id: get_network_stats.xml,v 1.2 2003/10/02 16:01:52 tdb Exp $</releaseinfo> |
11 |
</refentryinfo> |
12 |
|
13 |
<refmeta> |
14 |
<refentrytitle>get_network_stats</refentrytitle> |
15 |
<manvolnum>3</manvolnum> |
16 |
<refmiscinfo>i-scream</refmiscinfo> |
17 |
</refmeta> |
18 |
|
19 |
<refnamediv> |
20 |
<refname>get_network_stats</refname> |
21 |
<refname>get_network_stats_diff</refname> |
22 |
<refpurpose>get network statistics</refpurpose> |
23 |
</refnamediv> |
24 |
|
25 |
<refsynopsisdiv> |
26 |
<funcsynopsis> |
27 |
<funcsynopsisinfo>#include <statgrab.h></funcsynopsisinfo> |
28 |
<funcprototype> |
29 |
<funcdef>network_stat_t *<function>get_network_stats</function></funcdef> |
30 |
<paramdef>int *<parameter>entries</parameter></paramdef> |
31 |
</funcprototype> |
32 |
<funcprototype> |
33 |
<funcdef>network_stat_t *<function>get_network_stats_diff</function></funcdef> |
34 |
<paramdef>int *<parameter>entries</parameter></paramdef> |
35 |
</funcprototype> |
36 |
</funcsynopsis> |
37 |
</refsynopsisdiv> |
38 |
|
39 |
<refsect1> |
40 |
<title>Description</title> |
41 |
<para> |
42 |
Both calls take a pointer to an int, |
43 |
<parameter>entries</parameter>, which is filled with the number |
44 |
of network interfaces the machine has. This is needed to know how |
45 |
many <structname>network_stat_t</structname> structures have been |
46 |
returned. A pointer is returned to the first |
47 |
<structname>network_stat_t</structname>. |
48 |
</para> |
49 |
<para> |
50 |
<function>get_network_stats</function> returns the network |
51 |
traffic stored in the kernel which holds the amount of data |
52 |
transferred since bootup. On some platforms, such as Solaris 7, |
53 |
this value is stored in a 32bit int, so wraps around when it |
54 |
reaches 4GB. Other platforms, such as Solaris 8, hold the value |
55 |
in a 64bit int, which wraps somewhere near 17 million terabytes. |
56 |
</para> |
57 |
<para> |
58 |
<function>get_network_stats_diff</function> is the same as |
59 |
<function>get_network_stats</function> except it will return the |
60 |
difference since the last call. So, for instance a call to |
61 |
<function>get_network_stats_diff</function> is made, and called |
62 |
again 5 seconds later. Over that time, 20 bytes of traffic was |
63 |
transmitted and 10 bytes received. Tx will store 20, rx will |
64 |
store 10 and systime will store 5. This function copes with wrap |
65 |
arounds by the O/S so should be seemless to use. |
66 |
</para> |
67 |
</refsect1> |
68 |
|
69 |
<refsect1> |
70 |
<title>Return Values</title> |
71 |
|
72 |
<para> |
73 |
All network statistics return a pointer to a structure of type |
74 |
<structname>network_stat_t</structname>. |
75 |
</para> |
76 |
|
77 |
<programlisting> |
78 |
typedef struct{ |
79 |
char *interface_name; |
80 |
long long tx; |
81 |
long long rx; |
82 |
time_t systime; |
83 |
}network_stat_t; |
84 |
</programlisting> |
85 |
|
86 |
<variablelist> |
87 |
<varlistentry> |
88 |
<term> |
89 |
<structfield>interface_name</structfield> |
90 |
</term> |
91 |
<listitem> |
92 |
<para> |
93 |
The name known to the operating system. |
94 |
(eg. on linux it might be eth0) |
95 |
</para> |
96 |
</listitem> |
97 |
</varlistentry> |
98 |
<varlistentry> |
99 |
<term> |
100 |
<structfield>tx</structfield> |
101 |
</term> |
102 |
<listitem> |
103 |
<para> |
104 |
The number of bytes transmitted. |
105 |
</para> |
106 |
</listitem> |
107 |
</varlistentry> |
108 |
<varlistentry> |
109 |
<term> |
110 |
<structfield>rx</structfield> |
111 |
</term> |
112 |
<listitem> |
113 |
<para> |
114 |
The number of bytes received. |
115 |
</para> |
116 |
</listitem> |
117 |
</varlistentry> |
118 |
<varlistentry> |
119 |
<term> |
120 |
<structfield>systime</structfield> |
121 |
</term> |
122 |
<listitem> |
123 |
<para> |
124 |
The time period over which <parameter>tx</parameter> |
125 |
and <parameter>rx</parameter> were transferred. |
126 |
</para> |
127 |
</listitem> |
128 |
</varlistentry> |
129 |
</variablelist> |
130 |
</refsect1> |
131 |
|
132 |
<refsect1> |
133 |
<title>Bugs</title> |
134 |
<para> |
135 |
On the very first call |
136 |
<function>get_network_stats_diff</function> will return the same |
137 |
as <function>get_network_stats</function>. After the first call |
138 |
it will always return the difference. |
139 |
</para> |
140 |
<para> |
141 |
On operating system that hold only 32bits of data there is a |
142 |
problem if the values wrap twice. For example, on Solaris 7 if |
143 |
9GB is transferred and the operating system wraps at 4GB, the |
144 |
<function>get_network_stats_diff</function> function will return |
145 |
5GB. |
146 |
</para> |
147 |
</refsect1> |
148 |
|
149 |
<refsect1> |
150 |
<title>See Also</title> |
151 |
|
152 |
<simplelist type="inline"> |
153 |
<member> |
154 |
<citerefentry> |
155 |
<refentrytitle>statgrab</refentrytitle> |
156 |
<manvolnum>3</manvolnum> |
157 |
</citerefentry> |
158 |
</member> |
159 |
</simplelist> |
160 |
</refsect1> |
161 |
|
162 |
<refsect1> |
163 |
<title>Website</title> |
164 |
|
165 |
<simplelist type="vert"> |
166 |
<member> |
167 |
<ulink url="http://www.i-scream.org">http://www.i-scream.org</ulink> |
168 |
</member> |
169 |
</simplelist> |
170 |
</refsect1> |
171 |
|
172 |
</refentry> |