Search in sources :

Example 1 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class ProfileOrganizerRenderer method avg.

private String avg(PeerProfile prof, long rate, RateAverages ra) {
    RateStat rs = prof.getDbResponseTime();
    if (rs == null)
        return _t(NA);
    Rate r = rs.getRate(rate);
    if (r == null)
        return _t(NA);
    r.computeAverages(ra, false);
    if (ra.getTotalEventCount() == 0)
        return _t(NA);
    return DataHelper.formatDuration2(Math.round(ra.getAverage()));
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 2 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class SummaryHelper method getLifetimeKBps.

/**
 *    @return "x.xx / y.yy {K|M}"
 */
public String getLifetimeKBps() {
    if (_context == null)
        return "0 / 0";
    RateStat receiveRate = _context.statManager().getRate("bw.recvRate");
    double in;
    if (receiveRate == null)
        in = 0;
    else
        in = receiveRate.getLifetimeAverageValue();
    RateStat sendRate = _context.statManager().getRate("bw.sendRate");
    double out;
    if (sendRate == null)
        out = 0;
    else
        out = sendRate.getLifetimeAverageValue();
    return formatPair(in, out);
}
Also used : RateStat(net.i2p.stat.RateStat)

Example 3 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class SummaryHelper method getJobLag.

/**
 * How lagged our job queue is over the last minute (pretty printed with
 * the units attached)
 */
public String getJobLag() {
    if (_context == null)
        return "0";
    RateStat rs = _context.statManager().getRate("jobQueue.jobLag");
    if (rs == null)
        return "0";
    Rate lagRate = rs.getRate(60 * 1000);
    return DataHelper.formatDuration2((long) lagRate.getAverageValue());
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 4 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class SummaryListener method startListening.

/**
 *  @return success
 */
public boolean startListening() {
    RateStat rs = _rate.getRateStat();
    long period = _rate.getPeriod();
    String baseName = rs.getName() + "." + period;
    _name = createName(_context, baseName);
    _eventName = createName(_context, baseName + ".events");
    File rrdFile = null;
    try {
        RrdBackendFactory factory = RrdBackendFactory.getFactory(getBackendName());
        String rrdDefName;
        if (_isPersistent) {
            // generate full path for persistent RRD files
            File rrdDir = new SecureFile(_context.getRouterDir(), RRD_DIR);
            rrdFile = new File(rrdDir, RRD_PREFIX + _name + RRD_SUFFIX);
            rrdDefName = rrdFile.getAbsolutePath();
            if (rrdFile.exists()) {
                _db = new RrdDb(rrdDefName, factory);
                Archive arch = _db.getArchive(CF, STEPS);
                if (arch == null)
                    throw new IOException("No average CF in " + rrdDefName);
                _rows = arch.getRows();
                if (_log.shouldLog(Log.INFO))
                    _log.info("Existing RRD " + baseName + " (" + rrdDefName + ") with " + _rows + " rows consuming " + _db.getRrdBackend().getLength() + " bytes");
            } else {
                rrdDir.mkdir();
            }
        } else {
            rrdDefName = _name;
        }
        if (_db == null) {
            // not persistent or not previously existing
            RrdDef def = new RrdDef(rrdDefName, now() / 1000, period / 1000);
            // for info on the heartbeat, xff, steps, etc, see the rrdcreate man page, aka
            // http://www.jrobin.org/support/man/rrdcreate.html
            long heartbeat = period * 10 / 1000;
            def.addDatasource(_name, "GAUGE", heartbeat, Double.NaN, Double.NaN);
            def.addDatasource(_eventName, "GAUGE", heartbeat, 0, Double.NaN);
            if (_isPersistent) {
                _rows = (int) Math.max(MIN_ROWS, Math.min(MAX_ROWS, THREE_MONTHS / period));
            } else {
                _rows = MIN_ROWS;
            }
            def.addArchive(CF, XFF, STEPS, _rows);
            _db = new RrdDb(def, factory);
            if (_isPersistent)
                SecureFileOutputStream.setPerms(new File(rrdDefName));
            if (_log.shouldLog(Log.INFO))
                _log.info("New RRD " + baseName + " (" + rrdDefName + ") with " + _rows + " rows consuming " + _db.getRrdBackend().getLength() + " bytes");
        }
        _sample = _db.createSample();
        _renderer = new SummaryRenderer(_context, this);
        _rate.setSummaryListener(this);
        return true;
    } catch (OutOfMemoryError oom) {
        _log.error("Error starting RRD for stat " + baseName, oom);
    } catch (RrdException re) {
        _log.error("Error starting RRD for stat " + baseName, re);
        // corrupt file?
        if (_isPersistent && rrdFile != null)
            rrdFile.delete();
    } catch (IOException ioe) {
        _log.error("Error starting RRD for stat " + baseName, ioe);
    } catch (Throwable t) {
        _log.error("Error starting RRD for stat " + baseName, t);
    }
    return false;
}
Also used : Archive(org.jrobin.core.Archive) RrdDef(org.jrobin.core.RrdDef) SecureFile(net.i2p.util.SecureFile) IOException(java.io.IOException) RateStat(net.i2p.stat.RateStat) RrdBackendFactory(org.jrobin.core.RrdBackendFactory) RrdDb(org.jrobin.core.RrdDb) RrdException(org.jrobin.core.RrdException) SecureFile(net.i2p.util.SecureFile) File(java.io.File)

Example 5 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class ConfigStatsHelper method hasMoreStats.

/**
 * move the cursor to the next known stat, returning true if a valid
 * stat is available.
 *
 * @return true if a valid stat is available, otherwise false
 */
public boolean hasMoreStats() {
    if (_stats.isEmpty())
        return false;
    _currentIsGraphed = false;
    _currentStatName = _stats.remove(0);
    RateStat rs = _context.statManager().getRate(_currentStatName);
    if (rs != null) {
        _currentStatDescription = rs.getDescription();
        if (_currentGroup == null)
            _currentIsFirstInGroup = true;
        else if (!rs.getGroupName().equals(_currentGroup))
            _currentIsFirstInGroup = true;
        else
            _currentIsFirstInGroup = false;
        _currentGroup = rs.getGroupName();
        // should be the minimum
        long period = rs.getPeriods()[0];
        if (period <= 10 * 60 * 1000) {
            Rate r = rs.getRate(period);
            _currentCanBeGraphed = r != null;
            if (_currentCanBeGraphed) {
                // see above
                // _currentIsGraphed = r.getSummaryListener() != null;
                _currentGraphName = _currentStatName + "." + period;
                _currentIsGraphed = _graphs.contains(_currentGraphName);
            }
        } else {
            _currentCanBeGraphed = false;
        }
    } else {
        FrequencyStat fs = _context.statManager().getFrequency(_currentStatName);
        if (fs != null) {
            _currentStatDescription = fs.getDescription();
            if (_currentGroup == null)
                _currentIsFirstInGroup = true;
            else if (!fs.getGroupName().equals(_currentGroup))
                _currentIsFirstInGroup = true;
            else
                _currentIsFirstInGroup = false;
            _currentGroup = fs.getGroupName();
            _currentCanBeGraphed = false;
        } else {
            if (_log.shouldLog(Log.ERROR))
                _log.error("Stat does not exist?!  [" + _currentStatName + "]");
            return false;
        }
    }
    if (_filters.contains("*") || _filters.contains(_currentStatName))
        _currentIsLogged = true;
    else
        _currentIsLogged = false;
    return true;
}
Also used : FrequencyStat(net.i2p.stat.FrequencyStat) RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Aggregations

RateStat (net.i2p.stat.RateStat)33 Rate (net.i2p.stat.Rate)24 Hash (net.i2p.data.Hash)5 RouterInfo (net.i2p.data.router.RouterInfo)5 RateAverages (net.i2p.stat.RateAverages)4 PeerProfile (net.i2p.router.peermanager.PeerProfile)3 ArrayList (java.util.ArrayList)2 RouterContext (net.i2p.router.RouterContext)2 StatManager (net.i2p.stat.StatManager)2 File (java.io.File)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 StringTokenizer (java.util.StringTokenizer)1 TreeSet (java.util.TreeSet)1 RouterAddress (net.i2p.data.router.RouterAddress)1 CommSystemFacade (net.i2p.router.CommSystemFacade)1 TunnelInfo (net.i2p.router.TunnelInfo)1 DBHistory (net.i2p.router.peermanager.DBHistory)1 HopConfig (net.i2p.router.tunnel.HopConfig)1 TunnelPool (net.i2p.router.tunnel.pool.TunnelPool)1