Send protocol information as a label

This commit is contained in:
Zachary Seguin 2017-06-16 01:40:30 -04:00
parent 67855d14c9
commit 5b4c9492d7
3 changed files with 22 additions and 2 deletions

View File

@ -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()

View File

@ -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,
}

View File

@ -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