コード例 #1
0
  private void updateStats(int record_type) {
    long current_d_received = gm_stats.getTotalDataBytesReceived();
    long current_p_received = gm_stats.getTotalProtocolBytesReceived();

    long current_d_sent = gm_stats.getTotalDataBytesSent();
    long current_p_sent = gm_stats.getTotalProtocolBytesSent();

    long current_dht_sent = 0;
    long current_dht_received = 0;

    DHT[] dhts = getDHTs();

    if (dhts != null) {

      for (DHT dht : dhts) {

        DHTTransportStats dht_stats = dht.getTransport().getStats();

        current_dht_sent += dht_stats.getBytesSent();
        current_dht_received += dht_stats.getBytesReceived();
      }
    }

    write(
        record_type,
        new long[] {
          (current_p_sent - ss_p_sent),
          (current_d_sent - ss_d_sent),
          (current_p_received - ss_p_received),
          (current_d_received - ss_d_received),
          (current_dht_sent - ss_dht_sent),
          (current_dht_received - ss_dht_received)
        });
  }
コード例 #2
0
  private void sessionStart() {
    OverallStatsImpl stats = (OverallStatsImpl) StatsFactory.getStats();

    synchronized (this) {
      if (closing) {

        return;
      }

      boolean enabled = COConfigurationManager.getBooleanParameter("long.term.stats.enable");

      if (active || !enabled) {

        return;
      }

      active = true;

      long[] snap = stats.getLastSnapshot();

      ss_d_received = gm_stats.getTotalDataBytesReceived();
      ss_p_received = gm_stats.getTotalProtocolBytesReceived();

      ss_d_sent = gm_stats.getTotalDataBytesSent();
      ss_p_sent = gm_stats.getTotalProtocolBytesSent();

      ss_dht_sent = 0;
      ss_dht_received = 0;

      if (core.isStarted()) {

        DHT[] dhts = getDHTs();

        if (dhts != null) {

          for (DHT dht : dhts) {

            DHTTransportStats dht_stats = dht.getTransport().getStats();

            ss_dht_sent += dht_stats.getBytesSent();
            ss_dht_received += dht_stats.getBytesReceived();
          }
        }
      }

      st_p_sent = snap[0] + (ss_p_sent - snap[6]);
      st_d_sent = snap[1] + (ss_d_sent - snap[7]);
      st_p_received = snap[2] + (ss_p_received - snap[8]);
      st_d_received = snap[3] + (ss_d_received - snap[9]);
      st_dht_sent = snap[4] + (ss_dht_sent - snap[10]);
      st_dht_received = snap[5] + (ss_dht_received - snap[11]);

      write(
          RT_SESSION_START,
          new long[] {
            st_p_sent, st_d_sent, st_p_received, st_d_received, st_dht_sent, st_dht_received
          });

      if (event == null) { // should always be null but hey ho

        event =
            SimpleTimer.addPeriodicEvent(
                "LongTermStats",
                MIN_IN_MILLIS,
                new TimerEventPerformer() {
                  public void perform(TimerEvent event) {
                    updateStats();
                  }
                });
      }
    }
  }