Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
6dd29f3d
Commit
6dd29f3d
authored
Sep 25, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(LogDB): добавил возможность выбора в каком формате возвращать время
localtime или utc.
parent
94f971d1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
13 deletions
+24
-13
LogDB.cc
extensions/LogDB/LogDB.cc
+17
-11
LogDB.h
extensions/LogDB/LogDB.h
+2
-0
tests.sh
extensions/LogDB/tests/tests.sh
+5
-2
No files found.
extensions/LogDB/LogDB.cc
View file @
6dd29f3d
...
@@ -89,6 +89,11 @@ LogDB::LogDB( const string& name, int argc, const char* const* argv, const strin
...
@@ -89,6 +89,11 @@ LogDB::LogDB( const string& name, int argc, const char* const* argv, const strin
maxdbRecords
=
uniset
::
getArgPInt
(
"--"
+
prefix
+
"db-max-records"
,
argc
,
argv
,
it
.
getProp
(
"dbMaxRecords"
),
qbufSize
);
maxdbRecords
=
uniset
::
getArgPInt
(
"--"
+
prefix
+
"db-max-records"
,
argc
,
argv
,
it
.
getProp
(
"dbMaxRecords"
),
qbufSize
);
maxwsocks
=
uniset
::
getArgPInt
(
"--"
+
prefix
+
"ws-max"
,
argc
,
argv
,
it
.
getProp
(
"wsMax"
),
maxwsocks
);
maxwsocks
=
uniset
::
getArgPInt
(
"--"
+
prefix
+
"ws-max"
,
argc
,
argv
,
it
.
getProp
(
"wsMax"
),
maxwsocks
);
string
tformat
=
uniset
::
getArg2Param
(
"--"
+
prefix
+
"db-timestamp-format"
,
argc
,
argv
,
it
.
getProp
(
"dbTeimastampFormat"
),
"localtime"
);
if
(
tformat
==
"localtime"
||
tformat
==
"utc"
)
tmsFormat
=
tformat
;
double
checkConnection_sec
=
atof
(
uniset
::
getArg2Param
(
"--"
+
prefix
+
"ls-check-connection-sec"
,
argc
,
argv
,
it
.
getProp
(
"lsCheckConnectionSec"
),
"5"
).
c_str
());
double
checkConnection_sec
=
atof
(
uniset
::
getArg2Param
(
"--"
+
prefix
+
"ls-check-connection-sec"
,
argc
,
argv
,
it
.
getProp
(
"lsCheckConnectionSec"
),
"5"
).
c_str
());
int
bufSize
=
uniset
::
getArgPInt
(
"--"
+
prefix
+
"ls-read-buffer-size"
,
argc
,
argv
,
it
.
getProp
(
"lsReadBufferSize"
),
10001
);
int
bufSize
=
uniset
::
getArgPInt
(
"--"
+
prefix
+
"ls-read-buffer-size"
,
argc
,
argv
,
it
.
getProp
(
"lsReadBufferSize"
),
10001
);
...
@@ -315,8 +320,8 @@ void LogDB::addLog( LogDB::Log* log, const string& txt )
...
@@ -315,8 +320,8 @@ void LogDB::addLog( LogDB::Log* log, const string& txt )
ostringstream
q
;
ostringstream
q
;
q
<<
"INSERT INTO logs(tms,usec,name,text) VALUES(
'
"
q
<<
"INSERT INTO logs(tms,usec,name,text) VALUES("
<<
tm
.
tv_sec
<<
"'
,'"
// timestamp
<<
"datetime("
<<
tm
.
tv_sec
<<
",'unixepoch')
,'"
// timestamp
<<
tm
.
tv_nsec
<<
"','"
// usec
<<
tm
.
tv_nsec
<<
"','"
// usec
<<
log
->
name
<<
"','"
<<
log
->
name
<<
"','"
<<
qEscapeString
(
txt
)
<<
"');"
;
<<
qEscapeString
(
txt
)
<<
"');"
;
...
@@ -373,10 +378,11 @@ void LogDB::help_print()
...
@@ -373,10 +378,11 @@ void LogDB::help_print()
cout
<<
"--prefix-single-confile conf.xml - Отдельный конфигурационный файл (не требующий структуры uniset)"
<<
endl
;
cout
<<
"--prefix-single-confile conf.xml - Отдельный конфигурационный файл (не требующий структуры uniset)"
<<
endl
;
cout
<<
"--prefix-name name - Имя. Для поиска настроечной секции в configure.xml"
<<
endl
;
cout
<<
"--prefix-name name - Имя. Для поиска настроечной секции в configure.xml"
<<
endl
;
cout
<<
"database: "
<<
endl
;
cout
<<
"database: "
<<
endl
;
cout
<<
"--prefix-db-buffer-size sz - Размер буфера (до скидывания в БД)."
<<
endl
;
cout
<<
"--prefix-db-buffer-size sz - Размер буфера (до скидывания в БД)."
<<
endl
;
cout
<<
"--prefix-db-max-records sz - Максимальное количество записей в БД. При превышении, старые удаляются. 0 - не удалять"
<<
endl
;
cout
<<
"--prefix-db-max-records sz - Максимальное количество записей в БД. При превышении, старые удаляются. 0 - не удалять"
<<
endl
;
cout
<<
"--prefix-db-overflow-factor float - Коэффициент переполнения, после которого запускается удаление старых записей. По умолчанию: 1.3"
<<
endl
;
cout
<<
"--prefix-db-overflow-factor float - Коэффициент переполнения, после которого запускается удаление старых записей. По умолчанию: 1.3"
<<
endl
;
cout
<<
"--prefix-db-disable - Отключить запись в БД"
<<
endl
;
cout
<<
"--prefix-db-disable - Отключить запись в БД"
<<
endl
;
cout
<<
"--prefix-db-timestamp-format localtime|utc - Формат времени в ответе на запросы. По умолчанию: localtime"
<<
endl
;
cout
<<
"websockets: "
<<
endl
;
cout
<<
"websockets: "
<<
endl
;
cout
<<
"--prefix-ws-max num - Максимальное количество websocket-ов"
<<
endl
;
cout
<<
"--prefix-ws-max num - Максимальное количество websocket-ов"
<<
endl
;
...
@@ -938,9 +944,9 @@ Poco::JSON::Object::Ptr LogDB::httpGetLogs( const Poco::URI::QueryParameters& pa
...
@@ -938,9 +944,9 @@ Poco::JSON::Object::Ptr LogDB::httpGetLogs( const Poco::URI::QueryParameters& pa
else
if
(
p
.
first
==
"limit"
)
else
if
(
p
.
first
==
"limit"
)
limit
=
uni_atoi
(
p
.
second
);
limit
=
uni_atoi
(
p
.
second
);
else
if
(
p
.
first
==
"from"
)
else
if
(
p
.
first
==
"from"
)
q_where
.
push_back
(
"tms>=
CAST(strftime('%s','"
+
qDate
(
p
.
second
)
+
"') AS INT)
"
);
q_where
.
push_back
(
"tms>=
'"
+
qDate
(
p
.
second
)
+
" 00:00:00'
"
);
else
if
(
p
.
first
==
"to"
)
// <-- нужно добавить + 1 день, что диапазон вошёл
else
if
(
p
.
first
==
"to"
)
q_where
.
push_back
(
"tms<=
CAST(strftime('%s','"
+
qDate
(
p
.
second
)
+
"') AS INT) + 24*60*60
"
);
q_where
.
push_back
(
"tms<=
'"
+
qDate
(
p
.
second
)
+
" 23:59:59'
"
);
else
if
(
p
.
first
==
"last"
)
else
if
(
p
.
first
==
"last"
)
q_where
.
push_back
(
qLast
(
p
.
second
));
q_where
.
push_back
(
qLast
(
p
.
second
));
}
}
...
@@ -950,8 +956,8 @@ Poco::JSON::Object::Ptr LogDB::httpGetLogs( const Poco::URI::QueryParameters& pa
...
@@ -950,8 +956,8 @@ Poco::JSON::Object::Ptr LogDB::httpGetLogs( const Poco::URI::QueryParameters& pa
ostringstream
q
;
ostringstream
q
;
q
<<
"SELECT tms,"
q
<<
"SELECT tms,"
<<
" strftime('%d-%m-%Y',datetime(tms,'
unixepoch
')) as date,"
<<
" strftime('%d-%m-%Y',datetime(tms,'
"
<<
tmsFormat
<<
"
')) as date,"
<<
" strftime('%H:%M:%S',datetime(tms,'
unixepoch
')) as time,"
<<
" strftime('%H:%M:%S',datetime(tms,'
"
<<
tmsFormat
<<
"
')) as time,"
<<
" usec, text FROM logs WHERE name='"
<<
logname
<<
"'"
;
<<
" usec, text FROM logs WHERE name='"
<<
logname
<<
"'"
;
if
(
!
q_where
.
empty
()
)
if
(
!
q_where
.
empty
()
)
...
...
extensions/LogDB/LogDB.h
View file @
6dd29f3d
...
@@ -235,6 +235,8 @@ namespace uniset
...
@@ -235,6 +235,8 @@ namespace uniset
std
::
string
myname
;
std
::
string
myname
;
std
::
unique_ptr
<
SQLiteInterface
>
db
;
std
::
unique_ptr
<
SQLiteInterface
>
db
;
std
::
string
tmsFormat
=
{
"localtime"
};
/*!< формат возвращаемого времени */
bool
activate
=
{
false
};
bool
activate
=
{
false
};
typedef
std
::
queue
<
std
::
string
>
QueryBuffer
;
typedef
std
::
queue
<
std
::
string
>
QueryBuffer
;
...
...
extensions/LogDB/tests/tests.sh
View file @
6dd29f3d
...
@@ -13,12 +13,15 @@ function atexit()
...
@@ -13,12 +13,15 @@ function atexit()
{
{
trap
- EXIT
trap
- EXIT
[
-n
"
$LOGSERVER_PID
"
]
&&
kill
$LOGSERVER_PID
2>/dev/null
[
-n
"
$LOGDB_PID
"
]
&&
kill
$LOGDB_PID
2>/dev/null
sleep
4
[
-n
"
$LOGSERVER_PID
"
]
&&
kill
-9
$LOGSERVER_PID
2>/dev/null
[
-n
"
$LOGSERVER_PID
"
]
&&
kill
-9
$LOGSERVER_PID
2>/dev/null
[
-n
"
$LOGDB_PID
"
]
&&
kill
-9
$LOGDB_PID
2>/dev/null
[
-n
"
$LOGDB_PID
"
]
&&
kill
-9
$LOGDB_PID
2>/dev/null
sleep
3
sleep
2
rm
-f
"
$dbfile
*"
[
-a
"
$dbfile
"
]
&&
rm
-f
$dbfile
*
exit
$RET
exit
$RET
}
}
...
...
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