Package org.jrobin.core

Examples of org.jrobin.core.Sample


  public void reset()
  {
    try
    {
      RrdDb rrdDb = _rrdPool.requestRrdDb(_rrdPath);
      Sample sample = rrdDb.createSample();
      sample.setValue("calls", (Integer) _connection.getAttribute(_sessionManger, "callSessions"));
      long totalMemory = __runtime.totalMemory();
      sample.setValue("maxMemory", __runtime.maxMemory());
      sample.setValue("totalMemory", totalMemory);
      sample.setValue("usedMemory", totalMemory - __runtime.freeMemory());
      // No values are set for incomingMessages, outgoingMessages to reset these counters.
      sample.update();
      _rrdPool.release(rrdDb);
    }
    catch (Exception e)
    {
      _logger.warn("Unable to set statistics", e);
View Full Code Here


  public void updateDb()
  {
    try
    {
      RrdDb rrdDb = _rrdPool.requestRrdDb(_rrdPath);
      Sample sample = rrdDb.createSample();
      if (_connection.isRegistered(_sessionManger))
        sample.setValue("calls", (Integer) _connection.getAttribute(_sessionManger, "callSessions"));
     
      long totalMemory = __runtime.totalMemory();
      sample.setValue("maxMemory", __runtime.maxMemory());
      sample.setValue("totalMemory", totalMemory);
      sample.setValue("usedMemory", totalMemory - __runtime.freeMemory());
      if (_connection.isRegistered(ConsoleFilter.CONNECTOR_MANAGER))
      {
        sample.setValue("incomingMessages",
            (Long) _connection.getAttribute(ConsoleFilter.CONNECTOR_MANAGER, "messagesReceived"));
        sample.setValue("outgoingMessages",
            (Long) _connection.getAttribute(ConsoleFilter.CONNECTOR_MANAGER, "messagesSent"));
      }
     
      int nbCpu = (Integer) _connection.getAttribute(OPERATING_SYSTEM, "AvailableProcessors");
      if (_cpuStatAvailable)
      {
        long processCpuTime = (Long) _connection.getAttribute(OPERATING_SYSTEM, "ProcessCpuTime");
        sample.setValue("cpu", processCpuTime / nbCpu);
      }
     
      long timeInGc = 0;
      Set<ObjectName> garbageCollections = _connection.queryNames(GARBAGE_COLLECTORS, null);
      for (ObjectName objectName : garbageCollections)
      {
        timeInGc += (Long) _connection.getAttribute(objectName, "CollectionTime");
      }
      sample.setValue("timeInGc", timeInGc / nbCpu);
     
     
      sample.update();
      _rrdPool.release(rrdDb);
    }
    catch (Exception e)
    {
      _logger.warn("Unable to set statistics", e);
View Full Code Here

    m_db.close();
  }

  @Test
  public void testRrdUpdate() throws Exception {
    Sample sample = null;
    long startTime = System.currentTimeMillis() - 1000;
//    for (int i = 0; i < 1000000; i++) {
      sample = m_db.createSample();
      sample.setAndUpdate(startTime + ":" + m_random.nextInt());
      //sample.setAndUpdate(startTime++ + ":" + m_random.nextInt());
//    }
  }
View Full Code Here

        if (dsNames == null && dsCount + 1 != tokens.length) {
          throw new RrdException("Expected " + dsCount + " values, " +
              (tokens.length - 1) + " value(s) found in: " + words[i]);
        }
        timestamp = Util.getTimestamp(tokens[0]);
        Sample sample = rrdDb.createSample(timestamp);
        for (int j = 1; j < tokens.length; j++) {
          if (dsNames == null) {
            sample.setValue(j - 1, parseDouble(tokens[j]));
          }
          else {
            sample.setValue(dsNames[j - 1], parseDouble(tokens[j]));
          }
        }
        sample.update();
      }
      return timestamp;
    }
    finally {
      releaseRrdDbReference(rrdDb);
View Full Code Here

                    // long time to complete
                    if(newTime <= db.getLastArchiveUpdateTime()) {
                        Log.warn("Sample time of " + newTime +  " for statistic " + key + " is " +
                                "invalid.");
                    }
                    Sample sample = db.createSample(newTime);

                    if (Log.isDebugEnabled()) {
                        Log.debug("Stat: " + db.getPath() + ". Last sample: " + db.getLastUpdateTime() +
                                ". New sample: " + sample.getTime());
                    }

                    for (StatDefinition definition : definitions) {
                        // Get a statistic sample of this JVM
                        double statSample = sampleStat(key, definition);
                        // Add up samples of remote cluster nodes
                        for (Object nodeResult : remoteSamples) {
                            Map<String, Double> nodeSamples = (Map<String, Double>) nodeResult;
                            Double remoteSample = nodeSamples.get(key);
                            if (remoteSample != null) {
                                statSample += remoteSample;
                            }
                        }
                        // Update sample with values
                        sample.setValue(definition.getDatasourceName(), statSample);
                        sampledStats.add(definition.getDatasourceName());
                        definition.lastSampleTime = newTime;
                        definition.lastSample = statSample;
                    }
                    sample.update();
                }
                catch (IOException e) {
                    Log.error("Error sampling for statistic " + key, e);
                }
                catch (RrdException e) {
View Full Code Here

        if (dsNames == null && dsCount + 1 != tokens.length) {
          throw new RrdException("Expected " + dsCount + " values, " +
              (tokens.length - 1) + " value(s) found in: " + words[i]);
        }
        timestamp = Util.getTimestamp(tokens[0]);
        Sample sample = rrdDb.createSample(timestamp);
        for (int j = 1; j < tokens.length; j++) {
          if (dsNames == null) {
            sample.setValue(j - 1, parseDouble(tokens[j]));
          }
          else {
            sample.setValue(dsNames[j - 1], parseDouble(tokens[j]));
          }
        }
        sample.update();
      }
      return timestamp;
    }
    finally {
      releaseRrdDbReference(rrdDb);
View Full Code Here

  public void doWrite(Server server, Query query, ImmutableList<Result> results) throws Exception {
    RrdDb db = null;
    try {
      db = createOrOpenDatabase();
      Sample sample = db.createSample();
      List<String> dsNames = Arrays.asList(db.getDsNames());

      // go over all the results and look for datasource names that map to
      // keys from the result values
      for (Result res : results) {
        Map<String, Object> values = res.getValues();
        if (values != null) {
          for (Entry<String, Object> entry : values.entrySet()) {
            if (dsNames.contains(entry.getKey()) && NumberUtils.isNumeric(entry.getValue())) {
              sample.setValue(entry.getKey(), Double.valueOf(entry.getValue().toString()));
            }
          }
        }
      }
      sample.update();
    } finally {
      if (db != null) {
        db.close();
      }
    }
View Full Code Here

TOP

Related Classes of org.jrobin.core.Sample

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.