Class StatsMetric

java.lang.Object
com.frostwire.jlibtorrent.StatsMetric

public final class StatsMetric extends Object
Metadata describing a single session statistic metric.

StatsMetric identifies a specific statistic available from the session and provides its index for accessing values in SessionStatsAlert. Each metric has a name, index, and type (counter or gauge). Useful for discovering available metrics and accessing statistics programmatically.

Metric Types:

  • Counter: Cumulative total that only increases (NET_SENT_BYTES, etc)
  • Gauge: Current instantaneous value (DHT_NODES, etc)

Common Metrics:

 Network Sent (Counter):
   NET_SENT_PAYLOAD_BYTES:      Torrent data uploaded
   NET_SENT_BYTES:              Total upload including protocol
   NET_SENT_IP_OVERHEAD_BYTES:  TCP/IP headers in uploads

 Network Received (Counter):
   NET_RECV_PAYLOAD_BYTES:      Torrent data downloaded
   NET_RECV_BYTES:              Total download including protocol
   NET_RECV_IP_OVERHEAD_BYTES:  TCP/IP headers in downloads

 DHT Status (Gauge):
   DHT_NODES_GAUGE:             Number of nodes in DHT routing table
 

Accessing Metric Values:

 // From SessionStatsAlert
 sm.addListener(new AlertListener() {
     public int[] types() {
         return new int[] {AlertType.SESSION_STATS.swig()};
     }

     public void alert(Alert<?> alert) {
         SessionStatsAlert a = (SessionStatsAlert) alert;

         // Access using predefined indices
         long sentPayload = a.value(
             StatsMetric.NET_SENT_PAYLOAD_BYTES_COUNTER_INDEX);
         long recvPayload = a.value(
             StatsMetric.NET_RECV_PAYLOAD_BYTES_COUNTER_INDEX);
         long dhtNodes = a.value(
             StatsMetric.DHT_NODES_GAUGE_INDEX);

         System.out.println(\"Sent: \" + sentPayload + \" bytes\");
         System.out.println(\"Recv: \" + recvPayload + \" bytes\");
         System.out.println(\"DHT nodes: \" + dhtNodes);
     }
 });
 

Discovering All Metrics:

 // Get list of all available metrics
 java.util.List<StatsMetric> metrics = LibTorrent.metrics();

 for (StatsMetric metric : metrics) {
     System.out.println(\"Metric: \" + metric.name);
     System.out.println(\"  Index: \" + metric.valueIndex);
     System.out.println(\"  Type: \" +
         (metric.type == StatsMetric.TYPE_COUNTER ? \"counter\" : \"gauge\"));
 }
 

Metric Index Usage:

 // Metric index is used to access values in SessionStatsAlert
 int idx = StatsMetric.NET_SENT_PAYLOAD_BYTES_COUNTER_INDEX;
 long value = sessionStatsAlert.value(idx);

 // For counters, value is cumulative total
 // For gauges, value is current snapshot
 

Performance Analysis with Metrics:

 // Calculate actual useful bandwidth vs overhead
 long sentPayload = statsAlert.value(
     StatsMetric.NET_SENT_PAYLOAD_BYTES_COUNTER_INDEX);
 long sentTotal = statsAlert.value(
     StatsMetric.NET_SENT_BYTES_COUNTER_INDEX);
 long sentIP = statsAlert.value(
     StatsMetric.NET_SENT_IP_OVERHEAD_BYTES_COUNTER_INDEX);

 double efficiency = (double) sentPayload / sentTotal * 100;
 System.out.println(\"Upload efficiency: \" +
     String.format(\"%.1f%%\", efficiency));

 // sentTotal = sentPayload + protocol + IP overhead
 long protocol = sentTotal - sentPayload - sentIP;
 

Standard Metric Prefixes:

  • net.*: Network statistics (sent/received bytes)
  • dht.*: DHT statistics (nodes, lookups)
See Also:
  • Field Details

    • NET_SENT_PAYLOAD_BYTES_COUNTER_NAME

      public static final String NET_SENT_PAYLOAD_BYTES_COUNTER_NAME
      See Also:
    • NET_SENT_BYTES_COUNTER_NAME

      public static final String NET_SENT_BYTES_COUNTER_NAME
      See Also:
    • NET_SENT_IP_OVERHEAD_BYTES_COUNTER_NAME

      public static final String NET_SENT_IP_OVERHEAD_BYTES_COUNTER_NAME
      See Also:
    • NET_RECV_PAYLOAD_BYTES_COUNTER_NAME

      public static final String NET_RECV_PAYLOAD_BYTES_COUNTER_NAME
      See Also:
    • NET_RECV_BYTES_COUNTER_NAME

      public static final String NET_RECV_BYTES_COUNTER_NAME
      See Also:
    • NET_RECV_IP_OVERHEAD_BYTES_COUNTER_NAME

      public static final String NET_RECV_IP_OVERHEAD_BYTES_COUNTER_NAME
      See Also:
    • NET_SENT_PAYLOAD_BYTES_COUNTER_INDEX

      public static final int NET_SENT_PAYLOAD_BYTES_COUNTER_INDEX
    • NET_SENT_BYTES_COUNTER_INDEX

      public static final int NET_SENT_BYTES_COUNTER_INDEX
    • NET_SENT_IP_OVERHEAD_BYTES_COUNTER_INDEX

      public static final int NET_SENT_IP_OVERHEAD_BYTES_COUNTER_INDEX
    • NET_RECV_PAYLOAD_BYTES_COUNTER_INDEX

      public static final int NET_RECV_PAYLOAD_BYTES_COUNTER_INDEX
    • NET_RECV_BYTES_COUNTER_INDEX

      public static final int NET_RECV_BYTES_COUNTER_INDEX
    • NET_RECV_IP_OVERHEAD_BYTES_COUNTER_INDEX

      public static final int NET_RECV_IP_OVERHEAD_BYTES_COUNTER_INDEX
    • DHT_NODES_GAUGE_NAME

      public static final String DHT_NODES_GAUGE_NAME
      See Also:
    • DHT_NODES_GAUGE_INDEX

      public static final int DHT_NODES_GAUGE_INDEX
    • TYPE_COUNTER

      public static final int TYPE_COUNTER
    • TYPE_GAUGE

      public static final int TYPE_GAUGE
    • name

      public final String name
    • valueIndex

      public final int valueIndex
    • type

      public final int type
  • Method Details