⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rrdinspector.java

📁 jrobin,使用纯java实现的RRD数据库,使用RRD数据库来统计数据.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			else if (rrdNode.getDsIndex() >= 0) {
				tabbedPane.setSelectedIndex(1);
			}
			else {
				tabbedPane.setSelectedIndex(0);
			}
		}
	}

	private RrdNode getSelectedRrdNode() {
		TreePath path = mainTree.getSelectionPath();
		if (path != null) {
			DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
			Object obj = node.getUserObject();
			if (obj instanceof RrdNode) {
				return (RrdNode) obj;
			}
		}
		return null;
	}

	private void selectFile() {
		JFileChooser chooser = new JFileChooser(lastDirectory);
		FileFilter filter = new FileFilter() {
			public boolean accept(File file) {
				String path = file.getAbsolutePath().toLowerCase();
				return file.isDirectory() || path.endsWith(".rrd") ||
						path.endsWith(".jrb") || path.endsWith(".jrobin");
			}

			public String getDescription() {
				return "JRobin RRD files (*.rrd;*.jrb;*.jrobin)";
			}
		};
		chooser.setFileFilter(filter);
		int returnVal = chooser.showOpenDialog(this);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			File file = chooser.getSelectedFile();
			if (file != null) {
				lastDirectory = file.getParent();
				//inspectorModel.setFile(file);
				//tabbedPane.setSelectedIndex(0);
				loadFile(file);
			}
		}
	}

	private void loadFile(File file) {
		inspectorModel.setFile(file);
		tabbedPane.setSelectedIndex(0);
	}


	private void addDatasource() {
		if (!inspectorModel.isOk()) {
			Util.error(this, "Open a valid RRD file first.");
			return;
		}
		DsDef newDsDef = new EditDatasourceDialog(this, null).getDsDef();
		if (newDsDef != null) {
			// action
			try {
				String sourcePath = inspectorModel.getFile().getCanonicalPath();
				RrdToolkit .addDatasource(sourcePath, newDsDef, SHOULD_CREATE_BACKUPS);
				inspectorModel.refresh();
				tabbedPane.setSelectedIndex(0);
			}
			catch (IOException e) {
				Util.error(this, e);
			}
			catch (RrdException e) {
				Util.error(this, e);
			}
		}
	}

	private void addArchive() {
		if (!inspectorModel.isOk()) {
			Util.error(this, "Open a valid RRD file first.");
			return;
		}
		ArcDef newArcDef = new EditArchiveDialog(this, null).getArcDef();
		if (newArcDef != null) {
			// action
			try {
				String sourcePath = inspectorModel.getFile().getCanonicalPath();
				RrdToolkit.addArchive(sourcePath, newArcDef, SHOULD_CREATE_BACKUPS);
				inspectorModel.refresh();
				tabbedPane.setSelectedIndex(0);
			}
			catch (IOException e) {
				Util.error(this, e);
			}
			catch (RrdException e) {
				Util.error(this, e);
			}
		}
	}

	private void editDatasource() {
		if (!inspectorModel.isOk()) {
			Util.error(this, "Open a valid RRD file first.");
			return;
		}
		RrdNode rrdNode = getSelectedRrdNode();
		int dsIndex;
		if (rrdNode == null || (dsIndex = rrdNode.getDsIndex()) < 0) {
			Util.error(this, "Select datasource first");
			return;
		}
		try {
			String sourcePath = inspectorModel.getFile().getCanonicalPath();
			RrdDb rrd = new RrdDb(sourcePath, true);
			try {
				DsDef dsDef = rrd.getRrdDef().getDsDefs()[dsIndex];
				rrd.close();
				DsDef newDsDef = new EditDatasourceDialog(this, dsDef).getDsDef();
				if (newDsDef != null) {
					// action!
					RrdToolkit.setDsHeartbeat(sourcePath, newDsDef.getDsName(),
							newDsDef.getHeartbeat());
					RrdToolkit.setDsMinMaxValue(sourcePath, newDsDef.getDsName(),
							newDsDef.getMinValue(), newDsDef.getMaxValue(), SHOULD_FIX_ARCHIVED_VALUES);
					inspectorModel.refresh();
					tabbedPane.setSelectedIndex(0);
				}
			}
			finally {
				rrd.close();
			}
		}
		catch (IOException e) {
			Util.error(this, e);
		}
		catch (RrdException e) {
			Util.error(this, e);
		}
	}

	private void editArchive() {
		if (!inspectorModel.isOk()) {
			Util.error(this, "Open a valid RRD file first.");
			return;
		}
		RrdNode rrdNode = getSelectedRrdNode();
		int arcIndex;
		if (rrdNode == null || (arcIndex = rrdNode.getArcIndex()) < 0) {
			Util.error(this, "Select archive first");
			return;
		}
		try {
			String sourcePath = inspectorModel.getFile().getCanonicalPath();
			RrdDb rrd = new RrdDb(sourcePath, true);
			try {
				ArcDef arcDef = rrd.getRrdDef().getArcDefs()[arcIndex];
				rrd.close();
				ArcDef newArcDef = new EditArchiveDialog(this, arcDef).getArcDef();
				if (newArcDef != null) {
					// action!
					// fix X-files factor
					RrdToolkit.setArcXff(sourcePath, newArcDef.getConsolFun(),
							newArcDef.getSteps(), newArcDef.getXff());
					// fix archive size
					RrdToolkit.resizeArchive(sourcePath, newArcDef.getConsolFun(),
							newArcDef.getSteps(), newArcDef.getRows(), SHOULD_CREATE_BACKUPS);
					inspectorModel.refresh();
					tabbedPane.setSelectedIndex(0);
				}
			}
			finally {
				rrd.close();
			}
		}
		catch (IOException e) {
			Util.error(this, e);
		}
		catch (RrdException e) {
			Util.error(this, e);
		}
	}

	private void removeDatasource() {
		if (!inspectorModel.isOk()) {
			Util.error(this, "Open a valid RRD file first.");
			return;
		}
		RrdNode rrdNode = getSelectedRrdNode();
		int dsIndex;
		if (rrdNode == null || (dsIndex = rrdNode.getDsIndex()) < 0) {
			Util.error(this, "Select datasource first");
			return;
		}
		try {
			String sourcePath = inspectorModel.getFile().getCanonicalPath(), dsName;
			RrdDb rrd = new RrdDb(sourcePath, true);
			try {
				dsName = rrd.getRrdDef().getDsDefs()[dsIndex].getDsName();
			}
			finally {
				rrd.close();
			}
			RrdToolkit.removeDatasource(sourcePath, dsName, SHOULD_CREATE_BACKUPS);
			inspectorModel.refresh();
			tabbedPane.setSelectedIndex(0);
		}
		catch (IOException e) {
			Util.error(this, e);
		}
		catch (RrdException e) {
			Util.error(this, e);
		}
	}

	private void removeArchive() {
		if (!inspectorModel.isOk()) {
			Util.error(this, "Open a valid RRD file first.");
			return;
		}
		RrdNode rrdNode = getSelectedRrdNode();
		int arcIndex;
		if (rrdNode == null || (arcIndex = rrdNode.getArcIndex()) < 0) {
			Util.error(this, "Select archive first");
			return;
		}
		try {
			String sourcePath = inspectorModel.getFile().getCanonicalPath(), consolFun;
			int steps;
			RrdDb rrd = new RrdDb(sourcePath, true);
			try {
				ArcDef arcDef = rrd.getRrdDef().getArcDefs()[arcIndex];
				consolFun = arcDef.getConsolFun();
				steps = arcDef.getSteps();
			}
			finally {
				rrd.close();
			}
			RrdToolkit.removeArchive(sourcePath, consolFun, steps, SHOULD_CREATE_BACKUPS);
			inspectorModel.refresh();
			tabbedPane.setSelectedIndex(0);
		}
		catch (IOException e) {
			Util.error(this, e);
		}
		catch (RrdException e) {
			Util.error(this, e);
		}
	}

	private void plotArchive() {
		if (!inspectorModel.isOk()) {
			Util.error(this, "Open a valid RRD file first.");
			return;
		}
		RrdNode rrdNode = getSelectedRrdNode();
		int arcIndex;
		if (rrdNode == null || (arcIndex = rrdNode.getArcIndex()) < 0) {
			Util.error(this, "Select archive first");
			return;
		}
		String sourcePath = inspectorModel.getFile().getAbsolutePath();
		int dsIndex = rrdNode.getDsIndex();
		new GraphFrame(sourcePath, dsIndex, arcIndex);
	}

	private static void printUsageAndExit() {
		System.err.println("usage: " + RrdInspector.class.getName() + " [<filename>]");
		System.exit(1);
	}

	/**
	 * <p>To start the application use the following syntax:</p>
	 * <pre>
	 * java -cp JRobinLite.jar org.jrobin.inspector.RrdInspector
	 * java -cp JRobinLite.jar org.jrobin.inspector.RrdInspector [path to RRD file]
	 * </pre>
	 *
	 * @param args
	 */
	public static void main(String[] args) {
		if (args.length > 1) {
			printUsageAndExit();
		}
		String path = (args.length == 1) ? args[0] : null;
		new RrdInspector(path);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -