本文整理汇总了Java中org.rrd4j.core.RrdDb类的典型用法代码示例。如果您正苦于以下问题:Java RrdDb类的具体用法?Java RrdDb怎么用?Java RrdDb使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RrdDb类属于org.rrd4j.core包,在下文中一共展示了RrdDb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: storeCyclicGpuData
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
public void storeCyclicGpuData(DeviceCyclicData gpu) throws IOException {
RrdDb db = null;
try {
db = RrdDbFactory.getGpuDb(gpu.getClusterId(), gpu.getUntiId(),
gpu.getDeviceId());
if (db == null) {
db = RrdDbFactory.createGpuDb(gpu.getClusterId(), gpu.getUntiId(),
gpu.getDeviceId());
}
List<Integer> data = new LinkedList<>();
data.add(new BigDecimal(new Date().getTime() / 1000).intValue());
data.add(gpu.getGpuUsage());
data.add(gpu.getMemoryUsed());
data.add(gpu.getFanSpeed());
RrdHelper.store(data, db);
} catch (IOException ex) {
logger.log(Level.SEVERE, "Error while persisting sequential data", ex);
} finally {
if (db != null) {
db.close();
}
}
}
示例2: createUnitDb
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
public static RrdDb createUnitDb(int cores, int clusterId, int unitId) throws IOException {
Logger.getLogger(RrdDbFactory.class.getName()).info("Creating new RRD file: "
+ RrdHelper.getDbPath(clusterId, unitId));
RrdDef rrdDef = new RrdDef(RrdHelper.getDbPath(clusterId, unitId));
rrdDef.setStep(STEP);
rrdDef.addDatasource(new MonitoredEntity(MonitoredEntityType.CPU_SPEED).getStringId(),
DsType.GAUGE, TIMEOUT, Double.NaN, Double.NaN);
for (int i = 0; i < cores; i++) {
rrdDef.addDatasource(new MonitoredEntity(MonitoredEntityType.CPU_USAGE, i).getStringId(),
DsType.GAUGE, TIMEOUT, Double.NaN, Double.NaN);
}
rrdDef.addDatasource(new MonitoredEntity(MonitoredEntityType.MEMORY).getStringId(),
DsType.GAUGE, TIMEOUT, Double.NaN, Double.NaN);
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5,
RrdHelper.getSampleSize(RrdDbResolution.EXACT),
RrdHelper.getSampleWindow(RrdDbResolution.EXACT));
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5,
RrdHelper.getSampleSize(RrdDbResolution.LOW),
RrdHelper.getSampleWindow(RrdDbResolution.LOW));
RrdDb rrdDb = new RrdDb(rrdDef);
return rrdDb;
}
示例3: createGpuDb
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
public static RrdDb createGpuDb(int clusterId, int unitId, int deviceId) throws IOException {
Logger.getLogger(RrdDbFactory.class.getName()).info("Creating new GPU RRD file: "
+ RrdHelper.getDbPath(clusterId, unitId, deviceId));
RrdDef rrdDef = new RrdDef(RrdHelper.getDbPath(clusterId, unitId, deviceId));
rrdDef.setStep(STEP);
rrdDef.addDatasource(new MonitoredEntity(MonitoredEntityType.GPU_USAGE).getStringId(),
DsType.GAUGE, TIMEOUT, Double.NaN, Double.NaN);
rrdDef.addDatasource(new MonitoredEntity(MonitoredEntityType.GPU_GLOBAL_MEMORY).getStringId(),
DsType.GAUGE, TIMEOUT, Double.NaN, Double.NaN);
rrdDef.addDatasource(new MonitoredEntity(MonitoredEntityType.FAN).getStringId(),
DsType.GAUGE, TIMEOUT, 0, 100);
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5,
RrdHelper.getSampleSize(RrdDbResolution.EXACT),
RrdHelper.getSampleWindow(RrdDbResolution.EXACT));
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5,
RrdHelper.getSampleSize(RrdDbResolution.LOW),
RrdHelper.getSampleWindow(RrdDbResolution.LOW));
RrdDb rrdDb = new RrdDb(rrdDef);
return rrdDb;
}
示例4: run
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
/**
* Periodically dumps the new mbean state to the data base
*/
public void run() {
try {
RrdDb dataBase = new RrdDb(dataBaseFile);
logger.debug("RRD database configuration:\n" + dataBase.getRrdDef().dump());
while (!terminate) {
synchronized (dataSources) {
dataSources.wait(step * 1000);
if (terminate) {
break;
}
sample(dataBase, System.currentTimeMillis());
}
}
dataBase.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
示例5: samplesAreCreated_2Beans
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
@Test
public void samplesAreCreated_2Beans() throws Exception {
File rrdFile = createTempRRDFile();
Fake fakeBean = new Fake();
Fake fakeBean2 = new Fake();
MBeanServer beanServer = MBeanServerFactory.createMBeanServer();
beanServer.registerMBean(fakeBean, new ObjectName("java.lang:type=Memory"));
beanServer.registerMBean(fakeBean2, new ObjectName("sigar:Type=Mem"));
RRDSigarDataStore store = new RRDSigarDataStore(beanServer, rrdFile.getPath(), 4, Logger.getLogger("test"));
RrdDb dataBase = new RrdDb(rrdFile.getPath());
// sample 5 times every 10 seconds
long firstSampleTime = System.currentTimeMillis();
for (int i = 1; i <= 5; i++) {
store.sample(dataBase, firstSampleTime + i * TEN_SECONDS);
}
assertEquals((firstSampleTime + 5 * TEN_SECONDS) / 1000, dataBase.getLastUpdateTime());
assertEquals(42, dataBase.getDatasource("ValueMemory").getLastValue(), 0.001);
assertEquals(42, dataBase.getDatasource("ValueMem").getLastValue(), 0.001);
}
示例6: generateGraph
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
private void generateGraph(RrdDb rrdDb) throws IOException {
RrdGraphDef gDef = new RrdGraphDef();
gDef.setWidth(500);
gDef.setHeight(300);
gDef.setFilename(name + ".png");
gDef.setStartTime(startTime);
gDef.setEndTime(rrdDb.getLastUpdateTime());
gDef.setTitle(name);
gDef.setVerticalLabel(physicalQuantity.getUnit());
gDef.datasource(physicalQuantity.toString(), rrdPath, name, ConsolFun.MAX);
gDef.line(physicalQuantity.toString(), Color.RED, physicalQuantity.toString() + " max");
gDef.setImageFormat("png");
graph = new RrdGraph(gDef);
}
示例7: init
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
@Before
public void init() throws IOException {
CassandraBackendFactory factory = new CassandraBackendFactory("localhost:9160");
TimeTrace timeTrace = new TimeTrace();
timeTrace.begin();
for (int i = 0; i < rrdCount; i++) {
RrdDef rrdDef = new RrdDef("pt-5m-" + i, 0, 300);
rrdDef.setVersion(2);
rrdDef.addDatasource("ds", GAUGE, 3600, -5, 30);
rrdDef.addArchive(AVERAGE, 0.5, 300, 1000);
rrdDbs.add(new RrdDb(rrdDef, factory));
}
timeTrace.end();
System.out.printf("init time(Total):%s,count:%s\r\n", timeTrace.getMills(), rrdDbs.size());
System.out.printf("init time(Avg):%s\r\n", timeTrace.getMills() / rrdDbs.size());
}
示例8: testSetValue
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
@Test
public void testSetValue() throws IOException {
Calendar testTime = Calendar.getInstance();
testTime.set(Calendar.MINUTE, 0);
testTime.set(Calendar.SECOND, 0);
testTime.set(Calendar.MILLISECOND, 0);
long start = Util.getTimestamp(testTime);
TimeTrace timeTrace = new TimeTrace();
timeTrace.begin();
for (RrdDb rrdDb : rrdDbs) {
long timeStamp = start;
for (int i = 0; i < 1; i++) {
long sampleTime = timeStamp;
rrdDb.createSample(sampleTime).setValue("ds", 30).update();
timeStamp += 300;
}
}
timeTrace.end();
System.out.printf("setValue time(Total):%s,count:%s\r\n", timeTrace.getMills(), rrdDbs.size());
System.out.printf("setValue time(Avg):%s\r\n", timeTrace.getMills() / rrdDbs.size());
closeDb();
}
示例9: storeSequentialMessage
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
public void storeSequentialMessage(SequentialMessage message) throws IOException {
RrdDb db = null;
try {
logger.info("Storing message for cluster " + message.getClusterId());
db = RrdDbFactory.getUnitDb(message.getClusterId(), message.getUnitId());
if (db == null) {
db = RrdDbFactory.createUnitDb(message.getCpuCores(),
message.getClusterId(), message.getUnitId());
}
List<Integer> data = new LinkedList<>();
data.add(new BigDecimal(new Date().getTime() / 1000).intValue());
data.add(message.getClockSpeed());
for (int cpuUsage : message.getCpuUsage()) {
data.add(cpuUsage);
}
data.add(message.getMemoryUsed());
RrdHelper.store(data, db);
for (DeviceCyclicData gpu : message.getGpuDevices()) {
storeCyclicGpuData(gpu);
}
} catch (IOException ex) {
logger.log(Level.SEVERE, "Error while persisting sequential data", ex);
} finally {
if (db != null) {
db.close();
}
}
MonitoredEntity entity = new MonitoredEntity(MonitoredEntityType.FAN);
entity.setClusterId(message.getClusterId());
entity.setUnitId(message.getUnitId());
entity.setDeviceId(0);
RrdHelper.createGraph(entity, RrdDbResolution.EXACT);
}
示例10: getUnitDb
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
public static RrdDb getUnitDb(int clusterId, int unitId) throws IOException {
File f = new File(RrdHelper.getDbPath(clusterId, unitId));
if (f.exists() && f.isFile()) {
return new RrdDb(RrdHelper.getDbPath(clusterId, unitId));
} else {
return null;
}
}
示例11: getGpuDb
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
public static RrdDb getGpuDb(int clusterId, int unitId, int deviceId) throws IOException {
File f = new File(RrdHelper.getDbPath(clusterId, unitId, deviceId));
if (f.exists() && f.isFile()) {
return new RrdDb(RrdHelper.getDbPath(clusterId, unitId, deviceId));
} else {
return null;
}
}
示例12: store
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
public static void store(List<Integer> data, RrdDb db) {
StringBuilder sb = new StringBuilder();
for (Integer value : data) {
sb.append(value);
sb.append(':');
}
sb.deleteCharAt(sb.length() - 1);
try {
Sample sample = db.createSample();
sample.setAndUpdate(sb.toString());
} catch (IOException ex) {
Logger.getLogger(RrdHelper.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例13: build
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
@Override
public MetricsDatabase build() {
checkNotNull(metricName, METRIC_NAME_MSG);
checkNotNull(resourceName, RESOURCE_NAME_MSG);
checkArgument(!dsDefs.isEmpty(), METRIC_TYPE_MSG);
// define the resolution of monitored metrics
rrdDef = new RrdDef(DB_PATH + SPLITTER + metricName +
SPLITTER + resourceName, RESOLUTION_IN_SECOND);
try {
DsDef[] dsDefArray = new DsDef[dsDefs.size()];
IntStream.range(0, dsDefs.size()).forEach(i -> dsDefArray[i] = dsDefs.get(i));
rrdDef.addDatasource(dsDefArray);
rrdDef.setStep(RESOLUTION_IN_SECOND);
// raw archive, no aggregation is required
ArcDef rawArchive = new ArcDef(CONSOL_FUNCTION, XFF_VALUE,
STEP_VALUE, ROW_VALUE);
rrdDef.addArchive(rawArchive);
// always store the metric data in memory...
rrdDb = new RrdDb(rrdDef, RrdBackendFactory.getFactory(STORING_METHOD));
} catch (IOException e) {
log.warn("Failed to create a new round-robin database due to {}", e);
}
return new DefaultMetricsDatabase(metricName, resourceName, rrdDb);
}
示例14: RrdAccessor
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
private RrdAccessor(RrdDb rrdDb) {
this.rrdDb = rrdDb;
try {
this.logger.info("Opened RRD with {} archives and data sources {}.", rrdDb.getArcCount(), Arrays.toString(rrdDb.getDsNames()));
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
示例15: open
import org.rrd4j.core.RrdDb; //导入依赖的package包/类
public static RrdAccessor open(String rrdPath) {
try {
final RrdDb rrdDb = new RrdDb("", "rrdtool:/" + rrdPath, RrdBackendFactory.getFactory("MEMORY"));
rrdDb.getLastUpdateTime();
return new RrdAccessor(rrdDb);
} catch (IOException e) {
throw new RuntimeException("Could not open RRD.", e);
}
}