Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,6 @@ handler := monitor.New(mux, monitor.Config{
Description: "Live production service metrics.",
Footer: "Copyright 2026 Example Inc.",
FaviconURL: "/assets/favicon.svg",
ServiceName: "payments-api",
Version: "v1.2.0",
Environment: "production",
DefaultLanguage: "en",
DefaultTheme: "dark",
Background: "solid",
Expand All @@ -274,9 +271,6 @@ Defaults:
| `Description` | `Live process, runtime, system, and HTTP metrics for this Go service.` | Short visible description below the header. |
| `Footer` | `Powered by github.com/gofurry/monitor - MIT License.` | Footer text for copyright, ownership, or license notes. |
| `FaviconURL` | built-in favicon | Overrides the dashboard favicon with a root-relative path or absolute HTTP(S) URL. Empty or invalid values use the built-in favicon. |
| `ServiceName` | executable basename | Service name shown in the UI and snapshot. |
| `Version` | Go module build version | Running service version; a configured value takes precedence. |
| `Environment` | empty | Deployment environment such as `production`. |
| `DefaultLanguage` | `en` | Initial UI language when no browser preference is saved. Supported values: `en`, `zh-CN`. |
| `DefaultTheme` | `dark` | Initial UI theme when no browser preference is saved. Supported values: `light`, `dark`. |
| `Background` | `solid` | HTML page background. Supported values: `solid`, `grid`. |
Expand Down Expand Up @@ -378,15 +372,6 @@ Use a dedicated observability stack such as Prometheus, Grafana, tracing, and ce
"duration_ns": 1850000,
"partial": false
},
"service": {
"name": "payments-api",
"version": "v1.2.0",
"environment": "production",
"go_version": "go1.24.6",
"module": "example.com/payments",
"revision": "abc123",
"vcs_modified": false
},
"pid": {
"cpu_percent": 2.4,
"rss_bytes": 48140288,
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This is a small open-source project without a formal security response SLA. Main

## Dashboard Exposure

The monitor endpoint exposes service identity, build metadata, process, runtime, host, network, container, and HTTP traffic statistics. Treat it as an operational endpoint rather than a public application page.
The monitor endpoint exposes process, runtime, host, network, container, and HTTP traffic statistics. Treat it as an operational endpoint rather than a public application page.

- Use `Config.Authorize` or an upstream authenticated proxy in production.
- Restrict the endpoint at the network layer where practical and serve it only over TLS.
Expand All @@ -42,4 +42,4 @@ The monitor endpoint exposes service identity, build metadata, process, runtime,

`Authorize` runs only for the configured monitor path and before HTTP method handling. A denied request receives `401 Unauthorized` for HTML, JSON, `HEAD`, and unsupported methods. The package does not implement TLS, token storage, rate limiting, or role management.

JSON build metadata is limited to the Go version, module, module version, VCS revision, and modified state. It intentionally excludes the executable path, working directory, environment variables, and remote repository URL. Collection failures expose stable identifiers instead of underlying operating-system error text.
The JSON snapshot intentionally excludes executable paths, working directories, environment variables, build metadata, and remote repository URLs. Collection failures expose stable identifiers instead of underlying operating-system error text.
52 changes: 0 additions & 52 deletions buildinfo.go

This file was deleted.

1 change: 0 additions & 1 deletion collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func (m *Monitor) collectOnce() {

stats := Stats{
SchemaVersion: StatsSchemaVersion,
Service: m.service,
PID: pidStats,
Runtime: m.collectRuntime(),
OS: osStats,
Expand Down
10 changes: 0 additions & 10 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ type Config struct {
// the built-in favicon.
FaviconURL string

// ServiceName identifies the service in the dashboard and JSON snapshot.
// Empty uses the executable name.
ServiceName string

// Version identifies the running service version. Empty uses Go build info.
Version string

// Environment describes the deployment environment, such as "production".
Environment string

// DefaultLanguage controls the initial HTML UI language when the browser has
// no saved monitor language preference. Supported values are "en" and
// "zh-CN". Empty or unsupported values use "en".
Expand Down
142 changes: 19 additions & 123 deletions docs/monitor-v1.2-implementation-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@
1. JSON Snapshot 缺少版本与采集状态信息。
2. HTTP 指标缺少 RPS、错误率、P50/P95/P99 等生产环境常用指标。
3. 生命周期最大延迟 `max_ns` 长时间运行后参考价值不足。
4. Monitor 页面缺少服务版本、构建信息、运行环境等上下文。
5. 容器环境下 Host 指标可能不能真实反映进程资源限制。
6. Monitor 页面暴露生产运行信息,但目前缺少内建访问控制挂钩。
7. `Refresh` 可被错误配置为极小值,造成过度采集。
8. 手工 Request 生命周期 API 存在 in-flight 下溢风险。
9. CI 仍可补充 race、Windows 与多 Go 版本验证。
10. JSON / UI 对“指标值为 0”和“采集失败”缺少区分。
4. 容器环境下 Host 指标可能不能真实反映进程资源限制。
5. Monitor 页面暴露生产运行信息,但目前缺少内建访问控制挂钩。
6. `Refresh` 可被错误配置为极小值,造成过度采集。
7. 手工 Request 生命周期 API 存在 in-flight 下溢风险。
8. CI 仍可补充 race、Windows 与多 Go 版本验证。
9. JSON / UI 对“指标值为 0”和“采集失败”缺少区分。

---

Expand Down Expand Up @@ -156,11 +155,11 @@ type Stats struct {
CollectedAt time.Time `json:"collected_at"`
Collection CollectionStats `json:"collection"`

Service ServiceStats `json:"service"`
PID PIDStats `json:"pid"`
Runtime RuntimeStats `json:"runtime"`
OS OSStats `json:"os"`
HTTP HTTPStats `json:"http"`
PID PIDStats `json:"pid"`
Runtime RuntimeStats `json:"runtime"`
OS OSStats `json:"os"`
Container ContainerStats `json:"container"`
HTTP HTTPStats `json:"http"`
}
```

Expand Down Expand Up @@ -587,100 +586,11 @@ MaxNS = 生命周期最大值

---

# 9. Service / Build Info
# 9. Header / Identity Scope

## 9.1 目标
v1.2 不引入服务身份、部署环境或构建信息配置。Monitor 无法为不同项目统一定义这些字段的业务语义,而且这些信息会扩大公共 API 与数据暴露面。

让用户打开 `/monitor` 后第一眼知道:

```text
这是哪个服务
跑的是哪个版本
是什么环境
使用什么 Go 版本
编译版本是什么
```

---

## 9.2 配置

新增:

```go
type Config struct {
// existing...

ServiceName string
Version string
Environment string
}
```

推荐默认:

```text
ServiceName = executable name
Version = build info module version / "(devel)"
Environment = ""
```

---

## 9.3 自动采集

可以通过:

```go
runtime.Version()
debug.ReadBuildInfo()
os.Executable()
```

获得:

```text
Go Version
Module
Module Version
VCS Revision
VCS Time
VCS Modified
Executable
```

---

## 9.4 数据结构

```go
type ServiceStats struct {
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Environment string `json:"environment,omitempty"`

GoVersion string `json:"go_version"`
Module string `json:"module,omitempty"`
Revision string `json:"revision,omitempty"`
VCSModified bool `json:"vcs_modified,omitempty"`
}
```

---

## 9.5 隐私原则

默认不要暴露:

- 完整 executable filesystem path
- GOPATH
- 工作目录
- Build Host
- 用户名
- 环境变量
- Git Remote URL

UI/JSON 仅保留必要构建标识。
界面左上方只展示用户配置的 `Title`。JSON 不包含 service、environment、Go build info、可执行文件路径、工作目录或环境变量。

---

Expand Down Expand Up @@ -1313,9 +1223,6 @@ IgnoreRequest
新增:

```text
ServiceName
Version
Environment
Authorize
```

Expand Down Expand Up @@ -1674,9 +1581,6 @@ runtime usage
resource usage
disk mount information
request traffic
service version
revision
environment name
```

推荐用户:
Expand Down Expand Up @@ -1746,18 +1650,13 @@ Snapshot 模型稳定

---

## Phase 3:Service Info
## Phase 3:Header Scope

任务:

- [ ] Config.ServiceName
- [ ] Config.Version
- [ ] Config.Environment
- [ ] `runtime.Version`
- [ ] `debug.ReadBuildInfo`
- [ ] VCS revision
- [ ] UI header/service section
- [ ] README example
- [ ] 左上方只展示 `Title`
- [ ] 不增加 service identity 配置
- [ ] 不采集或暴露 Go build info

---

Expand Down Expand Up @@ -1888,7 +1787,6 @@ v1.2 improves production visibility while keeping monitor lightweight and depend
- Recent HTTP 4xx / 5xx / error rates.
- Approximate P50 / P95 / P99 request latency.
- Recent maximum request latency.
- Service and Go build information.
- Optional request authorization hook for the monitor endpoint.
- Linux cgroup v2 container memory and CPU limit metrics.
- Network receive / transmit metrics.
Expand All @@ -1897,7 +1795,7 @@ v1.2 improves production visibility while keeping monitor lightweight and depend
### Improved

- Monitor UI now distinguishes unavailable metrics from real zero values.
- Added production-oriented service and HTTP summary information.
- Added production-oriented HTTP summary information.
- Refresh intervals are clamped to a safe minimum.
- Improved CI coverage with race and cross-platform testing.

Expand Down Expand Up @@ -2029,8 +1927,6 @@ optional collectors
v1.2 最重要的成果不是“增加多少个指标”,而是让用户打开 `/monitor` 后,可以在几秒钟内回答:

```text
这个服务是谁?
运行的是哪个版本?
服务活着多久了?
当前请求压力多大?
错误率有没有异常?
Expand Down
2 changes: 1 addition & 1 deletion docs/releases/v1.2.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# v1.2.0 Release Notes

- Add snapshot metadata, service identity, partial collection status, and stable collector error identifiers.
- Add snapshot metadata, partial collection status, and stable collector error identifiers.
- Add RPS, recent HTTP error rates, fixed-bucket latency percentiles, and `BeginRequest`.
- Add aggregate network I/O and Linux cgroup v2 container limits.
- Add optional monitor-path authorization and an expanded live dashboard.
Expand Down
15 changes: 0 additions & 15 deletions docs/zh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,6 @@ handler := monitor.New(mux, monitor.Config{
Description: "Live production service metrics.",
Footer: "Copyright 2026 Example Inc.",
FaviconURL: "/assets/favicon.svg",
ServiceName: "payments-api",
Version: "v1.2.0",
Environment: "production",
DefaultLanguage: "en",
DefaultTheme: "dark",
Background: "solid",
Expand All @@ -271,9 +268,6 @@ handler := monitor.New(mux, monitor.Config{
| `Description` | `Live process, runtime, system, and HTTP metrics for this Go service.` | 页头下方的简短说明。 |
| `Footer` | `Powered by github.com/gofurry/monitor - MIT License.` | 页脚文本,可用于版权、归属或许可证说明。 |
| `FaviconURL` | 内嵌 favicon | 用站内相对 URL 或 HTTP(S) 绝对 URL 覆盖仪表盘图标。为空或无效时使用内嵌图标。 |
| `ServiceName` | 可执行文件名 | UI 和快照中显示的服务名。 |
| `Version` | Go module 构建版本 | 当前服务版本;显式配置优先。 |
| `Environment` | 空 | 部署环境,例如 `production`。 |
| `DefaultLanguage` | `en` | 浏览器没有保存偏好时的初始 UI 语言。支持值:`en`、`zh-CN`。 |
| `DefaultTheme` | `dark` | 浏览器没有保存偏好时的初始 UI 主题。支持值:`light`、`dark`。 |
| `Background` | `solid` | HTML 页面背景。支持值:`solid`、`grid`。 |
Expand Down Expand Up @@ -367,15 +361,6 @@ TLS 终止和网络层访问限制应在本包之外完成,监控 token 不要
"duration_ns": 1850000,
"partial": false
},
"service": {
"name": "payments-api",
"version": "v1.2.0",
"environment": "production",
"go_version": "go1.24.6",
"module": "example.com/payments",
"revision": "abc123",
"vcs_modified": false
},
"pid": {
"cpu_percent": 2.4,
"rss_bytes": 48140288,
Expand Down
4 changes: 2 additions & 2 deletions docs/zh/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

## 仪表盘暴露风险

监控端点会暴露服务标识、构建元数据、进程、runtime、主机、网络、容器和 HTTP 流量统计。请将它视为运维端点,而不是公开应用页面。
监控端点会暴露进程、runtime、主机、网络、容器和 HTTP 流量统计。请将它视为运维端点,而不是公开应用页面。

- 生产环境使用 `Config.Authorize` 或上游认证代理。
- 在可行时通过网络层限制访问,并且只通过 TLS 提供端点。
Expand All @@ -42,4 +42,4 @@

`Authorize` 只作用于配置的监控路径,并在 HTTP 方法处理之前执行。被拒绝的 HTML、JSON、`HEAD` 和不支持的方法请求都会返回 `401 Unauthorized`。本包不提供 TLS、token 存储、限流或角色管理。

JSON 构建元数据仅包含 Go 版本、module、module version、VCS revision 和 modified 状态,刻意排除可执行文件完整路径、工作目录、环境变量和远程仓库 URL。采集失败只暴露稳定标识,不返回底层操作系统错误文本。
JSON 快照刻意排除可执行文件完整路径、工作目录、环境变量、构建元数据和远程仓库 URL。采集失败只暴露稳定标识,不返回底层操作系统错误文本。
Loading