initial import
This commit is contained in:
31
core/prometheus/agent.go
Normal file
31
core/prometheus/agent.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"zero/core/logx"
|
||||
"zero/core/threading"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
|
||||
func StartAgent(c Config) {
|
||||
once.Do(func() {
|
||||
if len(c.Host) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
threading.GoSafe(func() {
|
||||
http.Handle(c.Path, promhttp.Handler())
|
||||
addr := fmt.Sprintf("%s:%d", c.Host, c.Port)
|
||||
logx.Infof("Starting prometheus agent at %s", addr)
|
||||
if err := http.ListenAndServe(addr, nil); err != nil {
|
||||
logx.Error(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
7
core/prometheus/config.go
Normal file
7
core/prometheus/config.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package prometheus
|
||||
|
||||
type Config struct {
|
||||
Host string `json:",optional"`
|
||||
Port int `json:",default=9101"`
|
||||
Path string `json:",default=/metrics"`
|
||||
}
|
||||
Reference in New Issue
Block a user