Bounded StatsD/DogStatsD codec and native async UDP client
| 能力 | 基础 StatsD | DogStatsD | 已做的真实验证 |
|---|---|---|---|
| Counter / Timer(毫秒) | 是 | 是 | StatsD 0.9.0、statsd_exporter 0.28.0、官方 DogStatsD 7.60.0 |
| 非负绝对 Gauge | 是 | 是 | 上述三个真实接收器验证最终值 |
| GaugeDelta | 是 | 拒绝 | StatsD 0.9.0:10 加 -3 得到 7 |
| 负绝对 Gauge | 明确报错 | 明确报错 | 不把它误作负增量 |
| Set | 是 | 是 | StatsD 0.9.0 / 官方 DogStatsD 7.60.0 去重;wire 差分 |
| Histogram / Distribution | 拒绝 | 是 | h:exporter 与官方 DogStatsD;d:exporter 与 wire 差分 |
| namespace、固定及调用级标签 | namespace;拒绝标签 | 是 | 采集器标签和参考客户端 wire |
| 概率采样 | Counter、Timer | 再加 Histogram、Distribution | 确定随机源测试;StatsD 采样放大 |
import {
"Ryan-1125/moonstatsd/client",
"moonbitlang/async",
"moonbitlang/async/socket",
}
pkgtype(kind: "executable")async fn main {
let address = @socket.Addr::parse("127.0.0.1:8125")
@client.with_client(address, client => {
ignore(client.record("requests", Counter(1.0), tags=["route:home"]))
ignore(client.record("latency", Timer(12.5))) // 毫秒
ignore(client.record("queue", Gauge(10.0)))
ignore(client.record("queue", Gauge(7.0)))
let report = client.flush()
println("local submitted=\{report.submitted}, send errors=\{report.send_errors}")
ignore(client.close())
}, mode=DogStatsD, prefix="service.", fixed_tags=["env:dev"])
}| 操作或情况 | 确定行为 |
|---|---|
| 队列满 | 拒绝最新调用并增加 queue_full;不覆盖旧指标 |
| 定时刷新 / flush | 单一任务发送;flush 是调用前入队项的完成屏障,后续生产者不延长此屏障 |
| 本机发送错误或发送超时 | 不重试;增加 send_errors(数据报次数)和 dropped(指标数),继续处理后续项 |
| flush 返回 | 返回累计 Stats,必须检查 dropped/send_errors;不是采集器 ACK |
| flush 超时或调用者取消 | 只停止该等待者,发送任务继续 |
| close | 立即拒绝新指标,限时排空;重复调用共享关闭结果 |
| close 超时或调用者取消 | 取消唯一发送任务,剩余项计入 dropped;其他关闭等待者也观察这次中止 |
| callback 成功退出 | 自动 close;失败或作用域取消则中止并丢弃未完成项 |
| 作用域退出 | 等待子任务清理并关闭 socket;逃逸的句柄也已关闭 |
moon update
moon fmt --check
moon info --target native
moon check --target native --deny-warn
moon build --target native --deny-warn
moon test --target native --deny-warn
moon test --target wasm-gc --package Ryan-1125/moonstatsd
./tools/install-collectors.ps1
node tools/test-interop.mjs
node tools/test-reference.mjs
./tools/test-consumer.ps1
moon package --listnode tools/test-agent.mjspub struct Message {
// private fields
}pub(all) enum Metric {
Counter(Double)
Gauge(Double)
GaugeDelta(Double)
Timer(Double)
Set(String)
Histogram(Double)
Distribution(Double)
} derive(Debug)fn pack(messages : Array[Message], max_bytes? : Int, max_total_bytes? : Int) -> Array[Bytes] raise EncodeErrorInstall
Download zipBounded StatsD/DogStatsD codec and native async UDP client