Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MetaGer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
MetaGer
Commits
343ad345
Commit
343ad345
authored
6 years ago
by
Dominik Hebeler
Browse files
Options
Downloads
Patches
Plain Diff
Extended count script
parent
ebbc468d
No related branches found
Branches containing commit
No related tags found
1 merge request
!1414
Extended count script
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/Http/Controllers/AdminInterface.php
+59
-43
59 additions, 43 deletions
app/Http/Controllers/AdminInterface.php
app/get_dates.awk
+9
-0
9 additions, 0 deletions
app/get_dates.awk
resources/views/admin/count.blade.php
+26
-7
26 additions, 7 deletions
resources/views/admin/count.blade.php
with
94 additions
and
50 deletions
app/Http/Controllers/AdminInterface.php
+
59
−
43
View file @
343ad345
...
...
@@ -16,18 +16,20 @@ class AdminInterface extends Controller
// Now we gonna check which stats we can find
$stati
=
array
();
foreach
(
$names
as
$name
){
foreach
(
$names
as
$name
)
{
$stats
=
Redis
::
hgetall
(
$name
.
".stats"
);
if
(
sizeof
(
$stats
)
>
0
){
if
(
sizeof
(
$stats
)
>
0
)
{
$fetcherStatus
=
Redis
::
get
(
$name
);
$stati
[
$name
][
"status"
]
=
$fetcherStatus
;
foreach
(
$stats
as
$pid
=>
$value
){
if
(
strstr
(
$value
,
";"
)){
foreach
(
$stats
as
$pid
=>
$value
)
{
if
(
strstr
(
$value
,
";"
))
{
$value
=
explode
(
";"
,
$value
);
$connection
=
json_decode
(
base64_decode
(
$value
[
0
]),
true
);
foreach
(
$connection
as
$key
=>
$val
){
if
(
strstr
(
$key
,
"_time"
))
foreach
(
$connection
as
$key
=>
$val
)
{
if
(
strstr
(
$key
,
"_time"
))
{
$stati
[
$name
][
"fetcher"
][
$pid
][
"connection"
][
$key
]
=
$val
;
}
}
$stati
[
$name
][
"fetcher"
][
$pid
][
"poptime"
]
=
$value
[
1
];
}
...
...
@@ -37,21 +39,21 @@ class AdminInterface extends Controller
// So now we can generate Median Times for every Fetcher
$fetcherCount
=
0
;
foreach
(
$stati
as
$engineName
=>
$engineStats
){
foreach
(
$stati
as
$engineName
=>
$engineStats
)
{
$connection
=
array
();
$poptime
=
0
;
$fetcherCount
+=
sizeof
(
$engineStats
[
"fetcher"
]);
foreach
(
$engineStats
[
"fetcher"
]
as
$pid
=>
$stats
){
foreach
(
$stats
[
"connection"
]
as
$key
=>
$value
){
if
(
!
isset
(
$connection
[
$key
])){
foreach
(
$engineStats
[
"fetcher"
]
as
$pid
=>
$stats
)
{
foreach
(
$stats
[
"connection"
]
as
$key
=>
$value
)
{
if
(
!
isset
(
$connection
[
$key
]))
{
$connection
[
$key
]
=
$value
;
}
else
{
}
else
{
$connection
[
$key
]
+=
$value
;
}
}
$poptime
+=
floatval
(
$stats
[
"poptime"
]);
}
foreach
(
$connection
as
$key
=>
$value
){
foreach
(
$connection
as
$key
=>
$value
)
{
$connection
[
$key
]
/=
sizeof
(
$engineStats
[
"fetcher"
]);
}
$poptime
/=
sizeof
(
$engineStats
[
"fetcher"
]);
...
...
@@ -70,13 +72,14 @@ class AdminInterface extends Controller
return
$response
;
}
private
function
getSearchEngineNames
(){
private
function
getSearchEngineNames
()
{
$url
=
config_path
()
.
"/sumas.xml"
;
$xml
=
simplexml_load_file
(
$url
);
$sumas
=
$xml
->
xpath
(
"suma"
);
$names
=
array
();
foreach
(
$sumas
as
$suma
){
foreach
(
$sumas
as
$suma
)
{
$names
[]
=
$suma
[
"name"
]
->
__toString
();
}
return
$names
;
...
...
@@ -85,30 +88,43 @@ class AdminInterface extends Controller
public
function
count
(
Request
$request
)
{
$days
=
intval
(
$request
->
input
(
'days'
,
28
));
if
(
!
is_int
(
$days
)
||
$days
<=
0
)
$days
=
28
;
$logToday
=
"mg3.log"
;
if
(
file_exists
(
"/var/log/metager/"
.
$logToday
))
{
$logToday
=
file
(
"/var/log/metager/"
.
$logToday
);
$interface
=
$request
->
input
(
'interface'
,
'all'
);
if
(
!
is_int
(
$days
)
||
$days
<=
0
)
{
$days
=
28
;
}
$logToday
=
"/var/log/metager/mg3.log"
;
if
(
file_exists
(
$logToday
))
{
if
(
$interface
===
"all"
)
{
$logToday
=
exec
(
"cat
$logToday
| wc -l"
);
}
else
{
$logToday
=
exec
(
"cat
$logToday
| grep interface="
.
$interface
.
" | wc -l"
);
}
}
else
{
return
redirect
(
''
);
}
$oldLogs
=
[];
$yesterday
=
0
;
$rekordTag
=
0
;
$oldLogs
=
[];
$rekordTag
=
0
;
$rekordTagDate
=
""
;
$size
=
0
;
$count
=
0
;
$size
=
0
;
$count
=
0
;
for
(
$i
=
1
;
$i
<=
$days
;
$i
++
)
{
$logDate
=
"/var/log/metager/archive/mg3.log.
$i
"
;
if
(
file_exists
(
$logDate
))
{
$sameTime
=
exec
(
"grep -n '"
.
date
(
'H'
)
.
":"
.
date
(
'i'
)
.
":'
$logDate
| tail -1 | cut -f1 -d':'"
);
$insgesamt
=
exec
(
"wc -l
$logDate
| cut -f1 -d' '"
);
if
(
$interface
===
"all"
)
{
$sameTime
=
exec
(
"awk -v hour=
\"
"
.
date
(
'H'
)
.
"
\"
-v minute=
\"
"
.
date
(
'i'
)
.
"
\"
-v second=
\"
"
.
date
(
's'
)
.
"
\"
-f "
.
app_path
(
'get_dates.awk'
)
.
" "
.
$logDate
.
" | wc -l"
);
$insgesamt
=
exec
(
"wc -l
$logDate
| cut -f1 -d' '"
);
}
else
{
$sameTime
=
exec
(
"awk -v hour=
\"
"
.
date
(
'H'
)
.
"
\"
-v minute=
\"
"
.
date
(
'i'
)
.
"
\"
-v second=
\"
"
.
date
(
's'
)
.
"
\"
-f "
.
app_path
(
'get_dates.awk'
)
.
" "
.
$logDate
.
" | grep interface="
.
$interface
.
" | wc -l"
);
$insgesamt
=
exec
(
"cat
$logDate
| grep interface="
.
$interface
.
" | wc -l"
);
}
if
(
$insgesamt
>
$rekordTag
)
{
$rekordTag
=
$insgesamt
;
$rekordTag
=
$insgesamt
;
$rekordTagSameTime
=
$sameTime
;
$rekordTagDate
=
date
(
"d.m.Y"
,
mktime
(
date
(
"H"
),
date
(
"i"
),
date
(
"s"
),
date
(
"m"
),
date
(
"d"
)
-
$i
,
date
(
"Y"
)));
$rekordTagDate
=
date
(
"d.m.Y"
,
mktime
(
date
(
"H"
),
date
(
"i"
),
date
(
"s"
),
date
(
"m"
),
date
(
"d"
)
-
$i
,
date
(
"Y"
)));
}
$oldLogs
[
$i
][
'sameTime'
]
=
number_format
(
floatval
(
$sameTime
),
0
,
","
,
"."
);
$oldLogs
[
$i
][
'sameTime'
]
=
number_format
(
floatval
(
$sameTime
),
0
,
","
,
"."
);
$oldLogs
[
$i
][
'insgesamt'
]
=
number_format
(
floatval
(
$insgesamt
),
0
,
","
,
"."
);
# Nun noch den median:
$count
+=
$insgesamt
;
...
...
@@ -120,34 +136,34 @@ class AdminInterface extends Controller
}
}
if
(
$request
->
input
(
'out'
,
'web'
)
===
"web"
){
if
(
$request
->
input
(
'out'
,
'web'
)
===
"web"
)
{
return
view
(
'admin.count'
)
->
with
(
'title'
,
'Suchanfragen - MetaGer'
)
->
with
(
'today'
,
number_format
(
floatval
(
sizeof
(
$logToday
)
)
,
0
,
","
,
"."
))
->
with
(
'today'
,
number_format
(
floatval
(
$logToday
),
0
,
","
,
"."
))
->
with
(
'oldLogs'
,
$oldLogs
)
->
with
(
'rekordCount'
,
number_format
(
floatval
(
$rekordTag
),
0
,
","
,
"."
))
->
with
(
'rekordTagSameTime'
,
number_format
(
floatval
(
$rekordTagSameTime
),
0
,
","
,
"."
))
->
with
(
'rekordDate'
,
$rekordTagDate
)
->
with
(
'days'
,
$days
);
}
else
{
$result
=
""
;
foreach
(
$oldLogs
as
$key
=>
$value
){
$resultTmp
=
'"'
.
date
(
"D, d M y"
,
mktime
(
date
(
"H"
),
date
(
"i"
),
date
(
"s"
),
date
(
"m"
),
date
(
"d"
)
-
$key
,
date
(
"Y"
)))
.
'",'
;
$resultTmp
.
=
'"'
.
$value
[
'sameTime'
]
.
'",'
;
$resultTmp
.
=
'"'
.
$value
[
'insgesamt'
]
.
'",'
;
$resultTmp
.
=
'"'
.
$value
[
'median'
]
.
'"'
.
"
\r\n
"
;
$result
=
$resultTmp
.
$result
;
}
return
response
(
$result
,
200
)
->
header
(
'Content-Type'
,
'text/csv'
)
->
header
(
'Content-Disposition'
,
'attachment; filename="count.csv"'
);
}
else
{
$result
=
""
;
foreach
(
$oldLogs
as
$key
=>
$value
)
{
$resultTmp
=
'"'
.
date
(
"D, d M y"
,
mktime
(
date
(
"H"
),
date
(
"i"
),
date
(
"s"
),
date
(
"m"
),
date
(
"d"
)
-
$key
,
date
(
"Y"
)))
.
'",'
;
$resultTmp
.
=
'"'
.
$value
[
'sameTime'
]
.
'",'
;
$resultTmp
.
=
'"'
.
$value
[
'insgesamt'
]
.
'",'
;
$resultTmp
.
=
'"'
.
$value
[
'median'
]
.
'"'
.
"
\r\n
"
;
$result
=
$resultTmp
.
$result
;
}
return
response
(
$result
,
200
)
->
header
(
'Content-Type'
,
'text/csv'
)
->
header
(
'Content-Disposition'
,
'attachment; filename="count.csv"'
);
}
}
public
function
check
()
{
$q
=
""
;
$q
=
""
;
$redis
=
Redis
::
connection
(
'redisLogs'
);
if
(
$redis
)
{
$q
=
$redis
->
lrange
(
"logs.search"
,
-
1
,
-
1
)[
0
];
...
...
This diff is collapsed.
Click to expand it.
app/get_dates.awk
0 → 100644
+
9
−
0
View file @
343ad345
BEGIN
{
end_t
=
mktime
(
"2019 02 25 "
hour
" "
minute
" "
second
)
FS
=
"[: \\]]"
}
{
now
=
mktime
(
"2019 02 25 "
$4
" "
$5
" "
$6
)
if
(
now
<=
end_t
)
{
print
}
}
This diff is collapsed.
Click to expand it.
resources/views/admin/count.blade.php
+
26
−
7
View file @
343ad345
...
...
@@ -3,9 +3,30 @@
@
section
(
'title'
,
$title
)
@
section
(
'content'
)
<
h2
>
{{
exec
(
"uptime"
)
}}
</
h2
>
<
p
>
{{
exec
(
"uptime"
)
}}
</
p
>
@
if
(
isset
(
$rekordDate
)
&&
isset
(
$rekordTagSameTime
)
&&
isset
(
$rekordCount
)
)
<
p
>
Rekord
am
{{
$rekordDate
}}
zur
gleichen
Zeit
<
span
class
=
"text-info"
>
{{
$rekordTagSameTime
}}
</
span
>
-
insgesamt
<
span
class
=
"text-danger"
>
{{
$rekordCount
}}
</
span
></
p
>
@
endif
<
p
>
Mittelwert
der
letzten
{{
sizeof
(
$oldLogs
)
}}
Tage
:
{{
$oldLogs
[
sizeof
(
$oldLogs
)][
'median'
]
}}
</
p
>
<
table
class
=
"table table-striped"
>
<
caption
>
Daten
der
letzten
<
form
method
=
"POST"
><
input
type
=
"number"
name
=
"days"
value
=
"
{
{$days}
}
"
/>
Tage
<
button
type
=
"submit"
class
=
"btn btn-sm btn-default"
>
Aktualisieren
</
button
><
button
type
=
"submit"
name
=
"out"
value
=
"csv"
class
=
"btn btn-sm btn-default"
>
Als
CSV
exportieren
</
button
></
form
></
caption
>
<
caption
>
<
form
method
=
"POST"
style
=
"display: flex; align-items: center;"
>
<
div
class
=
"form-group"
style
=
"max-width: 100px; margin-right: 8px;"
>
<
label
for
=
"days"
>
Tage
</
label
>
<
input
class
=
"form-control"
type
=
"number"
id
=
"days"
name
=
"days"
value
=
"
{
{$days}
}
"
/>
</
div
>
<
div
class
=
"form-group"
style
=
"max-width: 100px; margin-right: 8px;"
>
<
label
for
=
"interface"
>
Sprache
</
label
>
<
select
class
=
"form-control"
name
=
"interface"
id
=
"interface"
><
option
value
=
"all"
{{
(
Request
::
input
(
'interface'
,
'all'
)
==
"all"
?
"selected"
:
""
)}}
>
Alle
</
option
><
option
value
=
"de"
{{
(
Request
::
input
(
'interface'
,
'all'
)
==
"de"
?
"selected"
:
""
)}}
>
DE
</
option
><
option
value
=
"en"
{{
(
Request
::
input
(
'interface'
,
'all'
)
==
"en"
?
"selected"
:
""
)}}
>
EN
</
option
></
select
>
</
div
>
<
div
id
=
"refresh"
style
=
"margin-top: 11px; margin-right: 8px;"
>
<
button
type
=
"submit"
class
=
"btn btn-sm btn-default"
>
Aktualisieren
</
button
>
</
div
>
<
div
id
=
"export"
style
=
"margin-top: 11px;"
>
<
button
type
=
"submit"
name
=
"out"
value
=
"csv"
class
=
"btn btn-sm btn-default"
>
Als
CSV
exportieren
</
button
>
</
div
>
</
form
>
</
caption
>
<
tr
>
<
th
>
Datum
</
th
>
<
th
>
Suchanfragen
zur
gleichen
Zeit
</
th
>
...
...
@@ -14,7 +35,7 @@
</
tr
>
@
if
(
isset
(
$today
)
)
<
tr
>
<
td
>
{{
date
(
"D, d M y"
,
mktime
(
date
(
"H"
),
date
(
"i"
),
date
(
"s"
),
date
(
"m"
),
date
(
"d"
),
date
(
"Y"
))
)
}}
</
td
>
<
td
>
{{
Carbon
::
now
()
->
format
(
'D, d.m.Y'
)
}}
</
td
>
<
td
>
{{
$today
}}
</
td
>
<
td
>???</
td
>
<
td
>???</
td
>
...
...
@@ -22,14 +43,12 @@
@
endif
@
foreach
(
$oldLogs
as
$key
=>
$value
)
<
tr
>
<
td
>
{{
date
(
"D, d M y"
,
mktime
(
date
(
"H"
),
date
(
"i"
),
date
(
"s"
),
date
(
"m"
),
date
(
"d"
)
-
$key
,
date
(
"Y"
))
)
}}
</
td
>
<
td
>
{{
Carbon
::
now
()
->
subDays
(
$key
)
->
format
(
'D, d.m.Y'
)
}}
</
td
>
<
td
>
{{
$value
[
'sameTime'
]
}}
</
td
>
<
td
>
{{
$value
[
'insgesamt'
]
}}
</
td
>
<
td
>
{{
$value
[
'median'
]
}}
</
td
>
</
tr
>
@
endforeach
</
table
>
@
if
(
isset
(
$rekordDate
)
&&
isset
(
$rekordTagSameTime
)
&&
isset
(
$rekordCount
)
)
<
h3
>
Rekord
am
{{
$rekordDate
}}
zur
gleichen
Zeit
<
span
class
=
"text-info"
>
{{
$rekordTagSameTime
}}
</
span
>
-
insgesamt
<
span
class
=
"text-danger"
>
{{
$rekordCount
}}
</
span
></
h3
>
@
endif
@
endsection
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment