|
1 | 1 | package phpfpm
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "strings" |
4 | 5 | "sync"
|
| 6 | + "unicode" |
5 | 7 |
|
6 | 8 | "github.com/prometheus/client_golang/prometheus"
|
7 | 9 | "go.uber.org/zap"
|
@@ -42,8 +44,47 @@ func (c *PromCollector) setAndCollect(gaugeVec *prometheus.GaugeVec, poolName st
|
42 | 44 | gauge.Collect(ch)
|
43 | 45 | }
|
44 | 46 |
|
| 47 | +func (c *PromCollector) getStatusListenPath(pool Pool) string { |
| 48 | + if pool.StatusListen != "" { |
| 49 | + return pool.StatusListen |
| 50 | + } |
| 51 | + |
| 52 | + return pool.Listen |
| 53 | +} |
| 54 | + |
| 55 | +func (c *PromCollector) isDigitOnlyStr(s string) bool { |
| 56 | + for _, r := range s { |
| 57 | + if !unicode.IsDigit(r) { |
| 58 | + return false |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + return true |
| 63 | +} |
| 64 | + |
| 65 | +func (c *PromCollector) listenToNetAndAddr(listen string) (string, string) { |
| 66 | + network := "unix" |
| 67 | + const localhost = "127.0.0.1" |
| 68 | + semicolonPos := strings.IndexByte(listen, ':') |
| 69 | + |
| 70 | + if semicolonPos != -1 { |
| 71 | + network = "tcp" |
| 72 | + if semicolonPos == 0 { |
| 73 | + listen = localhost + listen |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + if c.isDigitOnlyStr(listen) { |
| 78 | + network = "tcp" |
| 79 | + listen = localhost + ":" + listen |
| 80 | + } |
| 81 | + |
| 82 | + return network, listen |
| 83 | +} |
| 84 | + |
45 | 85 | func (c *PromCollector) collectForPool(pool Pool, ch chan<- prometheus.Metric) {
|
46 |
| - status, err := GetStats(pool.Listen, pool.StatusPath) |
| 86 | + net, addr := c.listenToNetAndAddr(c.getStatusListenPath(pool)) |
| 87 | + status, err := GetStats(net, addr, pool.StatusPath) |
47 | 88 | if err != nil {
|
48 | 89 | c.log.Error("can't collect metrics", zap.String("pool", pool.Name), zap.Error(err))
|
49 | 90 | return
|
|
0 commit comments