java.lang.Object
org.rrd4j.core.jrrd.RRDatabase
- All Implemented Interfaces:
Closeable, AutoCloseable
Instances of this class model Round Robin Database (RRD) files.
Field Summary
FieldsModifier and TypeFieldDescriptionThe file's archives.private final ArrayList<DataSource> The file's data sources.(package private) final HeaderThe header(package private) final DateTimestamp of last data modificationprivate final StringThe RRD file's name.Data source name to index(package private) final RRDFileThe RRD fileConstructor Summary
ConstructorsConstructorDescriptionRRDatabase(File file) Creates a database to read from.RRDatabase(String name) Creates a database to read from.Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this database stream and releases any associated system resources.private ArchivefindBestArchive(long start, long end, long step, ArrayList<Archive> archives) Chooses the archive that answers a request most accurately, almost a verbatim copy of the original C code by Tobias Oetiker.getArchive(int index) Returns theArchiveat the specified position in this database.getArchive(String name) Look up an archive by its name.Collect the archives consolidated with the given function, in definition order.Returns an iterator over the archives in this database in proper sequence.Returns an iterator over the archives in this database of the given type in proper sequence.Returns data from the database corresponding to the given consolidation function and a step size of 1.getData(ConsolidationFunctionType type, long startTime, long endTime, long stepSeconds) Read consolidated data over a time range at a given step.getData(ConsolidationFunctionType type, Date startDate, Date endDate, long step) Returns data from the database corresponding to the given consolidation function.getDataSource(int index) Returns theDataSourceat the specified position in this database.Returns an iterator over the data sources in this database in proper sequence.Returns the names of the data sources defined in the database header.Returns theHeaderfor this database.Returns the date this database was last updated.intReturns the number of archives in this database.voidOutputs the header information of the database to the given print stream using the default number format.voidprintInfo(PrintStream s, NumberFormat numberFormat) Outputs the header information of the database to the given print stream using the given number format.toString()Returns a summary the contents of this database.voidtoXml(PrintStream s) Outputs the content of the database to the given print stream as a stream of XML.
Field Details
rrdFile
The RRD filename
The RRD file's name.header
The headerdataSources
The file's data sources.archives
lastUpdate
Timestamp of last data modificationnameindex
Constructor Details
RRDatabase
Creates a database to read from.- Parameters:
name- the filename of the file to read from.- Throws:
IOException- if an I/O error occurs.
RRDatabase
Creates a database to read from.- Parameters:
file- the file to read from.- Throws:
IOException- if an I/O error occurs.
Method Details
getHeader
getDataSourcesName
getLastUpdate
Returns the date this database was last updated. To convert this date to the form returned byrrdtool lastcall Date.getTime() and divide the result by 1000.- Returns:
- the date this database was last updated.
getDataSource
Returns theDataSourceat the specified position in this database.- Parameters:
index- index ofDataSourceto return.- Returns:
- the
DataSourceat the specified position in this database
getDataSources
Returns an iterator over the data sources in this database in proper sequence.- Returns:
- an iterator over the data sources in this database in proper sequence.
getArchive
Returns theArchiveat the specified position in this database.- Parameters:
index- index ofArchiveto return.- Returns:
- the
Archiveat the specified position in this database.
getArchive
getArchives
getNumArchives
public int getNumArchives()Returns the number of archives in this database.- Returns:
- the number of archives in this database.
getArchives
Returns an iterator over the archives in this database of the given type in proper sequence.- Parameters:
type- the consolidation function that should have been applied to the data.- Returns:
- an iterator over the archives in this database of the given type in proper sequence.
getArchiveList
Collect the archives consolidated with the given function, in definition order.- Parameters:
type- the consolidation function whose archives to collect- Returns:
- the matching archives, empty if the database holds none
close
Closes this database stream and releases any associated system resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an I/O error occurs.
printInfo
Outputs the header information of the database to the given print stream using the default number format. The default format fordoubleis 0.0000000000E0.- Parameters:
s- the PrintStream to print the header information to.
getData
Returns data from the database corresponding to the given consolidation function and a step size of 1.- Parameters:
type- the consolidation function that should have been applied to the data.- Returns:
- the raw data.
- Throws:
IllegalArgumentException- if there was a problem locating a data archive with the requested consolidation function.IOException- if there was a problem reading data from the database.
getData
public DataChunk getData(ConsolidationFunctionType type, Date startDate, Date endDate, long step) throws IOException Returns data from the database corresponding to the given consolidation function.- Parameters:
type- the consolidation function that should have been applied to the data.startDate- aDateobject.endDate- aDateobject.step- the step size to use.- Returns:
- the raw data.
- Throws:
IllegalArgumentException- if there was a problem locating a data archive with the requested consolidation function.IOException- if there was a problem reading data from the database.
getData
public DataChunk getData(ConsolidationFunctionType type, long startTime, long endTime, long stepSeconds) throws IOException Read consolidated data over a time range at a given step.- Parameters:
type- aConsolidationFunctionTypeobject.startTime- seconds since epochendTime- seconds since epochstepSeconds- resolution of the returned data, in seconds- Returns:
- a
DataChunkobject. - Throws:
IOException- if the archive cannot be read
findBestArchive
Chooses the archive that answers a request most accurately, almost a verbatim copy of the original C code by Tobias Oetiker.- Parameters:
start- the requested start timeend- the requested end timestep- the requested resolutionarchives- the archives to choose from- Returns:
- the archive that fits best
printInfo
Outputs the header information of the database to the given print stream using the given number format. The format is almost identical to that produced by rrdtool info- Parameters:
s- the PrintStream to print the header information to.numberFormat- the format to printdoubles as.
toXml
Outputs the content of the database to the given print stream as a stream of XML. The XML format is almost identical to that produced by rrdtool dumpA flush is issued at the end of the XML generation, so auto flush of the PrintStream can be set to false
- Parameters:
s- the PrintStream to send the XML to.
toString