-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpfpm.go
34 lines (30 loc) · 1023 Bytes
/
phpfpm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"regexp"
"strings"
)
func phpfpmStatus(httpReply string) string {
//find all numbers
var connections = regexp.MustCompile(`\d+`)
//match all new lines
var removeNewLines = regexp.MustCompile(`\n`)
//match everything up to and the accepted con string
var removeHeader = regexp.MustCompile(`^.*accepted conn.`)
//Return http status code on error
if httpReply[:5] == "http/" {
return httpReply
}
//trim all whitespace and remove new lines
cleanReply := removeNewLines.ReplaceAllString(strings.TrimSpace(httpReply), "")
//remove everything that matches regexp
cleanReply = removeHeader.ReplaceAllString(cleanReply, "")
//Remove everything but the numbers
phpfpmValues := connections.FindAllStringSubmatch(cleanReply, -1)
//iterate over all values and create []string
statusValues := make([]string, len(phpfpmValues))
for i := range statusValues {
statusValues[i] = phpfpmValues[i][0]
}
//Join all values with a new line intersected
return strings.Join(statusValues, "\n")
}