nidas v1.2.3
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.
 
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.
 
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.
 
void setAsync (bool enable)
 If enable is true, data will be posted to the database asynchronously.
 
 ~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.
 
bool sendData ()
 
unsigned int totalMeasurements ()
 Return the total number of measurements written to the database so far.
 
void flush ()
 Send whatever is left in the current buffer and wait for it to finish.
 
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() [1/2]

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

References _data, and _data1.

◆ ~InfluxDB()

InfluxDB::~InfluxDB ( )
inline

References _curl, and nidas::core::getSample().

◆ InfluxDB() [2/2]

InfluxDB::InfluxDB ( const InfluxDB & )
private

Member Function Documentation

◆ addMeasurement()

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 _count, _data, _nmeasurements, nidas::core::getSample(), CharBuffer::getSpace(), sendData(), and VLOG.

Referenced by SampleToDatabase::accumulate().

◆ createInfluxDB()

void InfluxDB::createInfluxDB ( )

◆ flush()

void InfluxDB::flush ( )
inline

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

References getErrors(), ILOG, and sendData().

◆ getAuth()

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

◆ getDatabase()

std::string InfluxDB::getDatabase ( )
inline

References _dbname.

◆ getErrors()

std::string InfluxDB::getErrors ( )
inline

References _errs.

Referenced by SampleToDatabase::accumulate(), and flush().

◆ getHostURL()

std::string InfluxDB::getHostURL ( )
inline

References _url.

Referenced by createInfluxDB(), and getWriteURL().

◆ getWriteURL()

std::string InfluxDB::getWriteURL ( )
inline

◆ handleResult()

void InfluxDB::handleResult ( CURLcode res)
inline

◆ isOpen()

bool InfluxDB::isOpen ( )
inline

References _curl.

Referenced by open(), and sendData().

◆ open()

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 _curl, _curl_errors, _result, nidas::core::getSample(), isOpen(), and writeInfluxResult().

Referenced by createInfluxDB(), and sendData().

◆ operator=()

InfluxDB & InfluxDB::operator= ( const InfluxDB & )
private

◆ sendData()

bool InfluxDB::sendData ( )
inline

◆ setAsync()

void InfluxDB::setAsync ( bool enable)
inline

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

References _async.

◆ setCount()

void InfluxDB::setCount ( unsigned int count)
inline

References _count.

◆ setDatabase()

void InfluxDB::setDatabase ( const std::string & dbname)
inline

◆ setEcho()

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.

References _echo, and nidas::core::getSample().

◆ setURL()

void InfluxDB::setURL ( const std::string & url)
inline

References _url, and nidas::core::getSample().

◆ setUser()

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 _password, _username, nidas::core::getSample(), and ILOG.

◆ totalMeasurements()

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.

References _total_measurements.

Member Data Documentation

◆ _async

bool InfluxDB::_async
private

Referenced by sendData(), and setAsync().

◆ _count

unsigned int InfluxDB::_count
private

Referenced by addMeasurement(), and setCount().

◆ _curl

CURL* InfluxDB::_curl
private

◆ _curl_errors

char InfluxDB::_curl_errors[CURL_ERROR_SIZE]
private

Referenced by handleResult(), and open().

◆ _data

CharBuffer* InfluxDB::_data
private

Referenced by addMeasurement(), InfluxDB(), and sendData().

◆ _data1

CharBuffer InfluxDB::_data1
private

Referenced by InfluxDB(), and sendData().

◆ _data2

CharBuffer InfluxDB::_data2
private

Referenced by sendData().

◆ _dbname

string InfluxDB::_dbname
private

◆ _echo

bool InfluxDB::_echo
private

Referenced by sendData(), and setEcho().

◆ _errs

string InfluxDB::_errs
private

◆ _nmeasurements

unsigned int InfluxDB::_nmeasurements
private

Referenced by addMeasurement(), and sendData().

◆ _password

string InfluxDB::_password
private

Referenced by getAuth(), and setUser().

◆ _post

std::future<CURLcode> InfluxDB::_post
private

Referenced by sendData().

◆ _result

CharBuffer InfluxDB::_result
private

Referenced by handleResult(), and open().

◆ _total_measurements

unsigned int InfluxDB::_total_measurements
private

Referenced by sendData(), and totalMeasurements().

◆ _url

string InfluxDB::_url
private

Referenced by getHostURL(), and setURL().

◆ _username

string InfluxDB::_username
private

Referenced by getAuth(), and setUser().


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