xosview  1.23
About: xosview is an X Windows based system monitor (cpu, memory, swap and network usage; interrupt and serial activities; load average).
  Fossies Dox: xosview-1.23.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

nfsmeter.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 1994, 1995, 2002, 2006 by Mike Romberg ( mike.romberg@noaa.gov )
3 //
4 // Modifications to support dynamic addresses by:
5 // Michael N. Lipp (mnl@dtro.e-technik.th-darmstadt.de)
6 //
7 // This file may be distributed under terms of the GPL
8 //
9 
10 #include "nfsmeter.h"
11 #include <string.h>
12 #include <stdio.h>
13 #include <fstream>
14 // #include <iostream>
15 
16 #ifndef MAX
17 #define MAX(_a, _b) ((_a) > (_b) ? (_a) : (_b))
18 #endif
19 
20 static const char *NFSSVCSTAT = "/proc/net/rpc/nfsd";
21 static const char * NFSCLTSTAT = "/proc/net/rpc/nfs";
22 
23 NFSMeter::NFSMeter(XOSView *parent, const char *name, int nfields,
24  const char *fields, const char *statfile)
25  : FieldMeterGraph( parent, nfields, name, fields ){
26  _statfile = statfile;
27  _statname = name;
28 }
29 
31 }
32 
35 }
36 
38  : NFSMeter(parent, "NFSD", 4, "BAD/UDP/TCP/IDLE", NFSSVCSTAT ){
39  starttimer();
40 }
41 
43 }
44 
47 
48  setfieldcolor( 0, parent_->getResource( "NFSDStatBadCallsColor" ) );
49  setfieldcolor( 1, parent_->getResource( "NFSDStatUDPColor" ) );
50  setfieldcolor( 2, parent_->getResource( "NFSDStatTCPColor" ) );
51  setfieldcolor( 3, parent_->getResource( "NFSDStatIdleColor" ) );
52 
53  useGraph_ = parent_->isResourceTrue( "NFSDStatGraph" );
54  dodecay_ = parent_->isResourceTrue( "NFSDStatDecay" );
55  SetUsedFormat (parent_->getResource("NFSDStatUsedFormat"));
56  //useGraph_ = 1;
57  //dodecay_ = 1;
58  //SetUsedFormat ("autoscale");
59  //SetUsedFormat ("percent");
60 }
62 {
63  char buf[4096], name[64];
64  unsigned long netcnt, netudpcnt, nettcpcnt, nettcpconn;
65  unsigned long calls, badcalls;
66  int found;
67 
68  std::ifstream ifs(_statfile);
69 
70  if (!ifs) {
71  // cerr <<"Can not open file : " <<_statfile <<endl;
72  // parent_->done(1);
73  return;
74  }
75 
76  fields_[0] = fields_[1] = fields_[2] = 0; // network activity
77  stoptimer();
78 
79  name[0] = '\0';
80  found = 0;
81  while (!ifs.eof() && found != 2) {
82  ifs.getline(buf, 4096, '\n');
83  if (strncmp("net", buf, strlen("net")) == 0) {
84  sscanf(buf, "%s %lu %lu %lu %lu\n", name,
85  &netcnt, &netudpcnt, &nettcpcnt, &nettcpconn);
86  found++;
87  }
88  if (strncmp("rpc", buf, strlen("rpc")) == 0) {
89  sscanf(buf, "%s %lu %lu\n", name, &calls, &badcalls);
90  found++;
91  }
92  }
93 
94  float t = 1000000.0 / usecs();
95 
96  if (t < 0)
97  t = 0.1;
98 
99  maxpackets_ = MAX(netcnt, calls) - _lastNetCnt;
100  if (maxpackets_ == 0) {
101  maxpackets_ = netcnt;
102  } else {
103  fields_[0] = (badcalls - _lastBad) * t;
104  fields_[1] = (netudpcnt - _lastUdp) * t;
105  fields_[2] = (nettcpcnt - _lastTcp) * t;
106  }
107 
108  total_ = fields_[0] + fields_[1] + fields_[2];
109  if (total_ > maxpackets_)
110  fields_[3] = 0;
111  else {
113  fields_[3] = total_ - fields_[0] - fields_[1] - fields_[2];
114  }
115 
116  if (total_)
117  setUsed(fields_[0] + fields_[1] + fields_[2], total_);
118 
119  starttimer();
120  drawfields();
121 
122  _lastNetCnt = MAX(netcnt, calls);
123  _lastTcp = nettcpcnt;
124  _lastUdp = netudpcnt;
125  _lastBad = badcalls;
126 }
127 
129  : NFSMeter(parent, "NFS", 4, "RETRY/AUTH/CALL/IDLE", NFSCLTSTAT ){
130  starttimer();
131 }
132 
134 }
135 
138 
139  setfieldcolor( 0, parent_->getResource( "NFSStatReTransColor" ) );
140  setfieldcolor( 1, parent_->getResource( "NFSStatAuthRefrshColor" ) );
141  setfieldcolor( 2, parent_->getResource( "NFSStatCallsColor" ) );
142  setfieldcolor( 3, parent_->getResource( "NFSStatIdleColor" ) );
143 
144  useGraph_ = parent_->isResourceTrue( "NFSStatGraph" );
145  dodecay_ = parent_->isResourceTrue( "NFSStatDecay" );
146  SetUsedFormat (parent_->getResource("NFSStatUsedFormat"));
147  //SetUsedFormat ("autoscale");
148  //SetUsedFormat ("percent");
149 }
150 
152 {
153  char buf[4096], name[64];
154  unsigned long calls = 0, retrns = 0, authrefresh = 0, maxpackets_;
155 
156  std::ifstream ifs(_statfile);
157 
158  if (!ifs) {
159  // cerr <<"Can not open file : " <<_statfile <<endl;
160  // parent_->done(1);
161  return;
162  }
163 
164  fields_[0] = fields_[1] = fields_[2] = 0;
165  stoptimer();
166 
167  name[0] = '\0';
168  while (!ifs.eof()) {
169  ifs.getline(buf, 4096, '\n');
170  if (strncmp("rpc", buf, strlen("rpc")))
171  continue;
172  sscanf(buf, "%s %lu %lu %lu\n", name, &calls, &retrns, &authrefresh);
173  break;
174  }
175 
176  float t = 1000000.0 / usecs();
177 
178  if (t < 0)
179  t = 0.1;
180 
181  maxpackets_ = calls - _lastcalls;
182  if (maxpackets_ == 0) {
183  maxpackets_ = calls;
184  } else {
185  fields_[2] = (calls - _lastcalls) * t;
186  fields_[1] = (authrefresh - _lastauthrefresh) * t;
187  fields_[0] = (retrns - _lastretrns) * t;
188  }
189 
190  total_ = fields_[0] + fields_[1] + fields_[2];
191  if (total_ > maxpackets_)
192  fields_[3] = 0;
193  else {
194  total_ = maxpackets_;
195  fields_[3] = total_ - fields_[2] - fields_[1] - fields_[0];
196  }
197 
198  if (total_)
199  setUsed(fields_[0] + fields_[1] + fields_[2], total_);
200 
201  starttimer();
202  drawfields();
203 
204  _lastcalls = calls;
205  _lastretrns = retrns;
206  _lastauthrefresh = authrefresh;
207 }
virtual void checkResources(void)
virtual void drawfields(int mandatory=0)
double total_
Definition: fieldmeter.h:41
void setfieldcolor(int field, const char *color)
Definition: fieldmeter.cc:108
void setUsed(double val, double total)
Definition: fieldmeter.cc:76
double * fields_
Definition: fieldmeter.h:40
void SetUsedFormat(const char *const str)
Definition: fieldmeter.cc:60
XOSView * parent_
Definition: meter.h:52
void checkevent(void)
Definition: nfsmeter.cc:61
unsigned long _lastNetCnt
Definition: nfsmeter.h:64
unsigned long _lastBad
Definition: nfsmeter.h:64
unsigned long _lastUdp
Definition: nfsmeter.h:64
float maxpackets_
Definition: nfsmeter.h:61
~NFSDStats(void)
Definition: nfsmeter.cc:42
NFSDStats(XOSView *parent)
Definition: nfsmeter.cc:37
void checkResources(void)
Definition: nfsmeter.cc:45
unsigned long _lastTcp
Definition: nfsmeter.h:64
const char * _statfile
Definition: nfsmeter.h:32
double usecs(void)
Definition: nfsmeter.h:28
void stoptimer(void)
Definition: nfsmeter.h:27
void starttimer(void)
Definition: nfsmeter.h:26
~NFSMeter(void)
Definition: nfsmeter.cc:30
const char * _statname
Definition: nfsmeter.h:28
NFSMeter(XOSView *parent, const char *name, int nfields, const char *files, const char *statfile)
Definition: nfsmeter.cc:23
void checkResources(void)
Definition: nfsmeter.cc:33
const char * name(void) const
Definition: nfsmeter.h:24
NFSStats(XOSView *parent)
Definition: nfsmeter.cc:128
~NFSStats(void)
Definition: nfsmeter.cc:133
unsigned long _lastretrns
Definition: nfsmeter.h:48
unsigned long _lastcalls
Definition: nfsmeter.h:48
unsigned long _lastauthrefresh
Definition: nfsmeter.h:48
void checkevent(void)
Definition: nfsmeter.cc:151
void checkResources(void)
Definition: nfsmeter.cc:136
int isResourceTrue(const char *name)
Definition: xwin.h:89
const char * getResource(const char *name)
Definition: xwin.cc:362
static const char * NFSSVCSTAT
Definition: nfsmeter.cc:20
static const char * NFSCLTSTAT
Definition: nfsmeter.cc:21
#define MAX(_a, _b)
Definition: nfsmeter.cc:17