-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphpfmp.go
58 lines (44 loc) · 1.02 KB
/
phpfmp.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/tomasen/fcgi_client"
)
func getStats(
dialNetwork, dialAddress string,
fcgiParams map[string]string,
) map[string]string {
fcgi, err := fcgiclient.Dial(dialNetwork, dialAddress)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
statsResponse, err := fcgi.Get(fcgiParams)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
statsBody, err := ioutil.ReadAll(statsResponse.Body)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
stats := parseStats(string(statsBody))
return stats
}
func parseStats(statsBody string) map[string]string {
stats := make(map[string]string)
statsByLine := strings.Split(statsBody, "\n")
for _, statistic := range statsByLine {
if statistic == "" {
continue
}
splitStatistc := strings.Split(statistic, ":")
statName := strings.Replace(splitStatistc[0], " ", "_", -1)
statValue := strings.TrimSpace(strings.Join(splitStatistc[1:], ":"))
stats[statName] = statValue
}
return stats
}