Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
MetaGer
Commits
9c6da5a6
Commit
9c6da5a6
authored
Nov 25, 2019
by
Dominik Hebeler
Browse files
Logs now get saved to disk directly instead over redis
parent
9820f49a
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/Http/Controllers/AdminInterface.php
View file @
9c6da5a6
...
...
@@ -331,10 +331,17 @@ class AdminInterface extends Controller
public
function
check
()
{
$q
=
""
;
$redis
=
Redis
::
connection
(
'redisLogs'
);
if
(
$redis
)
{
$q
=
$redis
->
lrange
(
"logs.search"
,
-
1
,
-
1
)[
0
];
$q
=
substr
(
$q
,
strpos
(
$q
,
"search="
)
+
7
);
$logpath
=
\
App\MetaGer
::
getMGLogFile
();
if
(
file_exists
(
$logpath
))
{
$fp
=
@
fopen
(
$logpath
,
"r"
);
while
((
$line
=
fgets
(
$fp
))
!==
false
)
{
if
(
!
empty
(
$line
))
{
$q
=
$line
;
}
}
fclose
(
$fp
);
$q
=
substr
(
$q
,
strpos
(
$q
,
"eingabe="
)
+
8
);
}
return
view
(
'admin.check'
)
->
with
(
'title'
,
'Wer sucht was? - MetaGer'
)
...
...
app/Http/Controllers/LogController.php
deleted
100644 → 0
View file @
9820f49a
<?php
namespace
App\Http\Controllers
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Redis
;
class
LogController
extends
Controller
{
public
function
clicklog
(
Request
$request
)
{
$redis
=
Redis
::
connection
(
'redisLogs'
);
if
(
$redis
)
{
$logEntry
=
""
;
$logEntry
.
=
"["
.
date
(
DATE_RFC822
,
mktime
(
date
(
"H"
),
date
(
"i"
),
date
(
"s"
),
date
(
"m"
),
date
(
"d"
),
date
(
"Y"
)))
.
"]"
;
$logEntry
.
=
" "
.
$request
->
input
(
'i'
);
$logEntry
.
=
" "
.
$request
->
input
(
's'
);
$logEntry
.
=
" "
.
$request
->
input
(
'q'
);
$logEntry
.
=
" "
.
$request
->
input
(
'p'
);
$logEntry
.
=
" "
.
$request
->
input
(
'url'
);
$redis
->
rpush
(
'logs.clicks'
,
$logEntry
);
}
return
''
;
}
public
function
pluginClose
()
{
$redis
=
Redis
::
connection
(
'redisLogs'
);
if
(
$redis
)
{
$redis
->
incr
(
'logs.plugin.close'
);
}
}
public
function
pluginInstall
()
{
$redis
=
Redis
::
connection
(
'redisLogs'
);
if
(
$redis
)
{
$redis
->
incr
(
'logs.plugin.install'
);
}
}
}
app/MetaGer.php
View file @
9c6da5a6
...
...
@@ -1338,10 +1338,19 @@ class MetaGer
return
$this
->
canCache
;
}
public
static
function
getMGLogFile
()
{
$logpath
=
storage_path
(
"logs/metager/"
);
if
(
!
file_exists
(
$logpath
))
{
mkdir
(
$logpath
,
0777
,
true
);
}
$logpath
.
=
(
new
\
DateTime
())
->
format
(
'Y-m-d'
)
.
".log"
;
return
$logpath
;
}
public
function
createLogs
()
{
if
(
$this
->
shouldLog
)
{
$redis
=
Redis
::
connection
(
'redisLogs'
);
try
{
$logEntry
=
""
;
$logEntry
.
=
"["
.
date
(
"D M d H:i:s"
)
.
"]"
;
...
...
@@ -1364,9 +1373,8 @@ class MetaGer
$logEntry
.
=
" key="
.
$this
->
apiKey
;
$logEntry
.
=
" eingabe="
.
$this
->
eingabe
;
# 2 Arten von Logs in einem wird die Anzahl der Abfragen an eine Suchmaschine gespeichert und in der anderen
# die Anzahl, wie häufig diese Ergebnisse geliefert hat.
$redis
->
rpush
(
'logs.search'
,
$logEntry
);
$logpath
=
\
App\MetaGer
::
getMGLogFile
();
file_put_contents
(
$logpath
,
$logEntry
.
PHP_EOL
,
FILE_APPEND
|
LOCK_EX
);
}
catch
(
\
Exception
$e
)
{
return
;
}
...
...
app/Providers/AppServiceProvider.php
View file @
9c6da5a6
...
...
@@ -4,7 +4,6 @@ namespace App\Providers;
use
Illuminate\Queue\Events\JobProcessed
;
use
Illuminate\Queue\Events\JobProcessing
;
use
Illuminate\Support\Facades\Redis
;
use
Illuminate\Support\ServiceProvider
;
use
Queue
;
use
Request
;
...
...
@@ -35,39 +34,9 @@ class AppServiceProvider extends ServiceProvider
\
App
::
setLocale
(
'es'
);
}
# Wir loggen im Redis-System für jede Sekunde des Tages, wie viele Worker aktiv am Laufen waren.
# Dies ist notwendig, damit wir mitbekommen können, ab welchem Zeitpunkt wir zu wenig Worker zur Verfügung haben.
Queue
::
before
(
function
(
JobProcessing
$event
)
{
$this
->
begin
=
strtotime
(
date
(
DATE_RFC822
,
mktime
(
date
(
"H"
),
date
(
"i"
),
date
(
"s"
),
date
(
"m"
),
date
(
"d"
),
date
(
"Y"
))));
});
Queue
::
after
(
function
(
JobProcessed
$event
)
{
$today
=
strtotime
(
date
(
DATE_RFC822
,
mktime
(
0
,
0
,
0
,
date
(
"m"
),
date
(
"d"
),
date
(
"Y"
))));
$end
=
strtotime
(
date
(
DATE_RFC822
,
mktime
(
date
(
"H"
),
date
(
"i"
),
date
(
"s"
),
date
(
"m"
),
date
(
"d"
),
date
(
"Y"
))))
-
$today
;
$expireAt
=
strtotime
(
date
(
DATE_RFC822
,
mktime
(
0
,
0
,
0
,
date
(
"m"
),
date
(
"d"
)
+
1
,
date
(
"Y"
))));
try
{
$redis
=
Redis
::
connection
(
'redisLogs'
);
if
(
!
$redis
)
{
return
;
}
$p
=
getmypid
();
$host
=
gethostname
();
$begin
=
$this
->
begin
-
$today
;
$redis
->
pipeline
(
function
(
$pipe
)
use
(
$p
,
$expireAt
,
$host
,
$begin
,
$end
)
{
for
(
$i
=
$begin
;
$i
<=
$end
;
$i
++
)
{
$pipe
->
sadd
(
"logs.worker.
$host
.
$i
"
,
strval
(
$p
));
$pipe
->
expire
(
"logs.worker.
$host
.
$i
"
,
10
);
$pipe
->
eval
(
"redis.call('hset', 'logs.worker.
$host
', '
$i
', redis.call('scard', 'logs.worker.
$host
.
$i
'))"
,
0
);
$pipe
->
sadd
(
"logs.worker"
,
$host
);
if
(
date
(
"H"
)
!==
0
)
{
$pipe
->
expire
(
"logs.worker.
$host
"
,
$expireAt
);
$pipe
->
expire
(
"logs.worker"
,
$expireAt
);
}
}
});
}
catch
(
\
Exception
$e
)
{
return
;
}
});
}
...
...
config/database.php
View file @
9c6da5a6
...
...
@@ -135,12 +135,6 @@ return [
'port'
=>
env
(
'REDIS_PORT'
,
6379
),
'database'
=>
0
,
],
'redisLogs'
=>
[
'host'
=>
env
(
'REDIS_LOGS_HOST'
,
'localhost'
),
'password'
=>
env
(
'REDIS_LOGS_PASSWORD'
,
env
(
'REDIS_PASSWORD'
,
null
)),
'port'
=>
env
(
'REDIS_LOGS_PORT'
,
6379
),
'database'
=>
1
,
],
'redisCache'
=>
[
'host'
=>
env
(
'REDIS_CACHE_HOST'
,
'localhost'
),
'password'
=>
env
(
'REDIS_CACHE_PASSWORD'
,
env
(
'REDIS_PASSWORD'
,
null
)),
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment