Send protocol information as a label
This commit is contained in:
parent
67855d14c9
commit
5b4c9492d7
|
@ -27,7 +27,7 @@ var (
|
|||
Name: "requests",
|
||||
Help: "Number of requests",
|
||||
},
|
||||
[]string{"project", "network", "success"},
|
||||
[]string{"project", "network", "protocol", "success"},
|
||||
)
|
||||
|
||||
bytesCounter = prometheus.NewCounterVec(
|
||||
|
@ -36,7 +36,7 @@ var (
|
|||
Name: "bytes",
|
||||
Help: "Number of bytes transferred",
|
||||
},
|
||||
[]string{"project", "network", "success"},
|
||||
[]string{"project", "network", "protocol", "success"},
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -88,6 +88,7 @@ func process(requests <-chan *Request) {
|
|||
labels := prometheus.Labels{
|
||||
"project": project,
|
||||
"network": net,
|
||||
"protocol": request.Protocol.String(),
|
||||
"success": boolToString(request.Success),
|
||||
}
|
||||
requestsCounter.With(labels).Inc()
|
||||
|
|
4
nginx.go
4
nginx.go
|
@ -64,10 +64,14 @@ func processNginxLogLine(line *tail.Line, c chan<- *Request) {
|
|||
size, _ := strconv.ParseFloat(sizeStr, 64)
|
||||
|
||||
path := pathRe.FindStringSubmatch(pathStr)
|
||||
if len(path) != 2 {
|
||||
return;
|
||||
}
|
||||
|
||||
request := Request{
|
||||
SourceIP: net.ParseIP(sourceIP),
|
||||
Path: path[1],
|
||||
Protocol: ProtocolHTTP,
|
||||
Size: size,
|
||||
Success: status >= 200 && status < 300,
|
||||
}
|
||||
|
|
15
request.go
15
request.go
|
@ -4,10 +4,25 @@ import (
|
|||
"net"
|
||||
)
|
||||
|
||||
type RequestProtocol int
|
||||
const (
|
||||
ProtocolHTTP RequestProtocol = iota
|
||||
)
|
||||
|
||||
func (p RequestProtocol) String() string {
|
||||
switch(p) {
|
||||
case ProtocolHTTP:
|
||||
return "http"
|
||||
}
|
||||
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
// Client information
|
||||
SourceIP net.IP
|
||||
Path string
|
||||
Protocol RequestProtocol
|
||||
|
||||
// Result
|
||||
Size float64
|
||||
|
|
Loading…
Reference in New Issue