Summary of the invention
Technical matters to be solved by this invention provides a kind of database monitoring method and device, to solve traditional database monitoring method for the monitored object with moment property, has the problem that wrong report is more, the warning accuracy rate is lower.
For solving the problems of the technologies described above,, the invention discloses following technical scheme according to specific embodiment provided by the invention:
A kind of database monitoring method comprises:
Need the monitored object of two verifications that zone bit is set to each, be used to identify image data and whether surpass threshold values;
Acquisition monitoring object data periodically, and compare with corresponding threshold values; If surpass threshold values, then when the two verification of needs, read corresponding marker bit, judge that according to this zone bit whether the data of last collection are also above threshold values, if then send warning message;
Then current comparative result is updated to this zone bit.
Preferably, described method also comprises: according to data acquiring frequency the verification number of times is set.
Wherein, described current comparative result comprises that image data surpasses threshold values and is no more than two kinds of results of threshold values.
Described method also comprises: to not needing the monitored object of two verifications, if image data surpasses respective thresholds, then directly send warning message.
A kind of database monitoring device comprises:
The zone bit storage unit is used for the monitored object of the two verifications of each needs is provided with zone bit, is used for identifying image data and whether surpasses threshold values;
Data acquisition and threshold values judging unit are used for periodically acquisition monitoring object data, and compare with corresponding threshold values; If surpass threshold values, then the message call transmitting element carries out pair verifications when the two verification of needs, then current comparative result is updated to the zone bit of correspondence in the zone bit storage unit;
Message sending unit is used for reading corresponding marker bit from the zone bit storage unit, judges according to this zone bit whether last image data also surpasses threshold values, if then send warning message.
Wherein, described data acquisition and threshold values judging unit are to not needing the monitored object of two verifications, and when image data surpassed respective thresholds, directly the message call transmitting element sent warning message.
Wherein, the different parameters number imported into by data acquisition and threshold values judging unit of described message sending unit judges whether to carry out two verifications.
The present invention also provides the database monitoring method under a kind of database mode, comprising:
Acquisition monitoring object data periodically, and be saved in database;
To the monitored object of the two verifications of needs, Query Database obtains up-to-date two records of monitored object, and compares with corresponding threshold values respectively;
If two the data of record all surpass threshold values, then send warning message.
Preferably, described method also comprises: the quantity of obtaining the monitored object record according to the data acquiring frequency setting from database.
A kind of database monitoring device comprises:
Data acquisition unit is used for periodically acquisition monitoring object data;
Database is used to preserve the monitored object data that data acquisition unit is gathered;
The threshold values judging unit is used for the monitored object to the two verifications of needs, and Query Database obtains up-to-date two records of monitored object, and compares with corresponding threshold values respectively; If two the data of record all surpass threshold values, message call transmitting element then;
Message sending unit is used to send warning message.
Wherein, described threshold values judging unit obtains the quantity of monitored object record from database according to the data acquiring frequency setting.
According to specific embodiment provided by the invention, the invention discloses following technique effect:
The monitored object that has moment property at the lock in the database, obstruction, database server load etc., the present invention adopts the mode of repeatedly verification, if the monitored object continuous several times all surpasses respective thresholds, just can send warning message, thereby reduced the number of times of wrong report, improved the accuracy of reporting to the police, for the safe operation of database provides sound assurance.Wherein, described verification number of times is to set according to the frequency of data acquisition.
The invention provides two kinds of implementations, a kind of is at the database that operates on Unix or the (SuSE) Linux OS, comes the ruuning situation of database is monitored by writing the shell script.With two examples that are verified as, at first by data acquisition and threshold values judging unit acquisition monitoring object data, and with corresponding threshold values relatively, if surpass threshold values, then when needs carry out two verification, the message call transmitting element obtains corresponding zone bit from the zone bit storage unit, if the last image data of this zone bit sign also surpasses threshold values, then sends warning message.Then, by data acquisition and threshold values judging unit updating mark position, what the assurance message sending unit read at every turn is last comparative result.
Another kind of implementation is to adopt database mode, data acquisition unit all is saved in the monitored object data that collect in the database, monitored object for the two verifications of needs, the threshold values judging unit is from two up-to-date records of data base querying, if the data of these two records all surpass threshold values, send warning message with regard to the message call transmitting element.
Preferably, because in actual applications, the monitoring of a lot of objects is all needed to use the function that sends message,, will bring great difficulty to the maintenance of program if in each monitoring script, all add the message sending function.Therefore,, described message sending unit is encapsulated, independently send the message script with one and realize for strengthening the maintainability of script.And the message sending unit of described encapsulation is supported conventional the transmission and two verification transmission dual mode simultaneously, distinguishes by the different parameters number of importing script into.
Embodiment
For above-mentioned purpose of the present invention, feature and advantage can be become apparent more, the present invention is further detailed explanation below in conjunction with the drawings and specific embodiments.
The monitored object that has moment property at the lock in the database, obstruction, database server load etc., the embodiment of the invention adopts the mode of repeatedly verification, if the monitored object continuous several times all surpasses respective thresholds, just can send warning message notification database managerial personnel, thereby reduced the number of times of wrong report, improved the accuracy of reporting to the police, for the safe operation of database provides sound assurance.
Wherein, the notion of described lock is meant in order to prevent that object from being revised simultaneously by two different users, database initialize this data structure of lock realize locking mechanism.This mechanism is used the queue structure that is called queuing in database, carries out lock in the mode of serial." queuing " is a kind of data structure of lock, and this mechanism is carried out work based on frist come,frist serve in the mode of serial.If the lock in the database is too much, promptly a lot of locks in time do not discharge, and so can greatly influence performance of database yet.
Obstruction is caused by lock, when wanting to add two kinds of incompatible locks in the row level of an object or table, according to frist come,frist serve, the session that proposes earlier to lock will obtain to lock resource, carry out relevant operation, and session afterwards will enter the lock formation, begin to occur waiting for that this wait is blocked exactly.If it is long to block the formation that forms, will influence the performance of performance of database and application server.
Database loads is the overall target of an expression database performance.
Exist some to have the monitored object of moment property characteristic in the database, wherein lock, obstruction, database loads be the most representative, will be that example describes below with the monitoring of lock, obstruction, database loads.The embodiment of the invention has adopted the repeatedly mode of verification, and repeatedly verification is meant whether continuous several times check monitored object data surpass threshold values, and the number of times of verification is relevant with the frequency of data acquisition, is verified as example with two times below.The embodiment of the invention also provides two kinds of monitor modes, and a kind of is script mode, and a kind of is database mode, below explanation respectively.
For script mode, be example with the oracle database that operates on Unix or the (SuSE) Linux OS, come the ruuning situation of database is monitored by writing some shell scripts.Wherein, script is a kind of programming language, and the shell script is a kind of script wherein.
With reference to Fig. 1, be the database monitoring method embodiment process flow diagram under the described script mode.
Step 101, the monitored object that needs is carried out two verifications is provided with zone bit, and this zone bit is used for identifying image data and whether surpasses threshold values.In the present embodiment, surpass threshold values, do not surpass with 0 expression with 1 expression.
Step 102, acquisition monitoring object data periodically, and compare with corresponding threshold values.At certain monitored object, at first move a series of Unix or Linux order, and the output result of order is saved in the file as image data; Then with the numerical value of image data number as lock, and relatively,, then continue step 103 if surpass threshold values to threshold values that should monitored object, if do not surpass, then continue step 105.
Step 103 when the data of current collection surpass threshold values, reads corresponding marker bit information.If be 1, show that last data of gathering have also surpassed threshold values, execution in step 104 is reported to the police; If be 0, show that last data of gathering do not surpass threshold values, current is to surpass threshold values for the first time, the data acquisition that also needs to continue next time need just can judge whether to report to the police, and forwards step 105 to.
Step 104 all surpasses threshold values when the numerical value of monitored object is double, will send warning message in modes such as mail, SMS, and notification database managerial personnel handle, and continue execution in step 105 then.
Step 105 finishing above-mentioned all processing, needs the updating mark position at last, and current comparative result is recorded zone bit.If the data of current collection have surpassed threshold values, then updating mark position information is 1; If the data of current collection do not surpass threshold values, then updating mark position information is 0.Promptly, all need to upgrade corresponding marker bit, guarantee to read that zone bit obtains is last comparative result at every turn regardless of comparative result.
The monitoring flow process of above-mentioned twice verification also is applicable to the situation of repeatedly verification, according to the frequency of data acquisition, also may carry out continuous three times or verification more frequently, and needs increase this moment zone bit is preserved comparative result several times.
Above-mentioned process description to the monitor procedure of two verification monitored object, and, still adopt traditional method for supervising for other monitored object, promptly when image data surpasses corresponding threshold values, just report to the police.
At above-mentioned steps, the present invention also provides a kind of database monitoring device embodiment.With reference to Fig. 2, be the database monitoring device example structure figure under the described script mode, described device mainly comprises zone bit storage unit 201, data acquisition and threshold values judging unit 202, message sending unit 203.
Described zone bit storage unit 201 is mainly used in preserves two verification monitor data zone bits, preserves with document form, and value is that 0 or 1,0 expression image data does not surpass threshold values, and 1 expression surpasses.202 pairs of zone bit storage unit 201 of data acquisition and threshold values judging unit have the renewal authority, and 203 pairs of zone bit storage unit 201 of message sending unit read authority.
Data acquisition and threshold values judging unit 202 at first move a series of Linux or Unix order, and the output result of order is saved in the middle of some files as image data; Then the numerical value of the monitored object that collects is compared with the threshold values of corresponding monitored object, if surpass threshold values, promptly notification message transmitting element 203 is handled.In order to realize two verifications, data acquisition and threshold values judging unit 202 also will be finished a function, be exactly the zone bit of the two verification monitored object of record, but this function need be after message call transmitting element 203 be handled the respective flag position in the updating mark position storage unit 201 again.
The concrete execution flow process of data acquisition and threshold values judging unit 202 is with reference to shown in Figure 3, from process flow diagram as can be seen, call earlier and send message elements 203, and then 1 zone bit that will identify comparative result writes in the zone bit storage element 201, and message sending unit 203 can read last zone bit information like this.And, if the numerical value of monitored object collection is no more than threshold values, the respective flag position in the zone bit storage unit 201 that also will upgrade in time.
Message sending unit 203 is mainly used in the situation of calling according to data acquisition and threshold values judging unit 202, sends warning message by modes such as mail, SMS.Message sending unit 203 can also be handled conventional send mode when handling two verification monitored object, promptly the monitored object that carries out once relatively surpassing threshold values is sent warning message.The number of parameters that message sending unit 203 is imported into according to data acquisition and threshold values judging unit 202 is distinguished and is carried out that two verifications send or carrying out routine sends, if what receive is 2 parameters, then carries out the routine transmission; If receive 3 parameters, then carry out two verifications and send.Wherein, the warning message content of the implication of first Can Shuo $1 for sending, the implication of second Can Shuo $2 is for sending the mode (modes such as mail or note) of message, and the implication of the 3rd Can Shuo $3 is for sending the particular type (lock, obstruction or database loads) of message.Concrete treatment scheme is with reference to shown in Figure 4, as follows:
At first judge the number of parameters of importing into, if 2, then Yi $2 mode sends Xiao Xi $1; If 3, then judge that according to Can Shuo $3 concrete monitored object is lock, blocks or database loads, read corresponding sign from zone bit storage unit 201 then, judge last zone bit information, if 1 Yi $2 mode sends Bao Jingxiaoxi $1, if 0 does not send warning message.
Preferably, because in actual applications, the monitoring of a lot of objects is all needed to use the function that sends message,, will bring great difficulty to the maintenance of program if in each monitoring script, all add the message sending function.Therefore,, described message sending unit is encapsulated, independently send the message script with one and realize for strengthening the maintainability of script.
Above method is mainly come two verifications of fulfillment database monitor data by the shell script, but can also realize by database.With reference to Fig. 5, be the database monitoring method embodiment process flow diagram under the described database mode, still describe with two examples that are verified as.
Step 501, acquisition monitoring object data periodically, and be saved in database;
Step 502, after each data acquisition was finished, to the monitored object of the two verifications of needs, Query Database obtained up-to-date two records of monitored object, and compares with corresponding threshold values respectively;
Step 503 if the data of two records all surpass threshold values, is then sent warning message.
Because the verification number of times is relevant with data acquiring frequency, so if adopt three times or repeatedly verification, only need obtain up-to-date three or many records from database and can realize repeatedly verification.
With reference to Fig. 6, be the database monitoring device example structure figure under the described database mode.Described device comprises data database 601, data acquisition unit 602, threshold values judging unit 603, message sending unit 604.What preserve in the described database 601 is the monitored object data of gathering.Data acquisition unit 602 is used for periodically acquisition monitoring object data, and is saved in the database 601, after finishing data acquisition at every turn, and notice threshold values judging unit 603.Threshold values judging unit 603 is used for Query Database 601, for realizing two verifications, only needs up-to-date two records of query monitor object to get final product, if two records all surpass respective thresholds, with regard to message call transmitting element 604.Message sending unit 604 is used to send warning message.
As from the foregoing, the difference of database mode and script mode is:
The first, under the database mode, need judge separate processes to data acquisition and threshold values, promptly realize by independent module;
Second, the supervising device of the two constitutes different, do not need to be provided with the zone bit storage unit under the database mode, and preserve the data of collection by database, the threshold values judging unit will utilize the database SQL statement to come whether monitor data is surpassed threshold values to judge;
The 3rd, under the database mode, message sending unit need not add the logic of two verifications, but relatively whether to be sent the judgement of warning message by threshold values judging unit Query Database and with threshold values.
In sum, use database mode, can inquire the historical data information of monitored object, this adopts the shell script mode not accomplish.But, adopt the shell script mode to realize two verifications, because do not need to dispose database in its architecture, so the special light-type that seems, arrangement is disposed easily, cost is lower, and has satisfied the needs of monitoring well.
More than to a kind of database monitoring method provided by the present invention and device, be described in detail, used specific case herein principle of the present invention and embodiment are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and core concept thereof; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, part in specific embodiments and applications all can change.In sum, this description should not be construed as limitation of the present invention.