CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SQLMonitoringService.cc
Go to the documentation of this file.
1 #include "SQLMonitoringService.h"
2 #include "RelationalAccess/MonitoringException.h"
3 #include "CoralBase/MessageStream.h"
4 #include "CoralBase/TimeStamp.h"
5 #include "CoralKernel/Context.h"
6 #include "CoralKernel/IHandle.h"
8 
9 namespace cond
10 {
12  : active( false ), level( coral::monitor::Default ), stream()
13  {
14  }
15 
16  SessionMonitor::SessionMonitor( bool act, coral::monitor::Level lvl )
17  : active( act ), level( lvl ), stream()
18  {
19  }
20 
22  : coral::Service( key ),
23  m_events()
24  {
25  }
26 
28  {
29  }
30 
31  void SQLMonitoringService::setLevel( const std::string& contextKey, coral::monitor::Level level )
32  {
33  Repository::const_iterator rit;
34 
35  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
36  {
37  m_events[contextKey] = SessionMonitor();
38  m_monitoredDS.insert( contextKey );
39  }
40 
41  m_events[contextKey].level = level;
42 
43  if( level == coral::monitor::Off )
44  {
45  m_events[contextKey].active = false;
46  }
47  else
48  {
49  m_events[contextKey].active = true;
50  }
51  }
52 
53  coral::monitor::Level SQLMonitoringService::level( const std::string& contextKey ) const
54  {
55  Repository::const_iterator rit;
56 
57  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
58  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::level", this->name() );
59 
60  return (*rit).second.level;
61  }
62 
63  bool SQLMonitoringService::active( const std::string& contextKey ) const
64  {
65  Repository::const_iterator rit;
66 
67  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
68  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::active", this->name() );
69 
70  return (*rit).second.active;
71  }
72 
73  void SQLMonitoringService::enable( const std::string& contextKey )
74  {
75  Repository::iterator rit;
76 
77  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
78  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::enable", this->name() );
79 
80  (*rit).second.active = true;
81  }
82 
83  void SQLMonitoringService::disable( const std::string& contextKey )
84  {
85  Repository::iterator rit;
86 
87  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
88  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::disable", this->name() );
89 
90  (*rit).second.active = false;
91  }
92 
93  //relaxing filter on coral monitoring level due to a bug in the connection pool
95  {
96  Repository::iterator rit;
97 
98  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
99  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record( const std::string& , coral::monitor::Source, coral::monitor::Type, const std::string& )", this->name() );
100 
101  bool active = (*rit).second.active;
102  //coral::monitor::Level level = (*rit).second.level;
103 
104  if( active/* && (type & level)*/ )
105  {
106  (*rit).second.stream.push_back( coral::monitor::createEvent( source, type, description ) );
107  }
108  }
109 
111  {
112  Repository::iterator rit;
113 
114  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
115  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record( const std::string& , coral::monitor::Source, coral::monitor::Type, const std::string&, int )", this->name() );
116 
117  bool active = (*rit).second.active;
118  //coral::monitor::Level level = (*rit).second.level;
119 
120  if( active/* && (type & level)*/ )
121  {
122  (*rit).second.stream.push_back( coral::monitor::createEvent( source, type, description, data ) );
123  }
124  }
125 
127  {
128  Repository::iterator rit;
129 
130  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
131  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record( const std::string& , coral::monitor::Source, coral::monitor::Type, const std::string&, long long )", this->name() );
132 
133  bool active = (*rit).second.active;
134  //coral::monitor::Level level = (*rit).second.level;
135 
136  if( active/* && (type & level)*/ )
137  {
138  (*rit).second.stream.push_back( coral::monitor::createEvent( source, type, description, data ) );
139  }
140  }
141 
143  {
144  Repository::iterator rit;
145 
146  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
147  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record( const std::string& , coral::monitor::Source, coral::monitor::Type, const std::string&, double )", this->name() );
148 
149  bool active = (*rit).second.active;
150  //coral::monitor::Level level = (*rit).second.level;
151 
152  if( active/* && (type & level)*/ )
153  {
154  (*rit).second.stream.push_back( coral::monitor::createEvent( source, type, description, data ) );
155  }
156  }
157 
159  {
160  Repository::iterator rit;
161 
162  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
163  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record( const std::string& , coral::monitor::Source, coral::monitor::Type, const std::string&, const std::string& )", this->name() );
164 
165  bool active = (*rit).second.active;
166  //coral::monitor::Level level = (*rit).second.level;
167 
168  if( active /*&& (type & level)*/ )
169  {
170  (*rit).second.stream.push_back( coral::monitor::createEvent( source, type, description, data ) );
171  }
172  }
173 
174  const coral::IMonitoringReporter& SQLMonitoringService::reporter() const
175  {
176  return( static_cast<const coral::IMonitoringReporter&>(*this) );
177  }
178 
179  // The coral::IMonitoringReporter interface implementation
180  std::set< std::string > SQLMonitoringService::monitoredDataSources() const
181  {
182  return m_monitoredDS;
183  }
184 
185  void SQLMonitoringService::report( unsigned int /*level*/ ) const
186  {
187  Repository::const_iterator rit;
188  coral::MessageStream log( "MonitoringService" );
189 
190  // Dummy reporting so far
191  for( rit = m_events.begin(); rit != m_events.end(); ++rit )
192  reportForSession( rit, log );
193  }
194 
195  void SQLMonitoringService::report( const std::string& contextKey, unsigned int /* level */ ) const
196  {
197  Repository::const_iterator rit;
198 
199  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
200  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record", this->name() );
201 
202  // Dummy reporting so far
203  coral::MessageStream log( "MonitoringService" );
204 
205  reportForSession( rit, log );
206  }
207 
208  void SQLMonitoringService::reportToOutputStream( const std::string& contextKey, std::ostream& os, unsigned int /* level */ ) const
209  {
210  Repository::const_iterator rit;
211 
212  if( ( rit = m_events.find( contextKey ) ) == m_events.end() )
213  throw coral::MonitoringException( "Monitoring for session " + contextKey + " not initialized...", "MonitoringService::record", this->name() );
214 
215  // Dummy reporting so far
216  coral::MessageStream log( "MonitoringService" );
217 
218  reportForSession( rit, os );
219  }
220 
221  void SQLMonitoringService::reportOnEvent( EventStream::const_iterator& it, std::ostream& os ) const
222  {
223  std::string source("");
224  switch( it->m_source ) {
225  case coral::monitor::Application:
226  source = "Application";
227  break;
228  case coral::monitor::Session:
229  source = "Session";
230  break;
231  case coral::monitor::Transaction:
232  source = "Transaction";
233  break;
234  case coral::monitor::Statement:
235  source = "Statement";
236  break;
237  default:
238  source = "";
239  };
240 
241  std::string type("");
242  switch( it->m_type ) {
243  case coral::monitor::Info:
244  type = "Info";
245  break;
246  case coral::monitor::Time:
247  type = "Time";
248  break;
249  case coral::monitor::Warning:
250  type = "Warning";
251  break;
252  case coral::monitor::Error:
253  type = "Error";
254  break;
256  type = "Config";
257  break;
258  default:
259  type = "";
260  };
261 
262  if(it->m_source == coral::monitor::Statement || it->m_source == coral::monitor::Transaction)
263  {
264  os << boost::posix_time::to_iso_extended_string((*it).m_time.time()) << ": "
265  << source << "; "
266  << type << "; "
267  <<(*it).m_description << ";"<< std::endl;
268  }
269  }
270 
271 
272  void SQLMonitoringService::reportOnEvent( EventStream::const_iterator& it,coral::MessageStream& os ) const
273  {
274  std::string source("");
275  switch( it->m_source ) {
276  case coral::monitor::Application:
277  source = "Application";
278  break;
279  case coral::monitor::Session:
280  source = "Session";
281  break;
282  case coral::monitor::Transaction:
283  source = "Transaction";
284  break;
285  case coral::monitor::Statement:
286  source = "Statement";
287  break;
288  default:
289  source = "";
290  };
291 
292  std::string type("");
293  switch( it->m_type ) {
294  case coral::monitor::Info:
295  type = "Info";
296  break;
297  case coral::monitor::Time:
298  type = "Time";
299  break;
300  case coral::monitor::Warning:
301  type = "Warning";
302  break;
303  case coral::monitor::Error:
304  type = "Error";
305  break;
307  type = "Config";
308  break;
309  default:
310  type = "";
311  };
312 
313  if(it->m_source == coral::monitor::Statement || it->m_source == coral::monitor::Transaction)
314  {
315  os << boost::posix_time::to_iso_extended_string((*it).m_time.time()) << ": "
316  << source << "; "
317  << type << "; "
318  << (*it).m_description <<coral::MessageStream::flush;
319  }
320  }
321 
322  void SQLMonitoringService::reportForSession( Repository::const_iterator& it, std::ostream& os ) const
323  {
324  os << "Session: " << (*it).first << std::endl;
325  std::string lvl;
326  switch( (*it).second.level ) {
327  case (coral::monitor::Off) : lvl = "Off"; break;
328  case (coral::monitor::Minimal) : lvl = "Minimal"; break;
329  case (coral::monitor::Default) : lvl = "Default"; break;
330  case (coral::monitor::Debug) : lvl = "Debug"; break;
331  case (coral::monitor::Trace) : lvl = "Trace"; break;
332  default: lvl = "";
333  };
334  os << "Monitoring Level: " << lvl << std::endl;
335 
336  const EventStream& evsref = (*it).second.stream;
337  os << " Recorded " << evsref.size() << " events" << std::endl;
338 
339  for( EventStream::const_iterator evit = evsref.begin(); evit != evsref.end(); ++evit )
340  {
341  reportOnEvent( evit, os );
342  }
343  }
344 
345  void SQLMonitoringService::reportForSession( Repository::const_iterator& it, coral::MessageStream& os ) const
346  {
347  os << "Session: " << (*it).first;
348  std::string lvl;
349  switch( (*it).second.level ) {
350  case (coral::monitor::Off) : lvl = "Off"; break;
351  case (coral::monitor::Minimal) : lvl = "Minimal"; break;
352  case (coral::monitor::Default) : lvl = "Default"; break;
353  case (coral::monitor::Debug) : lvl = "Debug"; break;
354  case (coral::monitor::Trace) : lvl = "Trace"; break;
355  default: lvl = "";
356  };
357  os << " monitored at level: " << lvl;
358 
359  const EventStream& evsref = (*it).second.stream;
360  os << lvl << " has recorded " << evsref.size() << " events" << coral::MessageStream::endmsg;
361 
362  for( EventStream::const_iterator evit = evsref.begin(); evit != evsref.end(); ++evit )
363  {
364  reportOnEvent( evit, os );
365  }
366 
367  }
368 
369 } // namespace cond
370 
371 DEFINE_CORALSERVICE(cond::SQLMonitoringService,"COND/Services/SQLMonitoringService");
SQLMonitoringService(const std::string &)
type
Definition: HCALResponse.h:21
#define Default
Definition: vmac.h:108
virtual void disable(const std::string &contextKey)
void reportOnEvent(EventStream::const_iterator &it, std::ostream &os) const
#define DEFINE_CORALSERVICE(type, name)
virtual void record(const std::string &contextKey, coral::monitor::Source source, coral::monitor::Type type, const std::string &description)
virtual void reportToOutputStream(const std::string &contextKey, std::ostream &os, unsigned int level) const
virtual std::set< std::string > monitoredDataSources() const
virtual void report(unsigned int level) const
virtual void setLevel(const std::string &contextKey, coral::monitor::Level level)
std::vector< coral::monitor::Event::Record > EventStream
The raw stream of recorder monitoring events.
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
tuple description
Definition: idDealer.py:66
virtual const coral::IMonitoringReporter & reporter() const
The session related book-keeping of monitored events.
virtual void enable(const std::string &contextKey)
Repository m_events
The all events repository classified by the sessions&#39; keys.
void reportForSession(Repository::const_iterator &it, std::ostream &os) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
virtual coral::monitor::Level level(const std::string &contextKey) const
tuple level
Definition: testEve_cfg.py:34
volatile std::atomic< bool > shutdown_flag false
virtual bool active(const std::string &contextKey) const
tuple Config
Definition: helper.py:9
std::set< std::string > m_monitoredDS
const bool Debug
static std::string const source
Definition: EdmProvDump.cc:42