1414config_defaults = {
1515 "logdir" : "/var/log/mysql_flight_recorder" ,
1616 "pidfile" : "/tmp/mysql_flight_recorder.pid" ,
17+ "compresscmd" : "bzip2 -9" ,
1718}
1819
20+
1921class AlreadyRunningError (Exception ):
2022 """ Exception raised by pidfile if an instance of the process is already running. """
2123
@@ -93,7 +95,7 @@ def __repr__(self):
9395 str += f"CMD: { k } \n "
9496 i = 0
9597 for l in self .log [k ]:
96- i += 1
98+ i += 1
9799 str += f"{ i } : { l } \n "
98100 str += "\n "
99101
@@ -146,13 +148,13 @@ def update_version(self) -> None:
146148
147149 self .version = res ["version" ] # remember later for version comparisons
148150
149- self .log [cmd ] = [ res ["version" ] ]
151+ self .log [cmd ] = [res ["version" ]]
150152
151153 def update_uptime (self ) -> None :
152154 cmd : str = "show global status like 'Uptime'"
153155 cursor = self ._query (cmd )
154156 res = cursor .fetchone ()
155- self .log [cmd ] = [ res ["Value" ]]
157+ self .log [cmd ] = [res ["Value" ]]
156158
157159 def update_processlist (self ) -> None :
158160 cmd : str = "show full processlist"
@@ -166,7 +168,7 @@ def update_replica(self) -> None:
166168
167169 l = []
168170 for k , v in res .items ():
169- l .append (f"{ k } : { v } " )
171+ l .append (f"{ k } : { v } " )
170172
171173 self .log [cmd ] = l
172174
@@ -175,7 +177,7 @@ def update_innodb_status(self) -> None:
175177 cursor = self ._query (cmd )
176178 res = cursor .fetchone ()
177179
178- self .log [cmd ] = [ res ["Status" ] ]
180+ self .log [cmd ] = [res ["Status" ] ]
179181
180182 def update_innodb_trx (self ) -> None :
181183 cmd : str = "select /*+ max_execution_time(10000) */ * from information_schema.innodb_trx"
@@ -191,7 +193,6 @@ def update_innodb_locks(self) -> None:
191193 cursor = self ._query (cmd )
192194 self .log [cmd ] = cursor .fetchall ()
193195
194-
195196 def update_innodb_lock_waits (self ) -> None :
196197 table = "information_schema.innodb_lock_waits"
197198 if LooseVersion (self .version ) > LooseVersion ("8.0.1" ):
@@ -216,6 +217,16 @@ def update_innodb_metrics(self) -> None:
216217 cursor = self ._query (cmd )
217218 self .log [cmd ] = cursor .fetchall ()
218219
220+ def update_status (self ) -> None :
221+ cmd : str = "show global status"
222+ cursor = self ._query (cmd )
223+ self .log [cmd ] = cursor .fetchall ()
224+
225+ def update_variables (self ) -> None :
226+ cmd : str = "show global variables"
227+ cursor = self ._query (cmd )
228+ self .log [cmd ] = cursor .fetchall ()
229+
219230 def update_all (self ) -> None :
220231 self .log = {}
221232 self .update_version ()
@@ -231,7 +242,15 @@ def update_all(self) -> None:
231242 self .update_innodb_cmp ()
232243 self .update_innodb_cmpmem ()
233244 self .update_innodb_metrics ()
245+ self .update_status ()
246+ self .update_variables ()
234247
248+ def write (self , section : str ) -> None :
249+ """ writes data to file ./section_hh_mm (current directory set by create_logdir() """
250+ hhmm = datetime .now ().strftime ("%H_%M" )
251+ filename = f"{ section } _{ hhmm } "
252+ with open (filename , "w" ) as f :
253+ f .write (str (self ))
235254
236255def which (program : str ) -> Optional [str ]:
237256 fpath , fname = os .path .split (program )
@@ -308,6 +327,12 @@ def getconfig(defaults: dict) -> configparser.ConfigParser:
308327 probes [section ] = Probe (** connparms )
309328
310329 for probe in probes :
311- print ( f"Update { probe } ..." )
330+ # collect data from MySQL
312331 probes [probe ].update_all ()
313- print (f"{ probes [probe ]} " )
332+
333+ # Write data to file
334+ probes [probe ].write (probe )
335+
336+ # Compress data
337+ # if config[probe]["compresscmd"]:
338+ # subprocess.run()
0 commit comments