Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
a42ae915
Commit
a42ae915
authored
Sep 13, 2019
by
Daniele Tafani
Browse files
Cleaned Makefile
parent
eacba56a
Changes
5
Hide whitespace changes
Inline
Side-by-side
grafana/GrafanaServer.cpp
View file @
a42ae915
...
...
@@ -214,6 +214,7 @@ int main(int argc, char *argv[])
}
_httpsServer
=
new
RestAPI
(
restAPISettings
,
hierarchySettings
,
_cassandraConnection
);
//_httpsServer = new RestAPI(restAPISettings, hierarchySettings);
_configuration
->
readRestAPIUsers
(
_httpsServer
);
if
(
globalSettings
.
daemonize
)
{
...
...
@@ -235,7 +236,7 @@ int main(int argc, char *argv[])
//dummy to keep io service alive even if no tasks remain (e.g. because all sensors have been stopped over REST API)
keepAliveWork
=
boost
::
make_shared
<
boost
::
asio
::
io_service
::
work
>
(
io
);
//Create pool of threads which handle the sensors
for
(
size_t
i
=
0
;
i
<
globalSettings
.
threads
;
i
++
)
{
threads
.
create_thread
(
bind
(
static_cast
<
size_t
(
boost
::
asio
::
io_service
::*
)
()
>
(
&
boost
::
asio
::
io_service
::
run
),
&
io
));
...
...
@@ -259,7 +260,7 @@ int main(int argc, char *argv[])
LOG
(
trace
)
<<
"Running..."
;
//Run until Strg+C
threads
.
join_all
();
//
threads.join_all();
//will only continue if interrupted by SIGINT and threads were stopped
...
...
grafana/Makefile
View file @
a42ae915
include
../config.mk
CXXFLAGS
=
-O2
\
--std
=
c++11
\
-Wno-unused-local-typedefs
\
-Wno-deprecated-declarations
\
-Wno-unknown-warning-option
\
-fmessage-length
=
0
\
-I
../common/include/
\
CXXFLAGS
+=
-I
../common/include/
\
-I
../lib/include
\
-I
$(DCDBDEPLOYPATH)
/include
\
-DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
\
-DBOOST_LOG_DYN_LINK
\
-DBOOST_TEST_DYN_LINK
-I
$(DCDBDEPLOYPATH)
/include
OBJS
=
../common/src/sensornavigator.o
\
../common/src/globalconfiguration.o
\
../common/src/RESTHttpsServer.o
\
../common/src/logging.o
\
GrafanaServer.o
\
RestAPI.o
\
Configuration.o
../common/src/globalconfiguration.o
\
../common/src/RESTHttpsServer.o
\
../common/src/logging.o
\
GrafanaServer.o
\
RestAPI.o
\
Configuration.o
LIBS
=
-L
$(DCDBDEPLOYPATH)
/lib/
\
-L
../lib
\
...
...
@@ -31,7 +22,6 @@ LIBS = -L$(DCDBDEPLOYPATH)/lib/ \
-lboost_log
\
-lboost_regex
\
-lboost_log_setup
\
-lpthread
\
-lcrypto
\
-lssl
...
...
@@ -46,7 +36,6 @@ $(TARGET): $(OBJS)
@
LD_LIBRARY_PATH
=
$(DCDBDEPLOYPATH)
/lib:
$$
LD_LIBRARY_PATH
\
$(CXX)
$(CXXFLAGS)
-o
$(TARGET)
$(OBJS)
$(LIBS)
all
:
$(TARGET)
debug
:
CXXFLAGS += -DDEBUG
...
...
grafana/RestAPI.cpp
View file @
a42ae915
...
...
@@ -36,11 +36,11 @@
std::placeholders::_2, \
std::placeholders::_3)
DCDB
::
Connection
*
conn
;
RestAPI
::
RestAPI
(
serverSettings_t
settings
,
hierarchySettings_t
hierarchySettings
,
DCDB
::
Connection
*
cassandraConnection
)
:
RESTHttpsServer
(
settings
),
_connection
(
cassandraConnection
)
{
hierarchySettings_t
hierarchySettings
)
:
RESTHttpsServer
(
settings
)
{
//Configuring endpoints
addEndpoint
(
"/"
,
{
http
::
verb
::
get
,
stdBind
(
GET_datasource
)});
...
...
@@ -48,26 +48,43 @@ RestAPI::RestAPI(serverSettings_t settings,
addEndpoint
(
"/search"
,
{
http
::
verb
::
post
,
stdBind
(
POST_search
)});
addEndpoint
(
"/query"
,
{
http
::
verb
::
post
,
stdBind
(
POST_query
)});
//_connection = cassandraConnection;
std
::
cout
<<
"Trying connecting..."
<<
std
::
endl
;
conn
=
new
DCDB
::
Connection
();
conn
->
setHostname
(
"127.0.0.1"
);
conn
->
setPort
(
atoi
(
"9042"
));
// if (!conn->connect()) {
// LOG(fatal) << "Failed to connect to the Cassandra database!";
// }
LOG
(
info
)
<<
"Retrieving published sensor names and topics..."
;
//Get the list of all public sensors and topics.
std
::
list
<
DCDB
::
PublicSensor
>
publicSensors
;
_sensorConfig
=
new
DCDB
::
SensorConfig
(
_connection
);
_sensorConfig
->
getPublicSensorsVerbose
(
publicSensors
);
std
::
vector
<
std
::
string
>
sensors
;
std
::
vector
<
std
::
string
>
topics
;
for
(
auto
s
:
publicSensors
)
{
sensors
.
push_back
(
s
.
name
);
topics
.
push_back
(
s
.
pattern
);
}
//Build the tree navigator
LOG
(
info
)
<<
"Building the sensor navigator..."
;
// std::list<DCDB::PublicSensor> publicSensors;
// DCDB::SensorConfig sensorConfig(conn);
//sensorConfig.getPublicSensorsVerbose(publicSensors);
_navigator
=
new
SensorNavigator
();
_navigator
->
buildTree
(
hierarchySettings
.
regex
,
&
sensors
,
&
topics
,
hierarchySettings
.
separator
);
//_sensorConfig = new DCDB::SensorConfig(cassandraConnection);
//_sensorConfig->getPublicSensorsVerbose(publicSensors);
//
// std::vector<std::string> sensors;
// std::vector<std::string> topics;
//
// for(auto& s : publicSensors) {
// sensors.push_back(s.name);
// topics.push_back(s.pattern);
// }
//
// //Build the tree navigator
// LOG(info) << "Building the sensor navigator...";
//
// _navigator = new SensorNavigator();
// std::cout << "Ok" << std::endl;
// _navigator->buildTree(hierarchySettings.regex, &sensors, &topics, hierarchySettings.separator);
// std::cout << "Ok" << std::endl;
}
//Dummy GET request to create a datasource. All necessary checks that could be peformed here are
...
...
@@ -203,8 +220,12 @@ void::RestAPI::POST_query(endpointArgs) {
for
(
auto
&
sensorName
:
sensors
)
{
DCDB
::
Sensor
sensor
(
_connection
,
sensorName
);
_sensorConfig
->
getPublicSensorByName
(
ps
,
sensorName
.
c_str
());
// DCDB::SensorConfig sc(_connection);
// DCDB::Sensor sensor(_connection, sensorName);
DCDB
::
SensorConfig
sc
(
conn
);
DCDB
::
Sensor
sensor
(
conn
,
sensorName
);
//_sensorConfig->getPublicSensorByName(ps,sensorName.c_str());
sc
.
getPublicSensorByName
(
ps
,
sensorName
.
c_str
());
//Shoot the query for this sensor.
std
::
list
<
DCDB
::
SensorDataStoreReading
>
results
;
...
...
@@ -217,7 +238,9 @@ void::RestAPI::POST_query(endpointArgs) {
datapoints
+=
"["
+
std
::
to_string
(
r
.
value
*
ps
.
scaling_factor
)
+
","
+
std
::
to_string
(
r
.
timeStamp
.
getRaw
()
/
1000000
)
+
"],"
;
datapoints
.
pop_back
();
if
(
datapoints
.
back
()
==
','
)
datapoints
.
pop_back
();
datapoints
+=
"]"
;
res
.
body
()
+=
"{
\"
target
\"
:
\"
"
+
sensorName
+
"
\"
,
\"
datapoints
\"
:"
+
datapoints
+
"},"
;
}
...
...
grafana/RestAPI.h
View file @
a42ae915
...
...
@@ -51,9 +51,11 @@
class
RestAPI
:
public
RESTHttpsServer
{
public:
RestAPI
(
serverSettings_t
settings
,
hierarchySettings_t
hierarchySettings
,
DCDB
::
Connection
*
cassandraConnection
);
hierarchySettings_t
hierarchySettings
);
// RestAPI(serverSettings_t settings,
// hierarchySettings_t hierarchySettings,
// DCDB::Connection* cassandraConnection);
//
virtual
~
RestAPI
()
{}
private:
...
...
grafana/config/grafana.conf
View file @
a42ae915
global
{
threads
24
threads
1
verbosity
3
daemonize
false
tempdir
.
...
...
@@ -10,14 +10,18 @@ cassandra {
}
hierarchy
{
separator
,
;
regex
mpp3
.,
r
\\
d
{
2
}.,
c
\\
d
{
2
}.,
s
\\
d
{
2
}.,
cpu
\\
d
+
regex
/
mpp2
,/
r
\\
d
{
2
},/
c
\\
d
{
2
},/
s
\\
d
{
2
}
}
restAPI
{
address
127
.
0
.
0
.
1
:
8081
certificate
../..
/
deps
/
openssl
-
1
.
1
.
1
c
/
test
/
certs
/
ca
-
cert
.
pem
privateKey
../..
/
deps
/
openssl
-
1
.
1
.
1
c
/
test
/
certs
/
ca
-
key
.
pem
dhFile
../..
/
deps
/
openssl
-
1
.
1
.
1
c
/
crypto
/
dh
/
dh2048
.
pem
certificate
/
Users
/
di34bap
/
Projects
/
dcdb
-
grafana
/
deps
/
openssl
-
1
.
1
.
1
c
/
test
/
certs
/
ca
-
cert
.
pem
privateKey
/
Users
/
di34bap
/
Projects
/
dcdb
-
grafana
/
deps
/
openssl
-
1
.
1
.
1
c
/
test
/
certs
/
ca
-
key
.
pem
dhFile
/
Users
/
di34bap
/
Projects
/
dcdb
-
grafana
/
deps
/
openssl
-
1
.
1
.
1
c
/
crypto
/
dh
/
dh2048
.
pem
user
user1
{
...
...
@@ -32,7 +36,7 @@ restAPI {
POST
}
user
user3
{
user
user3
{
password
pass3
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment