xrootd
XrdCmsMeter.hh
Go to the documentation of this file.
00001 #ifndef __CMS_METER__H
00002 #define __CMS_METER__H
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                        X r d C m s M e t e r . h h                         */
00006 /*                                                                            */
00007 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00011 /*                                                                            */
00012 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00033 #include "XrdSys/XrdSysError.hh"
00034 #include "XrdSys/XrdSysPthread.hh"
00035 #include "XrdOuc/XrdOucStream.hh"
00036 
00037 class XrdCmsMeter
00038 {
00039 public:
00040 
00041 int   calcLoad(int pcpu, int pio, int pload, int pmem, int ppag);
00042 
00043 int   calcLoad(int xload,int pdsk);
00044 
00045 int   FreeSpace(int &tutil);
00046 
00047 void  Init();
00048 
00049 int   isOn() {return Running;}
00050 
00051 int   Monitor(char *pgm, int itv);
00052 
00053 void  Record(int pcpu, int pnet, int pxeq,
00054              int pmem, int ppag, int pdsk);
00055 
00056 int   Report(int &pcpu, int &pnet, int &pxeq,
00057              int &pmem, int &ppag, int &pdsk);
00058 
00059 void *Run();
00060 
00061 void *RunFS();
00062 
00063 int   numFS() {return fs_nums;}
00064 
00065 unsigned int TotalSpace(unsigned int &minfree);
00066 
00067 enum  vType {manFS = 1, peerFS = 2};
00068 
00069 void  setVirtual(vType vVal) {Virtual = vVal;}
00070 
00071 void  setVirtUpdt() {cfsMutex.Lock(); VirtUpdt = 1; cfsMutex.UnLock();}
00072 
00073        XrdCmsMeter();
00074       ~XrdCmsMeter();
00075 
00076 private:
00077       void calcSpace();
00078       char Scale(long long inval, long &outval);
00079       void SpaceMsg(int why);
00080       void UpdtSpace();
00081 
00082 XrdOucStream  myMeter;
00083 XrdSysMutex   cfsMutex;
00084 XrdSysMutex   repMutex;
00085 long long     MinFree;  // Calculated only once
00086 long long     HWMFree;  // Calculated only once
00087 long long     dsk_lpn;  // Calculated only once
00088 long long     dsk_tot;  // Calculated only once
00089 long long     dsk_free;
00090 long long     dsk_maxf;
00091 int           dsk_util;
00092 int           dsk_calc;
00093 int           fs_nums;  // Calculated only once
00094 int           lastFree;
00095 int           lastUtil;
00096 int           noSpace;
00097 int           Running;
00098 long          MinShow;  // Calculated only once
00099 long          HWMShow;  // Calculated only once
00100 char          MinStype; // Calculated only once
00101 char          HWMStype; // Calculated only once
00102 char          Virtual;  // This is a virtual filesystem
00103 char          VirtUpdt; // Data changed for the virtul FS
00104 
00105 time_t        rep_tod;
00106 char         *monpgm;
00107 int           monint;
00108 pthread_t     montid;
00109 
00110 unsigned int  xeq_load;
00111 unsigned int  cpu_load;
00112 unsigned int  mem_load;
00113 unsigned int  pag_load;
00114 unsigned int  net_load;
00115 };
00116 
00117 namespace XrdCms
00118 {
00119 extern    XrdCmsMeter Meter;
00120 }
00121 #endif