Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 052466e

Browse files
committed
Try to determine network type
1 parent 1b2555a commit 052466e

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/phpfpm-prometheus-exporter
2+
/main

main.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,32 @@ func GetFilesIn(dirPath string) []string {
267267

268268
func PollFpmStatusMetricsNativeClient(p *PhpFpmPool, pollInterval int, pollTimeout int, cgiFastCgiPath string, cgiFastCgiLdLibPath string, mustQuit chan bool, done chan bool) {
269269
poolCpy := p.GetSyncedCopy()
270+
endpoint := poolCpy.Endpoint
270271

271272
env := make(map[string]string)
272273
env["SCRIPT_NAME"] = poolCpy.StatusUri
273274
env["SCRIPT_FILENAME"] = poolCpy.StatusUri
274275
env["QUERY_STRING"] = "json"
275-
env["SERVER_SOFTWARE"] = "go / fcgiclient"
276-
env["REMOTE_ADDR"] = "127.0.0.1"
276+
env["SERVER_SOFTWARE"] = "go/fcgiclient"
277277

278278
var mts FpmPoolMetrics
279279

280+
var netType string
281+
fileInfo, err := os.Stat(endpoint)
282+
if err != nil {
283+
netType = "tcp"
284+
} else {
285+
if fileInfo.Mode()&os.ModeSocket != 0 {
286+
netType = "unix"
287+
} else {
288+
netType = "tcp"
289+
}
290+
}
291+
292+
log.Infoln(endpoint + " has been identified as " + netType + " network type")
293+
280294
for i := 0; i < 1; {
281-
fcgi, err := fcgiclient.DialTimeout("unix", poolCpy.Endpoint, time.Duration(500*int(time.Millisecond)))
295+
fcgi, err := fcgiclient.DialTimeout(netType, endpoint, time.Duration(500*int(time.Millisecond)))
282296
if err != nil {
283297
log.Errorln(err.Error())
284298
continue

0 commit comments

Comments
 (0)