-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
124 lines (116 loc) · 5.5 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>License Usage</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.2/chart.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/combine/npm/[email protected],npm/[email protected]"></script>
</head>
<body>
<h1>License Usage 2</h1>
<h2>License Server 1</h2>
<canvas id="licenseChart1" width="200" height="100"></canvas>
<h2>License Server 2</h2>
<canvas id="licenseChart2" width="200" height="100"></canvas>
<script>
// Fetch historical data
fetch('fetch_data.php')
.then(response => response.json())
.then(data => {
// const features = [
// { name: 'feature1', elementId: 'licenseChart1' },
// { name: 'feature2', elementId: 'licenseChart2' }
// ];
const licenseServers = [
{ name: 'server1', elementId: 'licenseChart1' },
{ name: 'server2', elementId: 'licenseChart2' }
];
licenseServers.forEach(server => {
const serverData = data[server.name];
// const featureData = data[feature.name];
// const featureData = serverData["feature1"];
// data[server.name]のkeyからfeature名を動的に取得
const features = Object.keys(data[server.name]);
// datasetsを生成
const datasets = Object.keys(data[server.name]).flatMap((feature, index) => {
const featureData = data[server.name][feature];
const timeData = featureData.map(entry => new Date(entry.timestamp).toLocaleString());
const usedData = featureData.map(entry => entry.used_licenses);
const totalData = featureData.map(entry => entry.total_licenses);
// total_licensesのデータセット(実線)
const totalDataset = {
label: `${feature} Total Licenses`,
data: timeData.map((time, i) => ({
x: time,
y: totalData[i],
})),
borderColor: `hsla(${index * 60}, 70%, 50%, 1)`, // 実線の色
backgroundColor: 'transparent',
borderWidth: 2,
tension: 0.0, // 折れ線を少し滑らかに
fill: false, // 塗りつぶしなし
};
// used_licensesのデータセット(点線)
const usedDataset = {
label: `${feature} Used Licenses`,
data: timeData.map((time, i) => ({
x: time,
y: usedData[i],
})),
borderColor: `hsla(${index * 60}, 70%, 50%, 0.7)`, // 点線の色(少し透明に)
// backgroundColor: 'transparent',
backgroundColor: `hsla(${index * 60}, 70%, 50%, 0.2)`,
borderWidth: 2,
borderDash: [5, 5], // 点線のスタイル
tension: 0.0, // 折れ線を少し滑らかに
fill: true, // 塗りつぶしなし
};
return [totalDataset, usedDataset];
});
// グラフを描画
const ctx = document.getElementById(server.elementId).getContext('2d');
new Chart(ctx, {
type: 'line', // 折れ線グラフ
data: {
datasets: datasets, // 動的に生成したdatasetsを使用
},
options: {
responsive: true,
scales: {
x: {
type: 'time',
time: {
unit: 'minute', // X軸を時間単位に設定
},
title: {
display: true,
text: 'Time',
}
},
y: {
beginAtZero: true, // Y軸の開始を0に設定
title: {
display: true,
text: 'Licenses',
},
}
},
plugins: {
tooltip: {
mode: 'index',
intersect: false, // 同じ時刻のデータをまとめて表示
},
legend: {
position: 'top', // 凡例を上部に配置
},
},
}
});
});
})
.catch(error => console.error('Error fetching data:', error));
</script>
</body>
</html>