1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 }