Skip to content

Commit a3152b8

Browse files
v2.8: 70-day cap, version badge, dates on the time axis
- max window is now 70 days (7d/30d/70d); retention lowered 300 -> 70 to match, so no data is kept that cannot be viewed - /api/version endpoint; the share panel header shows the running version - x-axis labels carry the date when the window spans more than a day: HH:MM under 6h, MM-DD + HH:MM between 6h and 24h, MM-DD beyond that; hover shows full date and time - no sampling introduced, per your call: every stored sample is still returned as-is Verified: /api/version ok, over-limit minutes falls back to 6h, axis formatter returns 09:29 for a 6h window and 07-23 for 70d.
1 parent 213b341 commit a3152b8

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func defaultConfig() *Config {
2828
DataDir: "./data",
2929
TargetsDir: "./targets",
3030
Probe: ProbeCfg{IntervalSec: 60, Packets: 20, GapMs: 50, TimeoutMs: 1000},
31-
RetentionDays: 300,
31+
RetentionDays: 70,
3232
}
3333
}
3434

static/index.html

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@
113113
<button data-m="1440">24h</button>
114114
<button data-m="10080">7d</button>
115115
<button data-m="43200">30d</button>
116-
<button data-m="129600">90d</button>
117-
<button data-m="259200">180d</button>
116+
<button data-m="100800">70d</button>
118117
</div>
119118
<div class="rng custom">
120119
<input type="datetime-local" id="customFrom" step="60">
@@ -136,7 +135,7 @@
136135
<div class="promo-b">This slot is for one VPS / IDC / network sponsor. Your GIF here — reach out on GitHub.</div>
137136
</a>
138137
<div class="promo share">
139-
<div class="promo-h">LIKE PINGPING?</div>
138+
<div class="promo-h">LIKE PINGPING? <span id="ver" style="color:var(--phos)"></span></div>
140139
<div class="promo-b">
141140
<a href="https://github.com/githubflyideas/pingping" target="_blank" rel="noopener">★ Star on GitHub</a>
142141
<span class="share-links" id="shareLinks"></span>
@@ -257,7 +256,17 @@
257256
animation: false,
258257
grid: { left: 52, right: 46, top: 18, bottom: 42 },
259258
xAxis: { type: 'time', axisLine: { lineStyle: { color: cssv('--grid-axis') } },
260-
axisLabel: { color: cssv('--dim'), fontSize: 10 }, splitLine: { lineStyle: { color: cssv('--grid-split') } },
259+
axisLabel: { color: cssv('--dim'), fontSize: 10,
260+
formatter: v => {
261+
const d = new Date(v);
262+
const p = n => String(n).padStart(2, '0');
263+
// 长窗口显示日期,短窗口显示时刻;跨天时两行都给
264+
const span = sel ? (sel.to - sel.from) : minutes * 60;
265+
if (span > 86400) return `${p(d.getMonth()+1)}-${p(d.getDate())}`;
266+
if (span > 21600) return `${p(d.getMonth()+1)}-${p(d.getDate())}\n${p(d.getHours())}:${p(d.getMinutes())}`;
267+
return `${p(d.getHours())}:${p(d.getMinutes())}`;
268+
} },
269+
splitLine: { lineStyle: { color: cssv('--grid-split') } },
261270
axisPointer: { show: true, snap: false,
262271
lineStyle: { color: cssv('--dim'), opacity: .45 },
263272
label: { show: true, backgroundColor: cssv('--panel'), color: cssv('--ink'),
@@ -275,7 +284,7 @@
275284
const ts = params[0] && params[0].axisValue;
276285
const i = roundInfo[ts];
277286
if (!i) return '';
278-
let html = `<b>${new Date(+ts).toLocaleTimeString()}</b>`;
287+
let html = `<b>${new Date(+ts).toLocaleString()}</b>`;
279288
html += `<br>rtt min/avg/max/mdev = ${i.lo.toFixed(3)}/${i.avg.toFixed(3)}/${i.hi.toFixed(3)}/${i.mdev.toFixed(3)} ms`;
280289
html += `<br>median <b>${i.med.toFixed(1)} ms</b> · ${i.n} samples`;
281290
html += `<br><span style="color:${i.lp > 0 ? cssv('--alert') : cssv('--dim')}">loss <b>${i.lp.toFixed(0)}%</b> (${i.lost}/${i.s})</span>`;
@@ -333,6 +342,11 @@
333342
});
334343

335344
// 分享的是公开项目主页,不是本地私有面板
345+
fetch('/api/version').then(r => r.json()).then(d => {
346+
const el = document.getElementById('ver');
347+
if (el && d.version) el.textContent = 'v' + d.version.replace(/^v/, '');
348+
}).catch(() => {});
349+
336350
(function buildShare() {
337351
const url = 'https://github.com/githubflyideas/pingping';
338352
const text = 'pingping — a single-binary link quality oscilloscope. One binary. One graph. Zero guesswork.';

web.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ func serveWeb(cfg *Config, store *Store, users map[string]string) error {
115115
writeJSON(w, map[string]bool{"ok": true})
116116
})
117117

118+
mux.HandleFunc("/api/version", func(w http.ResponseWriter, r *http.Request) {
119+
writeJSON(w, map[string]string{"version": version})
120+
})
121+
118122
mux.HandleFunc("/api/targets", guard(func(w http.ResponseWriter, r *http.Request) {
119123
now := time.Now()
120124
type item struct {
@@ -160,7 +164,7 @@ func serveWeb(cfg *Config, store *Store, users map[string]string) error {
160164
to, _ := strconv.ParseInt(q.Get("to"), 10, 64)
161165
if from == 0 || to == 0 {
162166
minutes, _ := strconv.Atoi(q.Get("minutes"))
163-
if minutes <= 0 || minutes > 259200 { // up to 180 days
167+
if minutes <= 0 || minutes > 100800 { // up to 70 days
164168
minutes = 360
165169
}
166170
to = time.Now().Unix()

0 commit comments

Comments
 (0)