[Rabbit-dev] Logging Usage

Luis Soltero lsoltero at globalmarinenet.com
Thu Aug 18 07:52:34 CEST 2011


Hi Robo,

almost there just need a little help...

here is my entries in rabbit.conf.  Note taht SQLBlockFilter works perfectly. I am using the same db but a different
table for the proxy_stats.  The SQL statement was verified manually so I know its good.

[rabbit.filter.SQLBlockFilter]
resource=jdbc/user_database
select=select 1 from banedhosts where hostname=?

[rabbit.proxy.GMNTrafficLogger]
resource=jdbc/user_database
select=insert into proxy_stats (username,client_read,client_write,network_read,network_write,last_access) values
(?,?,?,?,?,DEFAULT) ON DUPLICATE KEY UPDATE client_read=client_read+?, client_write=client_write+?,
network_read=network_read+?, network_write=network_write+?, last_access=DEFAULT

Here is my custom sql traffic logger...

public class GMNTrafficLogger implements ClientTrafficLogger {
    private DataSourceHelper dsh;
    private final Logger logger = Logger.getLogger (getClass ().getName ());
    private final String DEFAULT_SQL =
        "insert into proxy_stats (username) values (?) ON DUPLICATE KEY UPDATE username=?";

    public void logTraffic (String user, HttpHeader request,
                            TrafficLogger client, TrafficLogger network,
                            TrafficLogger cache, TrafficLogger proxy) {

//      System.out.println ("user: " + user +
//                          ", url: " + request.getRequestURI () +
//                          ", client read: " + client.read () +
//                          ", client write: " + client.write () +
//                          ", network read: " + network.read () +
//                          ", network write: " + network.write ());

       try {  
            java.sql.Connection db = dsh.getConnection ();
            try {
                PreparedStatement ps = db.prepareStatement (dsh.getSelect ());
                try {
                    ps.setString (1, user);
                    ps.setLong (2, client.read());
                    ps.setLong (3, client.write());
                    ps.setLong (4, network.read());
                    ps.setLong (5, network.write());
                    ps.setLong (6, client.read());
                    ps.setLong (7, client.write());
                    ps.setLong (8, network.read());
                    ps.setLong (9, network.write());
                    ResultSet rs = ps.executeQuery ();
                    rs.close ();
                } finally {
                    ps.close ();
                }
            } finally {
                db.close ();
            }
        } catch (SQLException e) {
            logger.log (Level.WARNING,
                        "Failed to get database connection",
                        e);
        }
    }

    /** Setup this class with the given properties.
     * @param props the new configuration of this class.
     */
    public void setup (SProperties props, HttpProxy proxy) {
        try {
            dsh = new DataSourceHelper (props, DEFAULT_SQL);
        } catch (NamingException e) {
            throw new RuntimeException (e);
        }
    }

I am getting a null exception

Exception in thread "pool-1-thread-2" java.lang.NullPointerException
    at rabbit.proxy.GMNTrafficLogger.logTraffic(GMNTrafficLogger.java:40)
    at rabbit.proxy.ClientTrafficLoggerHandler.logTraffic(ClientTrafficLoggerHandler.java:52)
    at rabbit.proxy.Connection.logConnection(Connection.java:1175)
    at rabbit.proxy.Connection.internalLogAndTryRestart(Connection.java:1156)
    at rabbit.proxy.Connection.access$900(Connection.java:44)
    at rabbit.proxy.Connection$2.run(Connection.java:1147)
    at org.khelekore.rnio.impl.StatisticsCollector.run(StatisticsCollector.java:37)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

which is at
40:               PreparedStatement ps = db.prepareStatement (dsh.getSelect ());
 
which suggests that my setup method is not being called.

Any pointers would greatly be appreciated...

Thanks,

--luis



On 8/17/11 4:20 PM, Robert Olofsson wrote:
> On Wed, 17 Aug 2011 16:06:43 -0400
> Luis Soltero <lsoltero at globalmarinenet.com> wrote:
>
>> It sounds like writing our own logger is probably the best way to do that but I have no idea how.  Would it be possible
>> to create a template that we could use as a starting point.  In the end we will want to execute sql statements to update
>> table entries in the db.
> Take a look at the StandardOutTrafficLogger that I made, consider it a 
> very basic template. You probably want to look at SQLBlockFilter to 
> see how to handle the database connection.
>
> I thought about writing an example sql traffic logger, but I did not
> figure out what values would be good to log in the general case.
>
> /robo
>


-- 


Luis Soltero, Ph.D., MCS
Director of Software Development, CTO
Global Marine Networks, LLC
StarPilot, LLC
Tel: 865-379-8723
Fax: 865-681-5017
E-Mail: lsoltero at globalmarinenet.net
Web: http://www.globalmarinenet.net
Web: http://www.starpilotllc.com





More information about the Rabbit-dev mailing list