"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/linux/nfsmeter.cc" (11 Jul 2020, 5215 Bytes) of package /linux/misc/xosview-1.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "nfsmeter.cc" see the Fossies "Dox" file reference documentation.

    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 
   30 NFSMeter::~NFSMeter( void ){
   31 }
   32 
   33 void NFSMeter::checkResources( void ){
   34   FieldMeterGraph::checkResources();
   35 }
   36 
   37 NFSDStats::NFSDStats(XOSView *parent)
   38   : NFSMeter(parent, "NFSD", 4, "BAD/UDP/TCP/IDLE", NFSSVCSTAT ){
   39     starttimer();
   40 }
   41 
   42 NFSDStats::~NFSDStats( void ) {
   43 }
   44 
   45 void NFSDStats::checkResources( void ){
   46   NFSMeter::checkResources();
   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 }
   61 void NFSDStats::checkevent(void)
   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 {
  112         total_ = maxpackets_;
  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 
  128 NFSStats::NFSStats(XOSView *parent)
  129   : NFSMeter(parent, "NFS", 4, "RETRY/AUTH/CALL/IDLE", NFSCLTSTAT ){
  130     starttimer();
  131 }
  132 
  133 NFSStats::~NFSStats( void ) {
  134 }
  135 
  136 void NFSStats::checkResources( void ){
  137   NFSMeter::checkResources();
  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 
  151 void NFSStats::checkevent(void)
  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 }