Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit 898f283bb2a545560e932aafde76fefb81a56c8e

  • avatar
  • Gustavo Duarte <gustavo @Gu…P.(none)>
  • Wed Apr 03 10:04:52 EDT 2013
Improves:
	+ Improvements in logs messages, changing levels of some lines.
	+ Add the file name to the line logs

BugFixes:
	Fix the format setting in log
  
77
88
99log = logging.getLogger("stats-consolidation")
10#log = logging.getLogger(__name__)
1110
1211class Consolidation:
1312
  
179179 info = (resource_name, )
180180 cursor.execute(insert, info)
181181 self.cnx.commit()
182 log.info('New Resource %s stored in DB', resource_name)
182183 except mysql.connector.Error as err:
183 log.info('MySQL on store_resource: %s %s', cursor.statement, err)
184 log.error('MySQL on store_resource: %s %s', cursor.statement, err)
184185
185186 cursor.close()
186187
199199 params = (rrd.get_user_hash(), rrd.get_uuid(), rrd.get_sn(), rrd.get_age(), rrd.get_school(), "1.0.0")
200200 cursor.execute(insert, params)
201201 self.cnx.commit()
202 log.debug('New User %s stored in DB', rrd.user_hash)
202203 except mysql.connector.Error as err:
203204 log.error('MySQL on store_user %s %s', cursor.statement, err)
204205
  
55from datetime import datetime
66
77
8#log = logging.getLogger(__name__)
98log = logging.getLogger("stats-consolidation")
109
1110
5050
5151
5252
53 print "******************************************"
54 print " creating a RRD instance "
55 print "start: " + str(datetime.fromtimestamp(float(self.date_start)))
56 print "end: " + str(datetime.fromtimestamp(float(self.date_end)))
57 print "PATH: " + path
58 print "RRD NAME: " + name
59 print "\n"
53 log.debug( '*******************************************')
54 log.debug( ' creating a RRD instance ')
55 log.debug( 'start: %s', str(datetime.fromtimestamp(float(self.date_start))))
56 log.debug( 'end: %s', str(datetime.fromtimestamp(float(self.date_end))))
57 log.debug( 'PATH: %s', path)
58 log.debug( 'RRD NAME: %s', name)
59 log.debug( '\n')
6060 try:
6161 self.rrd = rrdtool.fetch (str(os.path.join(path,name)), 'AVERAGE', '-r 60', '-s '+ self.date_start, '-e '+ self.date_end)
6262 except Exception as e:
6363 raise Exception("rrdtool.fetch: {0}".format(e))
64 print " DS "
64 log.debug(' DS ')
6565 for item in self.DS.keys():
6666 idx = self.get_ds_index (item)
6767 if idx != -1:
6868 self.DS[item] = idx
69 print "DS "+ item + ": " + str(self.DS[item])
7069 else:
71 print "DS "+ item + " not found in header"
72 print "***********************************************"
70 log.warning( 'DS %s not found in header of %s rrd file', item, name)
71 log.debug('***********************************************')
7372
7473 def get_ds_index(self, ds):
7574 i=0
8888 i=0
8989 found = False
9090
91 print "-------Calcule "+ ds_name +"-------"
91 log.debug('-------Calcule %s -------', ds_name)
9292 while i < len(self.rrd[self.data_item]):
9393 value = str(self.rrd[self.data_item][i][self.DS[ds_name]])
9494
101101 else:
102102 if found:
103103 if self.verify_interrupt(i, ds_name, prev_value):
104 print str(datetime.fromtimestamp(float(start))) + " -> " + str(datetime.fromtimestamp(float(end))) + ": " + prev_value
104 log.debug( '%s -> %s : %s',str(datetime.fromtimestamp(float(start))),
105 str(datetime.fromtimestamp(float(end))),
106 prev_value)
105107 res.append((start, prev_value))
106108 found = False
107109 prev_value = 0.0
108110 i=i+1
109111 return res
110 print "---------------------------------------------------"
112 log.debug('---------------------------------------------------')
111113
112114
113115 def get_active_by_interval (self):
122122 return self.rrd_name.partition(".rrd")[0]
123123
124124 def show_valid_ds(self, ds_name):
125 print "------------------- DS "+ ds_name +"---------------------"
125 log.debug('------------------- DS %s ---------------------', ds_name)
126126 i=0
127127 while i < len(self.rrd[self.data_item]):
128128 timestamp = str (long (self.date_start) + ((i+1) * 60))
129129 value = str (self.rrd[self.data_item][i][self.DS[ds_name]])
130130
131131 if value != "None":
132 print str(datetime.fromtimestamp(float(timestamp))) + " (" + timestamp + ")" + ": " + value
132 log.debug( '%s (%s): %s',str(datetime.fromtimestamp(float(timestamp))),
133 timestamp,
134 value)
133135 i=i+1
134 print "---------------------------------------------------"
136 log.debug('---------------------------------------------------')
135137
136138
137139 def get_date_last_record(self):
185185 value = str(self.rrd[self.data_item][i][self.DS[ds_name]])
186186 if value != "None":
187187 """
188 print "["+str(j)+ "] current value: " + value + " prev value: " + str (float (prev_value) + (60 * j)) + " ("+ prev_value+")"
188 log.debug( "["+str(j)+ "] current value: " + value + " prev value: " + str (float (prev_value) + (60 * j)) + " ("+ prev_value+")"
189189 """
190190 if float(value) > (float (prev_value) + (60 * j)):
191191 return False
  
3232args = parser.parse_args()
3333
3434
35_LOG_FORMAT='[%(asctime)s]-%(levelname)s-\'%(name)s\': %(message)s'
35_LOG_FORMAT='[%(asctime)s]-%(levelname)s-\'%(filename)s\': %(message)s'
3636_LOG_LEVEL = { 'debug': logging.DEBUG,
3737 'info': logging.INFO,
3838 'warning': logging.WARNING,
5757 db_user = config.get('main', 'db_user')
5858 db_pass = config.get('main', 'db_pass')
5959 rrd_path = config.get('main', 'rrd_path')
60
6061 LOG_FILENAME = os.path.join(log_path,'stats-consolidation.log')
61
6262 # Add the log message handler to the logger
6363 handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=10000000, backupCount=5)
64 handler.setFormatter(logging.Formatter(fmt=_LOG_FORMAT))
65 handler.setLevel(_LOG_LEVEL[log_level])
66
6467 log = logging.getLogger("stats-consolidation")
6568 log.setLevel(_LOG_LEVEL[log_level])
6669 log.addHandler(handler)