6647f95be4
Wire-format and metric overhaul. Both file and UDP ingest now share one
versioned ParseLine that dispatches on the v<N>\t prefix; v1 stays
unchanged, v2 adds $bytes_sent (replacing $body_bytes_sent),
$request_length, $upstream_response_time, and $upstream_status. File
ingest gains the same versioning, and the legacy positional file format
is removed (no live deployments).
Prometheus exposition is rewritten:
- nginx_http_bytes_sent and nginx_http_request_duration_seconds gain
a source_tag label.
- nginx_http_requests_by_source_total gains status_class.
- New v2-only metrics: nginx_http_request_bytes,
nginx_http_upstream_duration_seconds,
nginx_http_upstream_requests_total{status_class}.
- Dropped nginx_http_response_body_bytes_by_source (subsumed by the
dual-labeled bytes_sent metric).
Adds 'make fixstyle' (gofmt -w) and clears all golangci-lint findings
across the repo (errcheck, S1001, ST1005, unused).
Docs in design.md FR-2/FR-8 and user-guide.md are rewritten to present
v2 as the recommended log format.
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
pb "git.ipng.ch/ipng/nginx-logtail/proto/logtailpb"
|
|
)
|
|
|
|
func runTargets(args []string) {
|
|
fs := flag.NewFlagSet("targets", flag.ExitOnError)
|
|
sf, target := bindShared(fs)
|
|
fs.Usage = func() {
|
|
fmt.Fprintln(os.Stderr, "usage: logtail-cli targets [--target host:port] [--json]")
|
|
fs.PrintDefaults()
|
|
}
|
|
_ = fs.Parse(args) // ExitOnError: only returns nil here
|
|
sf.resolve(*target)
|
|
|
|
for _, addr := range sf.targets {
|
|
conn, client, err := dial(addr)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "targets: cannot connect to %s: %v\n", addr, err)
|
|
continue
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
resp, err := client.ListTargets(ctx, &pb.ListTargetsRequest{})
|
|
cancel()
|
|
_ = conn.Close()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "targets: %s: %v\n", addr, err)
|
|
continue
|
|
}
|
|
|
|
if sf.jsonOut {
|
|
type row struct {
|
|
QueryTarget string `json:"query_target"`
|
|
Name string `json:"name"`
|
|
Addr string `json:"addr"`
|
|
}
|
|
for _, t := range resp.Targets {
|
|
_ = json.NewEncoder(os.Stdout).Encode(row{QueryTarget: addr, Name: t.Name, Addr: t.Addr})
|
|
}
|
|
} else {
|
|
if len(sf.targets) > 1 {
|
|
fmt.Println(targetHeader(addr, "", len(sf.targets)))
|
|
}
|
|
for _, t := range resp.Targets {
|
|
addrCol := t.Addr
|
|
if addrCol == "" {
|
|
addrCol = "(self)"
|
|
}
|
|
fmt.Printf("%-40s %s\n", t.Name, addrCol)
|
|
}
|
|
}
|
|
}
|
|
}
|