Beispiel
github.com/prometheus/procfs v0.22.0: FS.NetDev
Verifiziertes Beispiel für golang github.com/prometheus/procfs v0.22.0: FS.NetDev. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und bestand.
sha256:9a51f9235b6d8679e504adea9ff04c226c2b981eece977a4f202971bd62a2989
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
linux 24 · ubuntu · glibc 2.39 x64 go
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-05 |
Fall
HOW- Ziel
- verify procfs.FS.NetDev in pkg:golang/github.com/prometheus/procfs@v0.22.0
- Symbole
-
- procfs.FS.NetDev
- Erstellt
- 2026-09-05T07:42:18Z
Contract
- procfs.NewFS initializes an FS instance for a valid directory
- procfs.FS.NetDev returns an error when net/dev does not exist
- procfs.FS.NetDev parses /proc/net/dev and returns device statistics by interface name
- procfs.NetDev.Total calculates cumulative network statistics across all interfaces
Dateien
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Quelltext
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify procfs.FS.NetDev in pkg:golang/github.com/prometheus/procfs@v0.22.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/prometheus/procfs@v0.22.0
Demonstrate these symbols/APIs:
- procfs.FS.NetDev
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:1c5583f7b90088eaa538b3f056cc3b32c76d9157091c5019fa030854aed6df21","contract":["procfs.NewFS initializes an FS instance for a valid directory","procfs.FS.NetDev returns an error when net/dev does not exist","procfs.FS.NetDev parses /proc/net/dev and returns device statistics by interface name","procfs.NetDev.Total calculates cumulative network statistics across all interfaces"],"goal":"verify procfs.FS.NetDev in pkg:golang/github.com/prometheus/procfs@v0.22.0","kind":"HOW","packages":["pkg:golang/github.com/prometheus/procfs@v0.22.0"],"schemaVersion":1,"symbols":["procfs.FS.NetDev"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/prometheus/procfs@v0.22.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/prometheus/procfs@v0.22.0","symbols":["procfs.FS.NetDev"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.25.0
require github.com/prometheus/procfs v0.22.0
require golang.org/x/sys v0.47.0 // indirect
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/prometheus/procfs v0.22.0 h1:6q9+/JL9IKAPbCmBrv9n5O5Ty3NKnciV5X7YGw0oics=
github.com/prometheus/procfs v0.22.0/go.mod h1:CvmFr/GVhIjIvWJZW3tgkODBQMRIf0EyWMQLHCHab58=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
package main
import (
"fmt"
"os"
"github.com/prometheus/procfs"
)
func main() {
fs, err := procfs.NewFS(procfs.DefaultMountPoint)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open procfs: %v\n", err)
os.Exit(1)
}
netDev, err := fs.NetDev()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to read net/dev: %v\n", err)
os.Exit(1)
}
for iface, stats := range netDev {
fmt.Printf("%s: rx_bytes=%d, tx_bytes=%d\n", iface, stats.RxBytes, stats.TxBytes)
}
total := netDev.Total()
fmt.Printf("Total: rx_bytes=%d, tx_bytes=%d\n", total.RxBytes, total.TxBytes)
}
{
"schemaVersion": 1,
"goal": "verify procfs.FS.NetDev in pkg:golang/github.com/prometheus/procfs@v0.22.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/prometheus/procfs@v0.22.0"
],
"symbols": [
"procfs.FS.NetDev"
]
}
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/prometheus/procfs"
)
func main() {
// 1. procfs.NewFS initializes an FS instance for a valid directory
mockDir, err := os.MkdirTemp("", "mock-procfs-*")
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create mock directory: %v\n", err)
os.Exit(1)
}
defer os.RemoveAll(mockDir)
fs, err := procfs.NewFS(mockDir)
if err != nil {
fmt.Fprintf(os.Stderr, "contract failed: procfs.NewFS failed for valid directory: %v\n", err)
os.Exit(1)
}
// 2. procfs.FS.NetDev returns an error when net/dev does not exist
if _, err := fs.NetDev(); err == nil {
fmt.Fprintf(os.Stderr, "contract failed: expected error when net/dev does not exist, got nil\n")
os.Exit(1)
}
// 3. procfs.FS.NetDev parses /proc/net/dev and returns device statistics by interface name
netDir := filepath.Join(mockDir, "net")
if err := os.MkdirAll(netDir, 0755); err != nil {
fmt.Fprintf(os.Stderr, "failed to create mock net directory: %v\n", err)
os.Exit(1)
}
mockDevData := "Inter-| Receive | Transmit\n" +
" face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed\n" +
" lo: 1024 16 0 0 0 0 0 0 1024 16 0 0 0 0 0 0\n" +
" eth0: 2097152 16384 1 2 3 4 0 5 1048576 8192 6 7 8 9 10 0\n"
if err := os.WriteFile(filepath.Join(netDir, "dev"), []byte(mockDevData), 0644); err != nil {
fmt.Fprintf(os.Stderr, "failed to write mock net/dev: %v\n", err)
os.Exit(1)
}
netDev, err := fs.NetDev()
if err != nil {
fmt.Fprintf(os.Stderr, "contract failed: fs.NetDev() returned error: %v\n", err)
os.Exit(1)
}
if len(netDev) != 2 {
fmt.Fprintf(os.Stderr, "contract failed: expected 2 interfaces, got %d\n", len(netDev))
os.Exit(1)
}
lo, ok := netDev["lo"]
if !ok {
fmt.Fprintf(os.Stderr, "contract failed: 'lo' interface missing in netDev map\n")
os.Exit(1)
}
if lo.Name != "lo" || lo.RxBytes != 1024 || lo.TxBytes != 1024 || lo.RxPackets != 16 || lo.TxPackets != 16 {
fmt.Fprintf(os.Stderr, "contract failed: unexpected stats for 'lo': %+v\n", lo)
os.Exit(1)
}
eth0, ok := netDev["eth0"]
if !ok {
fmt.Fprintf(os.Stderr, "contract failed: 'eth0' interface missing in netDev map\n")
os.Exit(1)
}
if eth0.Name != "eth0" || eth0.RxBytes != 2097152 || eth0.TxBytes != 1048576 || eth0.RxPackets != 16384 || eth0.TxPackets != 8192 {
fmt.Fprintf(os.Stderr, "contract failed: unexpected byte/packet counts for 'eth0': %+v\n", eth0)
os.Exit(1)
}
if eth0.RxErrors != 1 || eth0.RxDropped != 2 || eth0.RxFIFO != 3 || eth0.RxFrame != 4 || eth0.RxMulticast != 5 {
fmt.Fprintf(os.Stderr, "contract failed: unexpected rx detail for 'eth0': %+v\n", eth0)
os.Exit(1)
}
if eth0.TxErrors != 6 || eth0.TxDropped != 7 || eth0.TxFIFO != 8 || eth0.TxCollisions != 9 || eth0.TxCarrier != 10 {
fmt.Fprintf(os.Stderr, "contract failed: unexpected tx detail for 'eth0': %+v\n", eth0)
os.Exit(1)
}
// 4. procfs.NetDev.Total calculates cumulative network statistics across all interfaces
total := netDev.Total()
expectedRxBytes := uint64(1024 + 2097152)
expectedTxBytes := uint64(1024 + 1048576)
expectedRxPackets := uint64(16 + 16384)
expectedTxPackets := uint64(16 + 8192)
if total.RxBytes != expectedRxBytes {
fmt.Fprintf(os.Stderr, "contract failed: expected total RxBytes %d, got %d\n", expectedRxBytes, total.RxBytes)
os.Exit(1)
}
if total.TxBytes != expectedTxBytes {
fmt.Fprintf(os.Stderr, "contract failed: expected total TxBytes %d, got %d\n", expectedTxBytes, total.TxBytes)
os.Exit(1)
}
if total.RxPackets != expectedRxPackets {
fmt.Fprintf(os.Stderr, "contract failed: expected total RxPackets %d, got %d\n", expectedRxPackets, total.RxPackets)
os.Exit(1)
}
if total.TxPackets != expectedTxPackets {
fmt.Fprintf(os.Stderr, "contract failed: expected total TxPackets %d, got %d\n", expectedTxPackets, total.TxPackets)
os.Exit(1)
}
fmt.Println("PASS")
}
Ursprungs-Seeder
anonym