package org.apache.cassandra.metrics;
import java.net.InetAddress;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics;
import org.apache.cassandra.net.OutboundTcpConnectionPool;
public class ConnectionMetrics
{
public static final String TYPE_NAME = "Connection";
public static final Meter totalTimeouts = Metrics.meter(DefaultNameFactory.createMetricName(TYPE_NAME, "TotalTimeouts", null));
public final String address;
public final Gauge<Integer> largeMessagePendingTasks;
public final Gauge<Long> largeMessageCompletedTasks;
public final Gauge<Long> largeMessageDroppedTasks;
public final Gauge<Integer> smallMessagePendingTasks;
public final Gauge<Long> smallMessageCompletedTasks;
public final Gauge<Long> smallMessageDroppedTasks;
public final Gauge<Integer> gossipMessagePendingTasks;
public final Gauge<Long> gossipMessageCompletedTasks;
public final Gauge<Long> gossipMessageDroppedTasks;
public final Meter timeouts;
private final MetricNameFactory factory;
public ConnectionMetrics(InetAddress ip, final OutboundTcpConnectionPool connectionPool)
{
address = ip.getHostAddress().replace(':', '.');
factory = new DefaultNameFactory("Connection", address);
largeMessagePendingTasks = Metrics.register(factory.createMetricName("LargeMessagePendingTasks"), new Gauge<Integer>()
{
public Integer getValue()
{
return connectionPool.largeMessages.getPendingMessages();
}
});
largeMessageCompletedTasks = Metrics.register(factory.createMetricName("LargeMessageCompletedTasks"), new Gauge<Long>()
{
public Long getValue()
{
return connectionPool.largeMessages.getCompletedMesssages();
}
});
largeMessageDroppedTasks = Metrics.register(factory.createMetricName("LargeMessageDroppedTasks"), new Gauge<Long>()
{
public Long getValue()
{
return connectionPool.largeMessages.getDroppedMessages();
}
});
smallMessagePendingTasks = Metrics.register(factory.createMetricName("SmallMessagePendingTasks"), new Gauge<Integer>()
{
public Integer getValue()
{
return connectionPool.smallMessages.getPendingMessages();
}
});
smallMessageCompletedTasks = Metrics.register(factory.createMetricName("SmallMessageCompletedTasks"), new Gauge<Long>()
{
public Long getValue()
{
return connectionPool.smallMessages.getCompletedMesssages();
}
});
smallMessageDroppedTasks = Metrics.register(factory.createMetricName("SmallMessageDroppedTasks"), new Gauge<Long>()
{
public Long getValue()
{
return connectionPool.smallMessages.getDroppedMessages();
}
});
gossipMessagePendingTasks = Metrics.register(factory.createMetricName("GossipMessagePendingTasks"), new Gauge<Integer>()
{
public Integer getValue()
{
return connectionPool.gossipMessages.getPendingMessages();
}
});
gossipMessageCompletedTasks = Metrics.register(factory.createMetricName("GossipMessageCompletedTasks"), new Gauge<Long>()
{
public Long getValue()
{
return connectionPool.gossipMessages.getCompletedMesssages();
}
});
gossipMessageDroppedTasks = Metrics.register(factory.createMetricName("GossipMessageDroppedTasks"), new Gauge<Long>()
{
public Long getValue()
{
return connectionPool.gossipMessages.getDroppedMessages();
}
});
timeouts = Metrics.meter(factory.createMetricName("Timeouts"));
}
public void release()
{
Metrics.remove(factory.createMetricName("LargeMessagePendingTasks"));
Metrics.remove(factory.createMetricName("LargeMessageCompletedTasks"));
Metrics.remove(factory.createMetricName("LargeMessageDroppedTasks"));
Metrics.remove(factory.createMetricName("SmallMessagePendingTasks"));
Metrics.remove(factory.createMetricName("SmallMessageCompletedTasks"));
Metrics.remove(factory.createMetricName("SmallMessageDroppedTasks"));
Metrics.remove(factory.createMetricName("GossipMessagePendingTasks"));
Metrics.remove(factory.createMetricName("GossipMessageCompletedTasks"));
Metrics.remove(factory.createMetricName("GossipMessageDroppedTasks"));
Metrics.remove(factory.createMetricName("Timeouts"));
}
}