Persistent connection to database

2014-06-26
2014-06-30
  • Andres Gomez Casanova

    I am a DB2 DBA, and I have written Nagios plugins to monitor databases. However, I have a problem with connections, because each time a plugin is executed, a connection to the database is established.

    If there are too many elements to monitor in the database, there are too many connection, and that impacts the database.

    I have thought about creating a DB server-side plugin that keeps the connections open, and it just receives the requests from Nagios server. However, in order to do that, I need to have a daemon on the DB server, and deal with remote requests (NRPE, for example)

    I have found your project, and I would like to know if I can create a plugin for DB2, that keeps a connection (or a connection pool) opened to the database.

    As far as I have seen, it is possible, because JNRPE is a daemon (JVM), and it can keep a DB connection. However, I want to be sure of that, and that is why I created this forum.

    This problem exist for all databases, however the people is not concerned about that. It would be an opportunity for you to provide a solution for this issue.

     
  • Massimiliano Ziccardi

    Yes, it is possible,
    However, since JNRPE creates a new instance of the plugin for each execution,
    the only way to achieve that result would be using a static connection pool.

    Since we can use the same plugin for different kind of checks, than an idea could be to create e different
    connection pool for each different connection url, do you agree?

    Thank you very much!

    Regards,
    Massimilinao

     
  • Andres Gomez Casanova

    When you say that JNRPE creates a new instance, you mean something like: You instantiate an object via Class.forName, execute a standard method, and then the object should be destroyed by the garbage collector?

    About the connection, I have been thinking to use a Class with static method to get the only instance (singleton pattern). Is that a good way to do that?

     
  • Massimiliano Ziccardi

    When you say that JNRPE creates a new instance, you mean something like: You instantiate an object via Class.forName, execute a standard method, and then the object should be destroyed by the garbage collector?


    Yes


    About the connection, I have been thinking to use a Class with static method to get the only instance (singleton pattern). Is that a good way to do that?


    Correct.
    Moreover, I'm thinking of a way to notify your plugin for the shutdown event.
    For the moment, I guess the best solution is that you install a shutdown hook yourself to close the connection in the pool when JNRPE stops.

    Thank you for your contribution!

     
  • Massimiliano Ziccardi

    I have added a feature request to the tracker (https://jnrpe-tracker.atlassian.net/browse/JNRPE-12)

     
  • Andres Gomez Casanova

    Features requests are private, and not visible even for people registered in that site :(

     
  • Massimiliano Ziccardi

    Now you should be able to see them even if not authenticated.

    Thanks,
    Massimiliano

     
  • Massimiliano Ziccardi

    Hi Andres.

    If you'd like to give it a look, I've totally rewritten the way components were able to send/receive events.

    Now it would be easy for your connection pool to receive the JNRPE 'shutdown' event to be able to release all the connections.

    Everything you have to do to receive such event is:

    1. Create a method that takes a JNRPEStatusEvent object as parameter
    2. Annotate such method with the @Subscribe annotation
    3. Inside your plugin add a private variable of type IJNRPEExecutionContext (call it, for example, ctx)
    4. Annotate that variable with the @Inject annotation
    5. Register your class instance as an event listener with 'ctx.getEventBus().register(myclassIntsnace)

    Now your method will be called automatically when the JNRPE status changes.

    Received status can be (as of now):

    • STARTED
    • STOPPED
    • FAILED

    That's all!

    Any suggestion/comment is welcome!

    Regards,
    Massimiliano

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks