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)
        });
  }
Example #2
0
  public void periodicUpdate() {
    if (manager == null || stats == null) {
      return;
    }

    int swarms_peer_speed = (int) stats.getTotalSwarmsPeerRate(true, false);

    downSpeedGraphic.addIntsValue(
        new int[] {
          stats.getDataReceiveRate() + stats.getProtocolReceiveRate(),
          stats.getProtocolReceiveRate(),
          COConfigurationManager.getIntParameter("Max Download Speed KBs") * 1024,
          swarms_peer_speed
        });
  }
  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();
                  }
                });
      }
    }
  }
Example #4
0
    @Override
    public void run() {
      long startTime = System.currentTimeMillis();

      try {
        s = new Socket(InetAddress.getByName(host), port);

        out = s.getOutputStream();
        final DataInputStream in = new DataInputStream(s.getInputStream());
        Thread readThread =
            new Thread(
                new Runnable() {
                  @Override
                  public void run() {
                    logger.fine("running speed check to " + host + ":" + port);
                    try {
                      /*
                       * read the time stamps
                       */
                      while (!sendCompleted || localTimeStamps.size() > remoteTimeStamps.size()) {
                        logger.finest(
                            "reading again: complete="
                                + sendCompleted
                                + " sizediff="
                                + (localTimeStamps.size() - remoteTimeStamps.size()));
                        // read message len
                        int len = in.readInt();
                        logger.finest("message len: " + len);
                        byte id = in.readByte();
                        logger.finest("message id: " + id);
                        int timestamp = in.readInt();
                        logger.finest("message timestamp: " + timestamp);
                        remoteTimeStamps.add(timestamp);
                        if (stats != null) {
                          stats.protocolBytesReceived(9, false);
                        }
                      }
                      logger.fine("incoming reader complete");
                      completed = true;
                    } catch (IOException e) {
                      logger.fine(
                          "speed check connection closed: "
                              + e.getClass().getName()
                              + "::"
                              + e.getMessage());
                      closed = true;
                    }
                  }
                });
        readThread.setDaemon(true);
        readThread.setName("speed check outgoing: inputreader " + host + ":" + port);
        readThread.start();

        /*
         * first, send the handshake
         */
        byte[] rand = new byte[8];
        new Random().nextBytes(rand);
        out.write(getHsBytes(rand));

        /*
         * second, send the dummy data
         */
        byte[] dummyPacket = getDummyPacket();
        long elapsed;
        while ((elapsed = System.currentTimeMillis() - startTime) < SPEED_CHECK_TIME) {
          logger.finest("sending " + dummyPacket.length + " bytes");
          localTimeStamps.add((int) elapsed);
          out.write(dummyPacket);
          if (stats != null) {
            stats.protocolBytesSent(dummyPacket.length, false);
          }
        }
        sendCompleted = true;
        logger.fine("send completed: " + host + ":" + port);
      } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        logger.fine(
            "speed check connection closed: " + e.getClass().getName() + "::" + e.getMessage());
        closed = true;
      }
    }
Example #5
0
 @Override
 public void protocolBytesReceived(int byteCount) {
   if (stats != null) {
     stats.protocolBytesReceived(byteCount, false);
   }
 };