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
efc4efb5
Commit
efc4efb5
authored
5 years ago
by
Dominik Hebeler
Browse files
Options
Downloads
Patches
Plain Diff
admin interface working again
parent
0d504944
No related branches found
No related tags found
2 merge requests
!1502
Development
,
!1500
Resolve "Fix Admin Interface"
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/Http/Controllers/AdminInterface.php
+47
-6
47 additions, 6 deletions
app/Http/Controllers/AdminInterface.php
app/Jobs/ConvertCountFile.php
+12
-7
12 additions, 7 deletions
app/Jobs/ConvertCountFile.php
with
59 additions
and
13 deletions
app/Http/Controllers/AdminInterface.php
+
47
−
6
View file @
efc4efb5
...
@@ -87,8 +87,48 @@ class AdminInterface extends Controller
...
@@ -87,8 +87,48 @@ class AdminInterface extends Controller
return
$names
;
return
$names
;
}
}
private
function
convertLogs
()
{
$oldLogsPath
=
\storage_path
(
"logs/metager/old/"
);
$dir
=
new
\DirectoryIterator
(
$oldLogsPath
);
foreach
(
$dir
as
$fileinfo
)
{
if
(
$fileinfo
->
isDot
())
{
continue
;
}
$filename
=
$oldLogsPath
.
"/"
.
$fileinfo
->
getFilename
();
$daysAgo
=
substr
(
$fileinfo
->
getFilename
(),
strrpos
(
$fileinfo
->
getFilename
(),
"."
)
+
1
);
$dateOfFile
=
Carbon
::
now
()
->
subDays
(
$daysAgo
);
$outputFile
=
\storage_path
(
"logs/metager/"
.
$dateOfFile
->
format
(
"Y/m/d"
)
.
".log"
);
if
(
!
file_exists
(
dirname
(
$outputFile
)))
{
\mkdir
(
dirname
(
$outputFile
),
0777
,
true
);
}
$fhw
=
fopen
(
$outputFile
,
"w"
);
$fhr
=
fopen
(
$filename
,
"r"
);
try
{
$first
=
true
;
while
((
$line
=
fgets
(
$fhr
))
!=
false
)
{
$date
=
trim
(
substr
(
$line
,
0
,
strpos
(
$line
,
"]"
)),
"["
);
$date
=
trim
(
substr
(
$date
,
strrpos
(
$date
,
" "
)));
$rest
=
trim
(
substr
(
$line
,
strpos
(
$line
,
"]"
)
+
1
));
$outputString
=
""
;
if
(
!
$first
)
{
$outputString
.
=
PHP_EOL
;
}
$outputString
.
=
$date
.
" "
.
$rest
;
$first
=
false
;
fwrite
(
$fhw
,
$outputString
);
}
}
finally
{
fclose
(
$fhw
);
fclose
(
$fhr
);
}
}
}
public
function
count
(
Request
$request
)
public
function
count
(
Request
$request
)
{
{
#$this->convertLogs();
#return;
$days
=
intval
(
$request
->
input
(
'days'
,
28
));
$days
=
intval
(
$request
->
input
(
'days'
,
28
));
$interface
=
$request
->
input
(
'interface'
,
'all'
);
$interface
=
$request
->
input
(
'interface'
,
'all'
);
if
(
!
is_int
(
$days
)
||
$days
<=
0
)
{
if
(
!
is_int
(
$days
)
||
$days
<=
0
)
{
...
@@ -98,6 +138,7 @@ class AdminInterface extends Controller
...
@@ -98,6 +138,7 @@ class AdminInterface extends Controller
$oldLogs
=
[];
$oldLogs
=
[];
$rekordTag
=
0
;
$rekordTag
=
0
;
$rekordTagSameTime
=
0
;
$minCount
=
0
;
$minCount
=
0
;
$rekordTagDate
=
""
;
$rekordTagDate
=
""
;
$size
=
0
;
$size
=
0
;
...
@@ -249,14 +290,14 @@ class AdminInterface extends Controller
...
@@ -249,14 +290,14 @@ class AdminInterface extends Controller
$days
=
$maxDate
->
diffInDays
(
Carbon
::
now
());
$days
=
$maxDate
->
diffInDays
(
Carbon
::
now
());
}
}
$logToday
=
"/var/log/m
eta
g
er
/mg3.log"
;
$logToday
=
\App\M
eta
G
er
::
getMGLogFile
()
;
$archivePath
=
"/var/
log/metager/
archive/
"
;
$archivePath
=
storage_path
(
"
log
s
/metager/"
)
;
$today
=
[
$today
=
[
'logFile'
=>
$logToday
,
'logFile'
=>
$logToday
,
'countPath'
=>
storage_path
(
'logs/count/'
),
'countPath'
=>
storage_path
(
'logs/
metager/
count/'
),
'countFile'
=>
storage_path
(
'logs/count/'
.
getmypid
()),
'countFile'
=>
storage_path
(
'logs/
metager/
count/'
.
getmypid
()),
];
];
if
(
\file_exists
(
$today
[
"countFile"
]))
{
if
(
\file_exists
(
$today
[
"countFile"
]))
{
unlink
(
$today
[
"countFile"
]);
unlink
(
$today
[
"countFile"
]);
...
@@ -271,10 +312,10 @@ class AdminInterface extends Controller
...
@@ -271,10 +312,10 @@ class AdminInterface extends Controller
$requestedLogs
=
[];
$requestedLogs
=
[];
for
(
$i
=
1
;
$i
<=
$days
;
$i
++
)
{
for
(
$i
=
1
;
$i
<=
$days
;
$i
++
)
{
$date
=
Carbon
::
now
()
->
subDays
(
$i
);
$date
=
Carbon
::
now
()
->
subDays
(
$i
);
$countPath
=
storage_path
(
'logs/count/'
.
$date
->
year
.
"/"
.
$date
->
month
.
"/"
);
$countPath
=
storage_path
(
'logs/
metager/
count/'
.
$date
->
format
(
"Y/m"
)
.
"/"
);
$countFile
=
$countPath
.
$date
->
day
.
".json"
;
$countFile
=
$countPath
.
$date
->
day
.
".json"
;
$neededLogs
[
$i
]
=
[
$neededLogs
[
$i
]
=
[
'logFile'
=>
$archivePath
.
"mg3
.log
.
$i
"
,
'logFile'
=>
$archivePath
.
$date
->
format
(
"Y/m/d"
)
.
"
.log"
,
'countPath'
=>
$countPath
,
'countPath'
=>
$countPath
,
'countFile'
=>
$countFile
,
'countFile'
=>
$countFile
,
];
];
...
...
This diff is collapsed.
Click to expand it.
app/Jobs/ConvertCountFile.php
+
12
−
7
View file @
efc4efb5
...
@@ -39,6 +39,7 @@ class ConvertCountFile implements ShouldQueue
...
@@ -39,6 +39,7 @@ class ConvertCountFile implements ShouldQueue
];
];
$fh
=
false
;
$fh
=
false
;
$fullRound
=
false
;
$fullRound
=
false
;
$error
=
false
;
try
{
try
{
$fh
=
fopen
(
$this
->
files
[
"logFile"
],
"r"
);
$fh
=
fopen
(
$this
->
files
[
"logFile"
],
"r"
);
$currentLogTime
=
Carbon
::
now
()
->
hour
(
0
)
->
minute
(
0
)
->
second
(
0
)
->
addMinutes
(
5
);
$currentLogTime
=
Carbon
::
now
()
->
hour
(
0
)
->
minute
(
0
)
->
second
(
0
)
->
addMinutes
(
5
);
...
@@ -47,7 +48,7 @@ class ConvertCountFile implements ShouldQueue
...
@@ -47,7 +48,7 @@ class ConvertCountFile implements ShouldQueue
$logTime
=
[];
$logTime
=
[];
$interface
=
""
;
$interface
=
""
;
// i.e. [Wed Apr 17 00:00:01] ref=https://metager.de/ time=0.51 serv=web interface=de
// i.e. [Wed Apr 17 00:00:01] ref=https://metager.de/ time=0.51 serv=web interface=de
if
(
preg_match
(
'/
\[[a-zA-z]{3}\s[a-zA-Z]{3}\s\d{2}\s
(\d{2}:\d{2}:\d{2}).*?\sinterface=(\S+)/'
,
$line
,
$matches
))
{
if
(
preg_match
(
'/(\d{2}:\d{2}:\d{2}).*?\sinterface=(\S+)/'
,
$line
,
$matches
))
{
// Create Date Object
// Create Date Object
$logTime
=
explode
(
":"
,
$matches
[
1
]);
$logTime
=
explode
(
":"
,
$matches
[
1
]);
$interface
=
$matches
[
2
];
$interface
=
$matches
[
2
];
...
@@ -84,18 +85,22 @@ class ConvertCountFile implements ShouldQueue
...
@@ -84,18 +85,22 @@ class ConvertCountFile implements ShouldQueue
if
(
empty
(
$result
[
"time"
][
$currentLogTime
->
format
(
'H:i'
)]))
{
if
(
empty
(
$result
[
"time"
][
$currentLogTime
->
format
(
'H:i'
)]))
{
$result
[
"time"
][
$currentLogTime
->
format
(
'H:i'
)]
=
$result
[
"insgesamt"
];
$result
[
"time"
][
$currentLogTime
->
format
(
'H:i'
)]
=
$result
[
"insgesamt"
];
}
}
}
catch
(
\ErrorException
$e
)
{
$error
=
true
;
}
finally
{
}
finally
{
if
(
$fh
!==
false
)
{
if
(
$fh
!==
false
)
{
fclose
(
$fh
);
fclose
(
$fh
);
}
}
$oldUmask
=
umask
(
0
);
if
(
!
$error
)
{
// Write the result to a File
$oldUmask
=
umask
(
0
);
if
(
!
file_exists
(
$this
->
files
[
"countPath"
]))
{
// Write the result to a File
mkdir
(
$this
->
files
[
"countPath"
],
0777
,
true
);
if
(
!
file_exists
(
$this
->
files
[
"countPath"
]))
{
mkdir
(
$this
->
files
[
"countPath"
],
0777
,
true
);
}
file_put_contents
(
$this
->
files
[
"countFile"
],
json_encode
(
$result
,
JSON_PRETTY_PRINT
));
umask
(
$oldUmask
);
}
}
file_put_contents
(
$this
->
files
[
"countFile"
],
json_encode
(
$result
,
JSON_PRETTY_PRINT
));
umask
(
$oldUmask
);
Redis
::
del
(
md5
(
$this
->
files
[
"countFile"
]));
Redis
::
del
(
md5
(
$this
->
files
[
"countFile"
]));
}
}
...
...
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