Go to the documentation of this file.00001
00002
00003 #include "ace/Monitor_Control/Solaris_Network_Interface_Monitor.h"
00004
00005 #if defined (ACE_HAS_KSTAT)
00006
00007 #include "ace/Log_Msg.h"
00008 #include "ace/OS_NS_stdio.h"
00009
00010 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00011
00012 namespace ACE
00013 {
00014 namespace Monitor_Control
00015 {
00016 Solaris_Network_Interface_Monitor::Solaris_Network_Interface_Monitor (
00017 const ACE_TCHAR *lookup_str)
00018 : value_ (0UL),
00019 start_ (0UL),
00020 lookup_str_ (lookup_str)
00021 {
00022 this->init ();
00023 }
00024
00025 void
00026 Solaris_Network_Interface_Monitor::update_i (void)
00027 {
00028 this->access_kstats (this->value_);
00029 this->value_ -= this->start_;
00030 }
00031
00032 void
00033 Solaris_Network_Interface_Monitor::clear_impl (void)
00034 {
00035 this->init ();
00036 }
00037
00038 void
00039 Solaris_Network_Interface_Monitor::init (void)
00040 {
00041 unsigned long i;
00042
00043 for (i = 0UL; i < MAX_LO_INTERFACES; ++i)
00044 {
00045 this->value_array_lo_[i] = 0UL;
00046 }
00047
00048 for (i = 0UL; i < MAX_HME_INTERFACES; ++i)
00049 {
00050 this->value_array_hme_[i] = 0UL;
00051 }
00052
00053 this->access_kstats (this->start_);
00054 }
00055
00056 void
00057 Solaris_Network_Interface_Monitor::access_kstats (
00058 ACE_UINT64 &which_member)
00059 {
00060 this->kstats_ = kstat_open ();
00061
00062 if (this->kstats_ == 0)
00063 {
00064 ACE_ERROR ((LM_ERROR,
00065 ACE_TEXT ("opening kstats file failed\n")));
00066 return;
00067 }
00068
00069 this->kstat_id_ = this->kstats_->kc_chain_id;
00070 int status = 0;
00071
00072 while (true)
00073 {
00074
00075 for (this->kstat_ = this->kstats_->kc_chain;
00076 this->kstat_ != 0;
00077 this->kstat_ = this->kstat_->ks_next)
00078 {
00079 if (ACE_OS::strcmp (this->kstat_->ks_class, "net") != 0)
00080 {
00081 continue;
00082 }
00083
00084 unsigned long ks_instance = this->kstat_->ks_instance;
00085
00086 if (ACE_OS::strcmp (this->kstat_->ks_module, "lo") == 0)
00087 {
00088
00089 if (this->lookup_str_ == ACE_TEXT ("obytes")
00090 || this->lookup_str_ == ACE_TEXT ("rbytes"))
00091 {
00092 continue;
00093 }
00094
00095 status = this->check_ks_module (ks_instance,
00096 MAX_LO_INTERFACES,
00097 "MAX_LO_INTERFACES",
00098 this->value_array_lo_,
00099 which_member);
00100
00101 if (status == -1)
00102 {
00103
00104 (void) kstat_close (this->kstats_);
00105 return;
00106 }
00107 else if (status == 1)
00108 {
00109
00110 break;
00111 }
00112 }
00113 else if (ACE_OS::strcmp (this->kstat_->ks_module, "hme") == 0
00114 || ACE_OS::strcmp (this->kstat_->ks_module, "bge") == 0)
00115 {
00116 status = this->check_ks_module (ks_instance,
00117 MAX_HME_INTERFACES,
00118 "MAX_HME_INTERFACES",
00119 this->value_array_hme_,
00120 which_member);
00121
00122 if (status == -1)
00123 {
00124
00125 (void) kstat_close (this->kstats_);
00126 return;
00127 }
00128 else if (status == 1)
00129 {
00130
00131 break;
00132 }
00133 }
00134 }
00135
00136 if (this->kstat_)
00137 {
00138 this->kstat_id_ = kstat_chain_update (this->kstats_);
00139
00140 if (! this->kstat_id_ > 0)
00141 {
00142 ACE_ERROR ((LM_ERROR, "kstat is is not > 0.\n"));
00143 break;
00144 }
00145 }
00146 else
00147 {
00148 break;
00149 }
00150 }
00151
00152 status = kstat_close (this->kstats_);
00153
00154 if (status != 0)
00155 {
00156 ACE_ERROR ((LM_ERROR,
00157 ACE_TEXT ("closing kstats file failed\n")));
00158 }
00159 }
00160
00161 int
00162 Solaris_Network_Interface_Monitor::check_ks_module (
00163 const unsigned long ks_instance,
00164 const unsigned long which_max,
00165 const char *max_str,
00166 ACE_UINT64 *value_array,
00167 ACE_UINT64 &which_member)
00168 {
00169 if (! (ks_instance < which_max))
00170 {
00171 ACE_ERROR_RETURN ((LM_ERROR,
00172 "%s exceeded.\n",
00173 max_str),
00174 -1);
00175 }
00176
00177
00178
00179
00180
00181
00182 kid_t kstat_id =
00183 kstat_read (this->kstats_, this->kstat_, 0);
00184
00185 if (kstat_id != this->kstat_id_)
00186 {
00187
00188 return 1;
00189 }
00190
00191 kstat_named_t *value =
00192 (kstat_named_t *) kstat_data_lookup (
00193 this->kstat_,
00194 ACE_TEXT_ALWAYS_CHAR (this->lookup_str_.rep ()));
00195
00196 if (value == 0)
00197 {
00198
00199 return 0;
00200 }
00201
00202 if (value->data_type != KSTAT_DATA_UINT32)
00203 {
00204 ACE_ERROR_RETURN ((LM_ERROR,
00205 "Wrong data type.\n"),
00206 -1);
00207 }
00208
00209
00210 value_array[ks_instance] +=
00211 value->value.ui32
00212 - static_cast<ACE_UINT32> (value_array[ks_instance]);
00213
00214 which_member += value_array[ks_instance];
00215
00216 return 0;
00217 }
00218 }
00219 }
00220
00221 ACE_END_VERSIONED_NAMESPACE_DECL
00222
00223 #endif