Commit fe43dcef authored by Axel Auweter's avatar Axel Auweter
Browse files

dcdbquery now reports time stamps in human readable form.

Use the -r option to get raw values instead.
parent 950a6495
include ../config.mk
CXXFLAGS = -O0 -g --std=c++11 -Wall -Wno-unused-local-typedefs -Wno-unknown-warning-option -fmessage-length=0 -I$(DCDBDEPLOYPATH)/include/ -I$(DCDBBASEPATH)/include/
CXXFLAGS = -O0 -g --std=c++11 -Wall -Wno-unused-local-typedefs -Wno-unknown-warning-option -fmessage-length=0 -I$(DCDBDEPLOYPATH)/include/ -I$(DCDBBASEPATH)/include/ -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
OBJS = collectagent.o \
simplemqttserver.o \
simplemqttserverthread.o \
......
......@@ -3,7 +3,7 @@ include ../config.mk
# C++ Compiler Flags (use fPIC for our dynamic library)
CXXFLAGS = -O0 -ggdb -Wall -Werror -Wno-unused-local-typedefs -Wno-unknown-warning-option\
-fPIC --std=c++11 -I$(DCDBDEPLOYPATH)/include -I./include -I./include_internal\
-I$(DCDBBASEPATH)/include/ -fmessage-length=0
-I$(DCDBBASEPATH)/include/ -fmessage-length=0 -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
# List of object files to build and the derived list of corresponding source files
OBJS = src/sensordatastore.o \
......
......@@ -73,6 +73,12 @@ public:
*/
uint64_t getRaw(void);
/**
* @brief Returns the time stamp's value as human readable string
* @return The object's value as std::string.
*/
std::string getString(void);
/**
* @brief Returns the "weekstamp" corresponding to the object's value
* @return The week number of the timestamp.
......
......@@ -98,6 +98,20 @@ uint64_t DCDBTimeStamp::getRaw(void)
return raw;
}
/**
*
*/
std::string DCDBTimeStamp::getString(void)
{
#ifndef BOOST_DATE_TIME_HAS_NANOSECONDS
#error Needs nanoseconds support in boost.
#endif
boost::posix_time::ptime t(boost::gregorian::date(1970,1,1));
t += boost::posix_time::nanoseconds(raw);
return boost::posix_time::to_iso_extended_string(t);
}
/**
*
*/
......
include ../../config.mk
CXXFLAGS = -O0 -ggdb --std=c++11 -Wall -Wno-unused-local-typedefs -Wno-unknown-warning-option -fmessage-length=0 -I$(DCDBDEPLOYPATH)/include/ -I$(DCDBBASEPATH)/include/
CXXFLAGS = -O0 -ggdb --std=c++11 -Wall -Wno-unused-local-typedefs -Wno-unknown-warning-option -fmessage-length=0 -I$(DCDBDEPLOYPATH)/include/ -I$(DCDBBASEPATH)/include/ -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
OBJS = dcdbquery.o query.o casshelper.o
LIBS = -L$(DCDBDEPLOYPATH)/lib/ -ldcdb -lcassandra -luv -lboost_random -lboost_system -lboost_date_time
TARGET = dcdbquery
......
......@@ -21,15 +21,17 @@ void usage(void)
{
/* 0---------1---------2---------3---------4---------5---------6---------7--------- */
std::cout << "Usage:" << std::endl
<< "dcdbquery [-h <hostname>] <Sensor 1> [<Sensor 2> ...] <Start> <End>" << std::endl
<< "dcdbquery [-h <hostname>] [-r] <Sensor 1> [<Sensor 2> ...] <Start> <End>" << std::endl
<< "where" << std::endl
<< " <hostname> - the name of the DB server"
<< " <hostname> - the name of the DB server" << std::endl
<< " <Sensor n> - a public sensor name" << std::endl
<< " <Start> - start of time series" << std::endl
<< " <End> - end of time series" << std::endl
<< "Return the readings for the sensors in the interval from <Start> to <End>." << std::endl
<< "<Start> and <End> times should be supplied as 'yyyy-mm-dd hh:mm:ss' or unix" << std::endl
<< "timestamps." << std::endl;
<< "timestamps." << std::endl
<< "When the -r option is specified, timestamps will be reported in internal (raw)" << std::endl
<< "format (nanoseconds since epoch) insted of ISO human readable form." << std::endl;
exit(EXIT_SUCCESS);
}
......@@ -40,14 +42,18 @@ int main(int argc, char* argv[])
usage();
}
/* Get the hostname */
/* Get the options */
char ret;
const char *host = "localhost";
while ((ret=getopt(argc, argv, "+h:"))!=EOF) {
bool raw = false;
while ((ret=getopt(argc, argv, "+h:r"))!=EOF) {
switch(ret) {
case 'h':
host = optarg;
break;
case 'r':
raw = true;
break;
default:
usage();
exit(EXIT_FAILURE);
......@@ -77,7 +83,7 @@ int main(int argc, char* argv[])
sensors.push_back(argv[arg]);
}
DCDBQuery::doQuery(host, sensors, start, end);
DCDBQuery::doQuery(host, sensors, start, end, raw);
return 0;
}
......@@ -22,7 +22,7 @@
#include "casshelper.h"
/* Lovely spaghetti code coming up next. Be aware... */
void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DCDBTimeStamp start, DCDBTimeStamp end)
void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DCDBTimeStamp start, DCDBTimeStamp end, bool raw)
{
/* Connect to db */
CassCluster *cluster = CassHelper::create_cluster(hostname);
......@@ -53,7 +53,7 @@ void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DC
/* Print the CSV header */
std::cout << *it << ",Time,Value" << std::endl;
querySensorsCSV(session, *it, sidList, start, end);
querySensorsCSV(session, *it, sidList, start, end, raw);
}
/* Clean up */
......@@ -278,7 +278,7 @@ bool DCDBQuery::sidPatternMatch(SensorId& sid, std::string pattern)
return true;
}
void DCDBQuery::querySensorsCSV(CassSession* session, std::string sensorName, std::list<SensorId>& sidList, DCDBTimeStamp& start, DCDBTimeStamp& end)
void DCDBQuery::querySensorsCSV(CassSession* session, std::string sensorName, std::list<SensorId>& sidList, DCDBTimeStamp& start, DCDBTimeStamp& end, bool raw)
{
/* Since everything has been mangled until here, we assume parameter safety and do a non-prepared statement... Oh oh... */
std::stringstream query;
......@@ -312,8 +312,14 @@ void DCDBQuery::querySensorsCSV(CassSession* session, std::string sensorName, st
cass_value_get_int64(cass_row_get_column_by_name(row, "ts"), &ts);
cass_value_get_int64(cass_row_get_column_by_name(row, "value"), &value);
if (raw) {
std::cout << sensorName << "," << std::dec << ts << "," << std::dec << value << std::endl;
}
else {
DCDBTimeStamp t((uint64_t)ts);
std::cout << sensorName << "," << t.getString() << "," << std::dec << value << std::endl;
}
}
}
cass_statement_free(statement);
cass_future_free(future);
......
......@@ -20,7 +20,7 @@
class DCDBQuery
{
public:
static void doQuery(const char* hostname, std::list<std::string> sensors, DCDBTimeStamp start, DCDBTimeStamp end);
static void doQuery(const char* hostname, std::list<std::string> sensors, DCDBTimeStamp start, DCDBTimeStamp end, bool raw);
protected:
static void lookupPublishedSensorPattern(CassSession* session, std::string name, std::string& pattern);
......@@ -28,7 +28,7 @@ protected:
static bool topicToSid(SensorId& sid, std::string topic);
static std::string sidConvert(SensorId& sid);
static bool sidPatternMatch(SensorId& sid, std::string pattern);
static void querySensorsCSV(CassSession* session, std::string sensorName, std::list<SensorId>& sidList, DCDBTimeStamp& start, DCDBTimeStamp& end);
static void querySensorsCSV(CassSession* session, std::string sensorName, std::list<SensorId>& sidList, DCDBTimeStamp& start, DCDBTimeStamp& end, bool raw);
};
......
......@@ -41,7 +41,7 @@ DISTFILESNAMES = $(foreach f,$(DISTFILES),$(shell echo "$(f)" | sed 's/;.*//'))
DISTFILESPATHS = $(foreach f,$(DISTFILES),$(shell echo "$(f)" | sed 's/.tar.gz;.*//' | sed 's/.zip;.*//' ))
CFLAGS += -I$(DCDBDEPLOYPATH)/include -O0 -g
CXX11FLAGS = --std=c++11 -Wno-c99-extensions -Wno-missing-field-initializers
CXX11FLAGS = --std=c++11 -Wno-c99-extensions -Wno-missing-field-initializers -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
LDFLAGS += -L$(DCDBDEPLOYPATH)/lib -O0 -g
.PHONY : info all clean cleanall distclean $(LIBRARIES) $(PROJECTS)
......@@ -169,7 +169,7 @@ $(DCDBDEPSPATH)/.prerequesites: $(DCDBDEPSPATH)/.extract-distfiles
fi; \
cd $(DCDBDEPSPATH)/$(B) && ./bootstrap.sh --prefix=$(DCDBDEPLOYPATH) \
--with-libraries=atomic,chrono,date_time,exception,filesystem,program_options,random,system,thread,timer && \
./b2 -j $(MAKETHREADS) install && touch $(DCDBDEPSPATH)/$(B)/.installed; \
./b2 -j $(MAKETHREADS) cxxflags="$(CXX11FLAGS)" install && touch $(DCDBDEPSPATH)/$(B)/.installed; \
else \
echo "Skipping Boost (already built)..."; \
fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment