服务 当前状态 开机自启 结论
Apache2 active / running enabled 正常
PHP 8.2 Apache 模块加载 随 Apache 正常
MariaDB active / running enabled 正常
电影监控 active / running enabled 正常
健康检查 Timer active enabled 正常
Python 主程序 /var/lib/wateryaml-movie-monitor/monitor.py
systemd 服务配置 /etc/systemd/system/wateryaml-movie-monitor.service
定时器配置 /etc/systemd/system/wateryaml-healthcheck.timer
检查服务配置 /etc/systemd/system/wateryaml-healthcheck.service
故障处理服务配置 /etc/systemd/system/wateryaml-healthcheck-failure.service
本系统采用:HTML · CSS · JavaScript · HTML5 Video
MKV 播放逻辑会通过 Movi-Player 获取字幕轨道
外挂srt字幕:MP4 分支则使用浏览器原生字幕轨道,mkv 转成字幕 Cue 后添加。
外挂ASS / SSA使用: JASSUB ,不支持的字体使用Microsoft YaHei代替
手动扫描:
sudo flock -n /run/lock/wateryaml-movie-db-writer.lock \
php /var/www/html/movies/app/scan.php
更新音乐库
python3 /var/www/html/music/update_music_library.py
封闭格式为Matroska / WebM:使用Movi-Player 0.4.1
MP4 等其他格式:使用原生 HTML5 Video
“外挂字幕关联数”统计的是视频版本与字幕文件之间的关联次数;同一个字幕供两个同名视频版本使用时,会计为两次。
stream.php 提供视频文件,不负责字幕提取或转换。不能让 GCP 服务器的出站流量经过 CDN,但不禁止用户浏览器直接访问 CDN
winscp原子改名设置:Use POSIX rename
查看每个月的出站流量
clear
python3 - <<'PY'
import json
import datetime
import collections
FILE = "/var/lib/wateryaml-traffic/traffic.json"
def fmt(n):
n = int(n or 0)
return f"{n / 1024**3:.3f} GiB ({n / 1000**3:.3f} GB)"
def bytes_value(n):
return f"{int(n or 0):,} Bytes"
def clean_time(value):
return str(value).replace("+00:00", "").replace("Z", "")
def parse_time(value):
try:
dt = datetime.datetime.fromisoformat(value)
if dt.tzinfo is None:
dt = dt.replace(tzinfo=datetime.timezone.utc)
return dt
except (ValueError, TypeError):
return None
def next_month(month):
year, mon = map(int, month.split("-"))
if mon == 12:
return f"{year + 1}-01"
return f"{year}-{mon + 1:02d}"
with open(FILE, encoding="utf-8") as f:
data = json.load(f)
records = data.get("records", [])
state = data.get("state", {})
# 整理有效记录
valid_records = []
for r in records:
dt = parse_time(r.get("time"))
if dt:
valid_records.append((dt, r))
valid_records.sort(key=lambda x: x[0])
record_count = len(valid_records)
first_time = (
clean_time(valid_records[0][1]["time"])
if valid_records else "暂无记录"
)
# 按 UTC 月份分组
monthly_records = collections.defaultdict(list)
for dt, r in valid_records:
monthly_records[dt.strftime("%Y-%m")].append((dt, r))
# 使用实际 UTC 当前月份
current_month = datetime.datetime.now(
datetime.timezone.utc
).strftime("%Y-%m")
updated_at = clean_time(data.get("updated_at", "未知"))
print("=" * 85)
print(" WATERYAML 服务器出站流量报告")
print("=" * 85)
print(f"监控网卡: {data.get('interface', '未知')}")
print(f"统计更新时间: {updated_at}")
print("-" * 85)
print("[记录情况]")
print(f"最早保留记录时间: {first_time}")
print(f"已记录次数: {record_count} 次")
print("记录保留策略: 最近60条")
print("-" * 85)
print("[每月流量明细]")
if monthly_records:
for month in sorted(monthly_records):
items = monthly_records[month]
following_month = next_month(month)
# 本月1日首次记录作为月初基准
baselines = [
(dt, r) for dt, r in items
if dt.day == 1
]
baseline = baselines[0] if baselines else None
# 次月1日首次记录作为上个月月末边界
next_items = monthly_records.get(following_month, [])
next_baselines = [
(dt, r) for dt, r in next_items
if dt.day == 1
]
end_boundary = (
next_baselines[0] if next_baselines else None
)
# 当前月份暂时使用最新记录作为终点
if month == current_month and not end_boundary:
end_boundary = items[-1]
print(f"\n{month}")
# 显示月初基准
if baseline:
base_dt, base_record = baseline
base_raw = base_record.get("raw_bytes", 0)
print(
f" 月初基准 | {clean_time(base_record['time'])}"
f" | 当时网卡流量:{fmt(base_raw)}"
f" | {bytes_value(base_raw)}"
)
else:
print(" 月初基准:缺失,无法完整统计")
# 确定本月明细范围
if baseline:
base_dt = baseline[0]
display_items = [
(dt, r) for dt, r in valid_records
if dt > base_dt
and (
end_boundary is None
or dt <= end_boundary[0]
)
]
else:
display_items = list(items)
# 没有月初基准时,也展示次月1日边界
if (
end_boundary
and end_boundary[0].strftime("%Y-%m") != month
):
display_items.append(end_boundary)
# 逐条展示采样记录
for dt, r in display_items:
timestamp = clean_time(r["time"])
delta = r.get("delta_bytes")
raw = r.get("raw_bytes", 0)
status = r.get("status", "unknown")
is_next_month_boundary = (
dt.day == 1
and dt.strftime("%Y-%m") == following_month
)
if is_next_month_boundary:
if status == "counter_reset":
print(
f" {timestamp} | 月末边界(次月1日首次记录)"
f" | 计数器重置"
f" | 当前网卡流量:{fmt(raw)}"
f" | {bytes_value(raw)}"
)
elif delta is not None:
print(
f" {timestamp} | 月末边界(次月1日首次记录)"
f" | 本次流量:{fmt(delta)}"
f" | {bytes_value(delta)}"
)
else:
print(
f" {timestamp} | 月末边界(次月1日首次记录)"
f" | 流量无法确认"
)
elif status == "baseline":
print(
f" {timestamp} | 基准记录"
f" | 当时网卡流量:{fmt(raw)}"
f" | {bytes_value(raw)}"
)
elif status == "counter_reset":
print(
f" {timestamp} | 计数器重置"
f" | 当前网卡流量:{fmt(raw)}"
f" | {bytes_value(raw)}"
)
elif delta is not None:
print(
f" {timestamp} | 本次流量:{fmt(delta)}"
f" | {bytes_value(delta)}"
)
else:
print(
f" {timestamp} | 流量未知"
f" | 当前网卡流量:{fmt(raw)}"
f" | {bytes_value(raw)}"
)
# 月度统计
if month == current_month:
# 当前月份临时统计
if baseline:
start_dt = baseline[0]
start_note = "以本月1日基准为起点"
else:
start_dt = items[0][0]
start_note = "缺少本月1日基准,从首条保留记录之后统计"
interval = [
(dt, r) for dt, r in items
if dt > start_dt
]
known_total = sum(
int(r["delta_bytes"])
for dt, r in interval
if r.get("delta_bytes") is not None
and r.get("status") != "counter_reset"
)
unknown_count = sum(
1 for dt, r in interval
if r.get("delta_bytes") is None
or r.get("status") == "counter_reset"
)
print(
f" 本月当前使用流量(临时):"
f"{fmt(known_total)} | {bytes_value(known_total)}"
)
print(f" 统计依据:{start_note}")
if unknown_count:
print(
f" 注意:有 {unknown_count} 条记录"
"存在重置或未知增量,未计入已确认流量"
)
print(
" 状态:当前月份,等待次月1日首次采样"
"确定最终边界"
)
else:
# 历史月份必须具备月初和月末边界
complete = (
baseline is not None
and end_boundary is not None
)
if complete:
base_dt = baseline[0]
end_dt = end_boundary[0]
interval = [
(dt, r) for dt, r in valid_records
if base_dt < dt <= end_dt
]
uncertain = any(
r.get("delta_bytes") is None
or r.get("status") == "counter_reset"
for dt, r in interval
)
if uncertain:
print(
" 月度流量:无法完整确认"
"(存在计数器重置或未知增量)"
)
else:
total = sum(
int(r["delta_bytes"])
for dt, r in interval
)
print(
f" 月度流量:{fmt(total)}"
f" | {bytes_value(total)}"
)
else:
print(
" 月度流量:边界记录不足,"
"暂无法完整统计"
)
else:
print("暂无记录")
# 如果当前月份没有任何保留记录
if current_month not in monthly_records:
print(f"\n{current_month}")
print(" 本月当前使用流量:暂无采样记录")
print(" 状态:等待本月首次采样")
print("-" * 85)
# 累计情况
print("[累计情况]")
cumulative = state.get("cumulative_bytes", 0)
last_raw = state.get("last_raw_bytes", 0)
print(f"累计量: {fmt(cumulative)}")
print(f"累计量字节数: {bytes_value(cumulative)}")
print(f"网卡计数器重置次数: {state.get('reset_count', 0)}")
print(f"最近原始网卡计数: {fmt(last_raw)}")
print(f"最近网卡字节数: {bytes_value(last_raw)}")
print("-" * 85)
print("说明:")
print("1. 数据来自本机网卡 tx_bytes,每日采样一次。")
print("2. 月度记录按 UTC 月份归类。")
print("3. JSON 严格保留最近60条记录。")
print("4. 每月1日首次采样作为月初基准。")
print("5. 次月1日首次采样作为上个月月末边界。")
print("6. 当前月份暂以最新采样记录作为临时终点。")
print("7. 当前月份显示能够确认的已使用流量,缺失部分不虚构。")
print("8. 缺少历史边界或发生计数器重置时,不提供虚假的完整月度统计。")
print("9. 累计量跨计数器重置周期累计可确认流量;重置期间无法恢复的流量不计入。")
print("10. 网卡统计值不等同于 GCP 账单精确计费流量。")
print("=" * 85)
PY
服务器重启后,启动过程是:
wateryaml-traffic.timer 随系统启动自动激活。
Timer 按照原定计划,每天 00:05 UTC 触发一次采样。
Timer 自动启动 wateryaml-traffic.service。
Python 脚本读取 ens4 网卡计数器,更新 JSON 数据。
不需要手动运行脚本,也不需要 SSH 登录服务器。
手动立即记录一次
sudo systemctl start wateryaml-traffic.service
检查定时任务
systemctl list-timers wateryaml-traffic.timer
sudo systemctl start qbittorrent.service
sudo systemctl stop qbittorrent.service
sudo systemctl status qbittorrent.service --no-pager
nano /etc/systemd/system/qbittorrent.service
btstatus
gcloud compute ssh wateryaml --zone=us-west1-b --ssh-flag="-L 8080:localhost:8080"
gcloud compute ssh wateryaml --zone=us-west1-b -- -L 8080:localhost:8080
http://localhost:8080
admin
adminadmin
sudo apt update && sudo apt install -y qbittorrent-nox
dpkg -L qbittorrent-nox
clear
cat > /var/www/html/Tp/update-2026-thumbnails.sh <<'SCRIPT'
#!/bin/bash
set -e
cd /var/www/html/Tp || {
echo "错误:相册目录不存在"
exit 1
}
mkdir -p 2026thumbnails
php -d memory_limit=256M <<'PHP'
<?php
$sourceDir = '/var/www/html/Tp/2026';
$thumbDir = '/var/www/html/Tp/2026thumbnails';
if (!is_dir($sourceDir) || !is_dir($thumbDir)) {
exit("错误:原图目录或缩略图目录不存在\n");
}
if (!function_exists('imagewebp')) {
exit("错误:PHP GD WebP 功能不可用\n");
}
$files = [];
$sourceNames = [];
foreach (scandir($sourceDir) as $name) {
if (!preg_match('/\.(jpg|jpeg|png|gif|webp)$/i', $name)) {
continue;
}
$input = $sourceDir . '/' . $name;
if (!is_file($input)) {
continue;
}
$files[] = $name;
$sourceNames[$name] = true;
}
sort($files, SORT_STRING);
$created = 0;
$updated = 0;
$skipped = 0;
$failed = 0;
$removed = 0;
foreach ($files as $name) {
$input = $sourceDir . '/' . $name;
$output = $thumbDir . '/' . $name . '.webp';
$originalTime = @filemtime($input);
$outputTime = is_file($output) ? @filemtime($output) : false;
$outputSize = is_file($output) ? @filesize($output) : 0;
// 时间一致且缩略图有效,直接跳过
if (
$outputSize > 0 &&
$originalTime !== false &&
$outputTime === $originalTime
) {
$skipped++;
continue;
}
$data = @file_get_contents($input);
$image = $data === false ? false : @imagecreatefromstring($data);
unset($data);
if (!$image) {
echo "[失败] $name:无法读取原图\n";
$failed++;
continue;
}
$w = imagesx($image);
$h = imagesy($image);
if ($w <= 0 || $h <= 0) {
imagedestroy($image);
$failed++;
echo "[失败] $name:图片尺寸无效\n";
continue;
}
$scale = min(1, 480 / max($w, $h));
$nw = max(1, (int)round($w * $scale));
$nh = max(1, (int)round($h * $scale));
$thumb = imagecreatetruecolor($nw, $nh);
imagealphablending($thumb, false);
imagesavealpha($thumb, true);
$transparent = imagecolorallocatealpha($thumb, 0, 0, 0, 127);
imagefill($thumb, 0, 0, $transparent);
imagecopyresampled(
$thumb, $image,
0, 0, 0, 0,
$nw, $nh, $w, $h
);
// 先生成临时文件,成功后再替换旧缩略图
$tempOutput = $output . '.' . getmypid() . '.tmp';
$ok = @imagewebp($thumb, $tempOutput, 75);
imagedestroy($thumb);
imagedestroy($image);
unset($thumb, $image);
gc_collect_cycles();
if (
$ok &&
is_file($tempOutput) &&
filesize($tempOutput) > 0 &&
$originalTime !== false
) {
@touch($tempOutput, $originalTime);
if (@rename($tempOutput, $output)) {
if ($outputSize > 0) {
$updated++;
echo "[更新] $name\n";
} else {
$created++;
echo "[新增] $name\n";
}
} else {
@unlink($tempOutput);
$failed++;
echo "[失败] $name:替换缩略图失败\n";
}
} else {
@unlink($tempOutput);
$failed++;
echo "[失败] $name:WebP生成失败\n";
}
}
// 清理已经没有对应原图的缩略图
foreach (scandir($thumbDir) as $thumbName) {
if (!preg_match('/\.(jpg|jpeg|png|gif|webp)\.webp$/i', $thumbName)) {
continue;
}
$originalName = substr($thumbName, 0, -5);
if (!isset($sourceNames[$originalName])) {
$staleFile = $thumbDir . '/' . $thumbName;
if (is_file($staleFile) && @unlink($staleFile)) {
$removed++;
echo "[清理] $thumbName\n";
}
}
}
// 统计缩略图数量
$total = 0;
foreach (scandir($thumbDir) as $name) {
if (
preg_match('/\.(jpg|jpeg|png|gif|webp)\.webp$/i', $name) &&
is_file($thumbDir . '/' . $name)
) {
$total++;
}
}
echo "\n========== 照片维护完成 ==========\n";
echo "原图数量:" . count($files) . " 张\n";
echo "新生成:$created 张\n";
echo "重新生成:$updated 张\n";
echo "跳过:$skipped 张\n";
echo "清理旧缩略图:$removed 张\n";
echo "失败:$failed 张\n";
echo "缩略图总数:$total 张\n";
if ($failed > 0) {
exit(1);
}
?>
PHP
SCRIPT
chmod 700 /var/www/html/Tp/update-2026-thumbnails.sh
echo "========== 执行照片维护 =========="
/var/www/html/Tp/update-2026-thumbnails.sh
echo
echo "========== 脚本位置 =========="
ls -lh /var/www/html/Tp/update-2026-thumbnails.sh
右键一张图片,点击save image as,下载下来的图片“修改日期”会变成你下载时的当前时间,而不是保留文件在服务器上的原始时间
PHP GD 图片读取、缩放和 WebP 转换
JSON 保存照片尺寸缓存
Bash 自动化照片维护脚本
clear
bash /var/www/html/Tp/update-2026-thumbnails.sh
clear
mkdir -p /var/cache/wateryaml
chown www-data:www-data /var/cache/wateryaml
chmod 750 /var/cache/wateryaml