nidas  v1.2-1520
Public Member Functions | Private Member Functions | Private Attributes | List of all members
InfluxDB Class Reference

Methods and memory for creating an Influx database, accumulating measurements, and posting them to the database. More...

Public Member Functions

 InfluxDB (const std::string &url="", const std::string &dbname="")
 
bool isOpen ()
 
void open ()
 Initialize for http database connections. More...
 
void setURL (const std::string &url)
 
void setDatabase (const std::string &dbname)
 
std::string getDatabase ()
 
void setUser (const std::string &username, const std::string &passwordfile)
 Set username to use for the http connection. More...
 
std::string getAuth (const std::string &prefix="")
 
void setCount (unsigned int count)
 
void setEcho (bool echo)
 If echo is true, the data posted to the database is printed on stdout instead of being written to the database. More...
 
void setAsync (bool enable)
 If enable is true, data will be posted to the database asynchronously. More...
 
 ~InfluxDB ()
 
std::string getHostURL ()
 
std::string getWriteURL ()
 
std::string getErrors ()
 
bool addMeasurement (const std::string &data)
 Return false if there is an error adding this measurement. More...
 
bool sendData ()
 
unsigned int totalMeasurements ()
 Return the total number of measurements written to the database so far. More...
 
void flush ()
 Send whatever is left in the current buffer and wait for it to finish. More...
 
void createInfluxDB ()
 
void handleResult (CURLcode res)
 

Private Member Functions

 InfluxDB (const InfluxDB &)
 
InfluxDBoperator= (const InfluxDB &)
 

Private Attributes

string _url
 
string _dbname
 
string _username
 
string _password
 
CharBuffer_data
 
CharBuffer _data1
 
CharBuffer _data2
 
CharBuffer _result
 
string _errs
 
unsigned int _nmeasurements
 
unsigned int _total_measurements
 
unsigned int _count
 
bool _echo
 
bool _async
 
CURL * _curl
 
char _curl_errors [CURL_ERROR_SIZE]
 
std::future< CURLcode > _post
 

Detailed Description

Methods and memory for creating an Influx database, accumulating measurements, and posting them to the database.

The host URL is something like "http://snoopy.eol.ucar.edu:8086"

The database URL is formed like "<url>/write?db=<dbname>&precision=u"

Constructor & Destructor Documentation

InfluxDB::InfluxDB ( const std::string &  url = "",
const std::string &  dbname = "" 
)
inline
InfluxDB::~InfluxDB ( )
inline
InfluxDB::InfluxDB ( const InfluxDB )
private

Member Function Documentation

bool InfluxDB::addMeasurement ( const std::string &  data)
inline

Return false if there is an error adding this measurement.

If enough measurements have accumulated, then this will post the current buffer to the database. If there is an error, the description will be in getError().

References VLOG.

void InfluxDB::createInfluxDB ( )

References ILOG.

void InfluxDB::flush ( )
inline

Send whatever is left in the current buffer and wait for it to finish.

References ILOG.

std::string InfluxDB::getAuth ( const std::string &  prefix = "")
inline

References prefix.

std::string InfluxDB::getDatabase ( )
inline
std::string InfluxDB::getErrors ( )
inline
std::string InfluxDB::getHostURL ( )
inline
std::string InfluxDB::getWriteURL ( )
inline
void InfluxDB::handleResult ( CURLcode  res)
inline

References DLOG.

bool InfluxDB::isOpen ( )
inline
void InfluxDB::open ( )
inline

Initialize for http database connections.

No database actions can be performed before this initialization happens, but the initialization only happens once. This will be called implicitly by other methods which need http. Do not call it if the database will not actually be used, such as when echo is enabled.

References writeInfluxResult().

InfluxDB& InfluxDB::operator= ( const InfluxDB )
private
bool InfluxDB::sendData ( )
inline

References dataToInfluxDB(), and DLOG.

void InfluxDB::setAsync ( bool  enable)
inline

If enable is true, data will be posted to the database asynchronously.

void InfluxDB::setCount ( unsigned int  count)
inline
void InfluxDB::setDatabase ( const std::string &  dbname)
inline
void InfluxDB::setEcho ( bool  echo)
inline

If echo is true, the data posted to the database is printed on stdout instead of being written to the database.

void InfluxDB::setURL ( const std::string &  url)
inline
void InfluxDB::setUser ( const std::string &  username,
const std::string &  passwordfile 
)
inline

Set username to use for the http connection.

If passwordfile is not empty, then open the file at the given path to read the password.

References ILOG.

unsigned int InfluxDB::totalMeasurements ( )
inline

Return the total number of measurements written to the database so far.

This does not include the measurements currently in the buffer and not yet written.

Member Data Documentation

bool InfluxDB::_async
private
unsigned int InfluxDB::_count
private
CURL* InfluxDB::_curl
private
char InfluxDB::_curl_errors[CURL_ERROR_SIZE]
private
CharBuffer* InfluxDB::_data
private
CharBuffer InfluxDB::_data1
private
CharBuffer InfluxDB::_data2
private
string InfluxDB::_dbname
private
bool InfluxDB::_echo
private
string InfluxDB::_errs
private
unsigned int InfluxDB::_nmeasurements
private
string InfluxDB::_password
private
std::future<CURLcode> InfluxDB::_post
private
CharBuffer InfluxDB::_result
private
unsigned int InfluxDB::_total_measurements
private
string InfluxDB::_url
private
string InfluxDB::_username
private

The documentation for this class was generated from the following file: