View Javadoc

1   /* ============================================================
2    * JRobin : Pure java implementation of RRDTool's functionality
3    * ============================================================
4    *
5    * Project Info:  http://www.jrobin.org
6    * Project Lead:  Sasa Markovic (saxon@jrobin.org);
7    *
8    * (C) Copyright 2003-2005, by Sasa Markovic.
9    *
10   * Developers:    Sasa Markovic (saxon@jrobin.org)
11   *
12   *
13   * This library is free software; you can redistribute it and/or modify it under the terms
14   * of the GNU Lesser General Public License as published by the Free Software Foundation;
15   * either version 2.1 of the License, or (at your option) any later version.
16   *
17   * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18   * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19   * See the GNU Lesser General Public License for more details.
20   *
21   * You should have received a copy of the GNU Lesser General Public License along with this
22   * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23   * Boston, MA 02111-1307, USA.
24   */
25  package org.jrobin.core;
26  
27  import org.jrobin.core.jrrd.RRDatabase;
28  
29  import java.io.IOException;
30  
31  class RrdToolReader extends DataImporter {
32  	private RRDatabase rrd;
33  
34  	RrdToolReader(String rrdPath) throws IOException {
35  		rrd = new RRDatabase(rrdPath);
36  	}
37  
38  	String getVersion() {
39  		return rrd.getHeader().getVersion();
40  	}
41  
42  	long getLastUpdateTime() {
43  		return Util.getTimestamp(rrd.getLastUpdate());
44  	}
45  
46  	long getStep() {
47  		return rrd.getHeader().getPDPStep();
48  	}
49  
50  	int getDsCount() {
51  		return rrd.getHeader().getDSCount();
52  	}
53  
54  	int getArcCount() throws RrdException, IOException {
55  		return rrd.getNumArchives();
56  	}
57  
58  	String getDsName(int dsIndex) {
59  		return rrd.getDataSource(dsIndex).getName();
60  	}
61  
62  	String getDsType(int dsIndex) {
63  		return rrd.getDataSource(dsIndex).getType().toString();
64  	}
65  
66  	long getHeartbeat(int dsIndex) {
67  		return rrd.getDataSource(dsIndex).getMinimumHeartbeat();
68  	}
69  
70  	double getMinValue(int dsIndex) {
71  		return rrd.getDataSource(dsIndex).getMinimum();
72  	}
73  
74  	double getMaxValue(int dsIndex) {
75  		return rrd.getDataSource(dsIndex).getMaximum();
76  	}
77  
78  	double getLastValue(int dsIndex) {
79  		String valueStr = rrd.getDataSource(dsIndex).getPDPStatusBlock().getLastReading();
80  		return Util.parseDouble(valueStr);
81  	}
82  
83  	double getAccumValue(int dsIndex) {
84  		return rrd.getDataSource(dsIndex).getPDPStatusBlock().getValue();
85  	}
86  
87  	long getNanSeconds(int dsIndex) {
88  		return rrd.getDataSource(dsIndex).getPDPStatusBlock().getUnknownSeconds();
89  	}
90  
91  	String getConsolFun(int arcIndex) {
92  		return rrd.getArchive(arcIndex).getType().toString();
93  	}
94  
95  	double getXff(int arcIndex) {
96  		return rrd.getArchive(arcIndex).getXff();
97  	}
98  
99  	int getSteps(int arcIndex) {
100 		return rrd.getArchive(arcIndex).getPdpCount();
101 	}
102 
103 	int getRows(int arcIndex) throws RrdException, IOException {
104 		return rrd.getArchive(arcIndex).getRowCount();
105 	}
106 
107 	double getStateAccumValue(int arcIndex, int dsIndex) throws RrdException, IOException {
108 		return rrd.getArchive(arcIndex).getCDPStatusBlock(dsIndex).getValue();
109 	}
110 
111 	int getStateNanSteps(int arcIndex, int dsIndex) throws RrdException, IOException {
112 		return rrd.getArchive(arcIndex).getCDPStatusBlock(dsIndex).getUnknownDatapoints();
113 	}
114 
115 	double[] getValues(int arcIndex, int dsIndex) throws RrdException, IOException {
116 		return rrd.getArchive(arcIndex).getValues()[dsIndex];
117 	}
118 
119 	void release() throws IOException {
120 		if (rrd != null) {
121 			rrd.close();
122 			rrd = null;
123 		}
124 	}
125 
126 	protected void finalize() throws Throwable {
127 		super.finalize();
128 		release();
129 	}
130 }