This commit is contained in:
Bruno Eckhardt committed 2026-02-16 16:37:54 +01:00
1 parent 0fcfb816db
commit fb8acbb749
2 files changed
+96 -32

No files matched your search

-3
View File
@@ -31,9 +31,6 @@ $db_res = DatabaseShow(
<p style="margin: 5px 0;"><strong>Home IP:</strong>
<code><?= htmlspecialchars($db_res[0]['HOME_IP']) ?></code>
</p>
<p style="margin: 5px 0;"><strong>TEST</strong>
<code>HELLO</code>
</p>
</div>
</div>
+96 -29
View File
@@ -1,16 +1,55 @@
<?php
$conn = db_connect();
$sql = "SELECT DATE(FIRST_REQUEST) as tag, COUNT(*) as anzahl FROM logs WHERE WEBSITE = 'blackpi.ipv64.net' OR WEBSITE IS NULL GROUP BY DATE(FIRST_REQUEST) ORDER BY DATE(FIRST_REQUEST)";
$result = $conn->query($sql);
// Dataset: Gesamte Logs
$sql_total = "SELECT DATE(FIRST_REQUEST) as tag, COUNT(*) as anzahl FROM logs GROUP BY DATE(FIRST_REQUEST) ORDER BY DATE(FIRST_REQUEST)";
$result_total = $conn->query($sql_total);
$labels = [];
$data = [];
$totalDataAssoc = [];
$allLabels = [];
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$labels[] = $row['tag'];
$data[] = (int)$row['anzahl'];
if ($result_total->num_rows > 0) {
while($row = $result_total->fetch_assoc()) {
$date = $row['tag'];
$totalDataAssoc[$date] = (int)$row['anzahl'];
$allLabels[] = $date;
}
}
// Nodes
$nodes = ['node1','node2','node3','node4'];
$nodeDataAssoc = [];
foreach ($nodes as $node) {
$sql = "SELECT DATE(FIRST_REQUEST) as tag, COUNT(*) as anzahl FROM logs WHERE SERVER_IP = '$node' GROUP BY DATE(FIRST_REQUEST)";
$result = $conn->query($sql);
$data = [];
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$date = $row['tag'];
$data[$date] = (int)$row['anzahl'];
if (!in_array($date, $allLabels)) {
$allLabels[] = $date;
}
}
}
$nodeDataAssoc[$node] = $data;
}
// Alle Labels chronologisch sortieren
sort($allLabels);
// Finales Array: Gesamt + Nodes
$finalTotalData = [];
$finalNodeData = [];
foreach ($allLabels as $label) {
$finalTotalData[] = isset($totalDataAssoc[$label]) ? $totalDataAssoc[$label] : 0;
foreach ($nodes as $node) {
if (!isset($finalNodeData[$node])) $finalNodeData[$node] = [];
$finalNodeData[$node][] = isset($nodeDataAssoc[$node][$label]) ? $nodeDataAssoc[$node][$label] : 0;
}
}
@@ -24,28 +63,61 @@ $conn->close();
<meta charset="UTF-8">
<title>Logs Chart</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom"></script>
</head>
<body>
<canvas id="logChart" width="600" height="400"></canvas>
<canvas id="logChart" width="900" height="500"></canvas>
<script>
const ctx = document.getElementById('logChart').getContext('2d');
const logChart = new Chart(ctx, {
type: 'line',
data: {
labels: <?php echo json_encode($labels); ?>,
labels: <?php echo json_encode($allLabels); ?>,
datasets: [{
label: 'Logs pro Tag',
data: <?php echo json_encode($data); ?>,
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
fill: true,
tension: 0
}]
label: 'Gesamt',
data: <?php echo json_encode($finalTotalData); ?>,
borderColor: 'rgb(255, 0, 0)',
backgroundColor: 'rgba(0, 0, 0, 0.2)',
fill: false,
tension: 0
},
{
label: 'Node1',
data: <?php echo json_encode($finalNodeData['node1']); ?>,
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
fill: false,
tension: 0
},
{
label: 'Node2',
data: <?php echo json_encode($finalNodeData['node2']); ?>,
borderColor: 'rgba(255, 99, 132, 1)',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
fill: false,
tension: 0
},
{
label: 'Node3',
data: <?php echo json_encode($finalNodeData['node3']); ?>,
borderColor: 'rgba(255, 206, 86, 1)',
backgroundColor: 'rgba(255, 206, 86, 0.2)',
fill: false,
tension: 0
},
{
label: 'Node4',
data: <?php echo json_encode($finalNodeData['node4']); ?>,
borderColor: 'rgba(54, 162, 235, 1)',
backgroundColor: 'rgba(54, 162, 235, 0.2)',
fill: false,
tension: 0
}
]
},
options: {
responsive: true,
@@ -53,7 +125,7 @@ $conn->close();
plugins: {
title: {
display: true,
text: 'Logs pro Tag'
text: 'Logs pro Tag nach Node und Gesamt'
},
legend: {
display: true,
@@ -62,13 +134,13 @@ $conn->close();
zoom: {
pan: {
enabled: true,
mode: 'x',
mode: 'x'
},
zoom: {
wheel: {
enabled: true,
enabled: true
},
mode: 'x',
mode: 'x'
}
}
},
@@ -84,16 +156,11 @@ $conn->close();
}
},
y: {
min: 0,
max: 300,
beginAtZero: true,
title: {
display: true,
text: 'Anzahl Logs'
},
ticks: {
stepSize: 20
},
beginAtZero: true
}
}
}
}