modify the metric
This commit is contained in:
parent
745efb4991
commit
1064f48811
@ -302,7 +302,7 @@ func doLogin(req *msg.ControlReq, c *conn.Conn) (ret int64, info string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update metric's proxy status
|
// update metric's proxy status
|
||||||
metric.SetProxyInfo(s.Name, s.Type, s.BindAddr, s.UseEncryption, s.UseGzip, s.PrivilegeMode, s.CustomDomains, s.ListenPort)
|
metric.SetProxyInfo(*s.ProxyServerConf)
|
||||||
|
|
||||||
// start proxy and listen for user connections, no block
|
// start proxy and listen for user connections, no block
|
||||||
err := s.Start(c)
|
err := s.Start(c)
|
||||||
|
@ -15,13 +15,23 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
type BaseConf struct {
|
type BaseConf struct {
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
AuthToken string
|
AuthToken string `json:"-"`
|
||||||
Type string
|
Type string `json:"type"`
|
||||||
UseEncryption bool
|
UseEncryption bool `json:"use_encryption"`
|
||||||
UseGzip bool
|
UseGzip bool `json:"use_gzip"`
|
||||||
PrivilegeMode bool
|
PrivilegeMode bool `json:"privilege_mode"`
|
||||||
PrivilegeToken string
|
PrivilegeToken string `json:"-"`
|
||||||
PoolCount int64
|
PoolCount int64 `json:"pool_count"`
|
||||||
HostHeaderRewrite string
|
HostHeaderRewrite string `json:"host_header_rewrite"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProxyServerConf struct {
|
||||||
|
BaseConf
|
||||||
|
BindAddr string `json:"bind_addr"`
|
||||||
|
ListenPort int64 `json:"bind_port"`
|
||||||
|
CustomDomains []string `json:"custom_domains"`
|
||||||
|
Locations []string `json:"custom_locations"`
|
||||||
|
|
||||||
|
Status int64 `json:"status"`
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatedier/frp/src/models/config"
|
||||||
"github.com/fatedier/frp/src/models/consts"
|
"github.com/fatedier/frp/src/models/consts"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,15 +30,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ServerMetric struct {
|
type ServerMetric struct {
|
||||||
Name string `json:"name"`
|
config.ProxyServerConf
|
||||||
Type string `json:"type"`
|
StatusDesc string `json:"status_desc"`
|
||||||
BindAddr string `json:"bind_addr"`
|
|
||||||
ListenPort int64 `json:"listen_port"`
|
|
||||||
CustomDomains []string `json:"custom_domains"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
UseEncryption bool `json:"use_encryption"`
|
|
||||||
UseGzip bool `json:"use_gzip"`
|
|
||||||
PrivilegeMode bool `json:"privilege_mode"`
|
|
||||||
|
|
||||||
// statistics
|
// statistics
|
||||||
CurrentConns int64 `json:"current_conns"`
|
CurrentConns int64 `json:"current_conns"`
|
||||||
@ -110,24 +104,16 @@ func GetProxyMetrics(proxyName string) *ServerMetric {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetProxyInfo(proxyName string, proxyType, bindAddr string,
|
func SetProxyInfo(p config.ProxyServerConf) {
|
||||||
useEncryption, useGzip, privilegeMode bool, customDomains []string,
|
|
||||||
listenPort int64) {
|
|
||||||
smMutex.Lock()
|
smMutex.Lock()
|
||||||
info, ok := ServerMetricInfoMap[proxyName]
|
info, ok := ServerMetricInfoMap[p.Name]
|
||||||
if !ok {
|
if !ok {
|
||||||
info = &ServerMetric{}
|
info = &ServerMetric{}
|
||||||
info.Daily = make([]*DailyServerStats, 0)
|
info.Daily = make([]*DailyServerStats, 0)
|
||||||
}
|
}
|
||||||
info.Name = proxyName
|
|
||||||
info.Type = proxyType
|
info.ProxyServerConf = p
|
||||||
info.UseEncryption = useEncryption
|
ServerMetricInfoMap[p.Name] = info
|
||||||
info.UseGzip = useGzip
|
|
||||||
info.PrivilegeMode = privilegeMode
|
|
||||||
info.BindAddr = bindAddr
|
|
||||||
info.ListenPort = listenPort
|
|
||||||
info.CustomDomains = customDomains
|
|
||||||
ServerMetricInfoMap[proxyName] = info
|
|
||||||
smMutex.Unlock()
|
smMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +123,7 @@ func SetStatus(proxyName string, status int64) {
|
|||||||
smMutex.RUnlock()
|
smMutex.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
metric.mutex.Lock()
|
metric.mutex.Lock()
|
||||||
metric.Status = consts.StatusStr[status]
|
metric.StatusDesc = consts.StatusStr[status]
|
||||||
metric.mutex.Unlock()
|
metric.mutex.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,9 +300,8 @@ func loadProxyConf(confFile string) (proxyServers map[string]*ProxyServer, err e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set metric statistics of all proxies
|
// set metric statistics of all proxies
|
||||||
for name, p := range proxyServers {
|
for _, p := range proxyServers {
|
||||||
metric.SetProxyInfo(name, p.Type, p.BindAddr, p.UseEncryption, p.UseGzip,
|
metric.SetProxyInfo(*p.ProxyServerConf)
|
||||||
p.PrivilegeMode, p.CustomDomains, p.ListenPort)
|
|
||||||
}
|
}
|
||||||
return proxyServers, nil
|
return proxyServers, nil
|
||||||
}
|
}
|
||||||
@ -363,8 +362,7 @@ func CreateProxy(s *ProxyServer) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ProxyServers[s.Name] = s
|
ProxyServers[s.Name] = s
|
||||||
metric.SetProxyInfo(s.Name, s.Type, s.BindAddr, s.UseEncryption, s.UseGzip,
|
metric.SetProxyInfo(*s.ProxyServerConf)
|
||||||
s.PrivilegeMode, s.CustomDomains, s.ListenPort)
|
|
||||||
s.Init()
|
s.Init()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -33,14 +33,9 @@ type Listener interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ProxyServer struct {
|
type ProxyServer struct {
|
||||||
config.BaseConf
|
*config.ProxyServerConf
|
||||||
BindAddr string
|
|
||||||
ListenPort int64
|
|
||||||
CustomDomains []string
|
|
||||||
Locations []string
|
|
||||||
|
|
||||||
Status int64
|
CtlConn *conn.Conn `json:"-"` // control connection with frpc
|
||||||
CtlConn *conn.Conn // control connection with frpc
|
|
||||||
listeners []Listener // accept new connection from remote users
|
listeners []Listener // accept new connection from remote users
|
||||||
ctlMsgChan chan int64 // every time accept a new user conn, put "1" to the channel
|
ctlMsgChan chan int64 // every time accept a new user conn, put "1" to the channel
|
||||||
workConnChan chan *conn.Conn // get new work conns from control goroutine
|
workConnChan chan *conn.Conn // get new work conns from control goroutine
|
||||||
@ -49,8 +44,9 @@ type ProxyServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewProxyServer() (p *ProxyServer) {
|
func NewProxyServer() (p *ProxyServer) {
|
||||||
|
psc := &config.ProxyServerConf{CustomDomains: make([]string, 0)}
|
||||||
p = &ProxyServer{
|
p = &ProxyServer{
|
||||||
CustomDomains: make([]string, 0),
|
ProxyServerConf: psc,
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
//"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ func (v *VhostMuxer) ListenByRouter(name string, domains []string, locations []s
|
|||||||
accept: make(chan *conn.Conn),
|
accept: make(chan *conn.Conn),
|
||||||
}
|
}
|
||||||
v.registryRouter.add(name, domain, locations, l)
|
v.registryRouter.add(name, domain, locations, l)
|
||||||
ls = append(ls)
|
ls = append(ls, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ls
|
return ls
|
||||||
@ -129,17 +129,19 @@ func (v *VhostMuxer) handle(c *conn.Conn) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
name = strings.ToLower(name)
|
//name = strings.ToLower(name)
|
||||||
l, ok := v.getListener(name)
|
l, ok := v.getListener(name)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = sConn.SetDeadline(time.Time{}); err != nil {
|
if err = sConn.SetDeadline(time.Time{}); err != nil {
|
||||||
|
log.Error("set dead line err: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.SetTcpConn(sConn)
|
c.SetTcpConn(sConn)
|
||||||
|
|
||||||
|
log.Debug("handle request: %s", c.GetRemoteAddr())
|
||||||
l.accept <- c
|
l.accept <- c
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,10 +155,12 @@ type Listener struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *Listener) Accept() (*conn.Conn, error) {
|
func (l *Listener) Accept() (*conn.Conn, error) {
|
||||||
|
log.Debug("[%s][%s] now to accept ...", l.name, l.domain)
|
||||||
conn, ok := <-l.accept
|
conn, ok := <-l.accept
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("Listener closed")
|
return nil, fmt.Errorf("Listener closed")
|
||||||
}
|
}
|
||||||
|
log.Debug("[%s][%s] accept something ...", l.name, l.domain)
|
||||||
|
|
||||||
// if rewriteFunc is exist and rewriteHost is set
|
// if rewriteFunc is exist and rewriteHost is set
|
||||||
// rewrite http requests with a modified host header
|
// rewrite http requests with a modified host header
|
||||||
|
Loading…
Reference in New Issue
Block a user