modify the metric

This commit is contained in:
XueBing 2016-12-18 16:34:38 +08:00
parent 745efb4991
commit 1064f48811
6 changed files with 43 additions and 49 deletions

View File

@ -302,7 +302,7 @@ func doLogin(req *msg.ControlReq, c *conn.Conn) (ret int64, info string) {
}
// 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
err := s.Start(c)

View File

@ -15,13 +15,23 @@
package config
type BaseConf struct {
Name string
AuthToken string
Type string
UseEncryption bool
UseGzip bool
PrivilegeMode bool
PrivilegeToken string
PoolCount int64
HostHeaderRewrite string
Name string `json:"name"`
AuthToken string `json:"-"`
Type string `json:"type"`
UseEncryption bool `json:"use_encryption"`
UseGzip bool `json:"use_gzip"`
PrivilegeMode bool `json:"privilege_mode"`
PrivilegeToken string `json:"-"`
PoolCount int64 `json:"pool_count"`
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"`
}

View File

@ -19,6 +19,7 @@ import (
"sync"
"time"
"github.com/fatedier/frp/src/models/config"
"github.com/fatedier/frp/src/models/consts"
)
@ -29,15 +30,8 @@ var (
)
type ServerMetric struct {
Name string `json:"name"`
Type string `json:"type"`
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"`
config.ProxyServerConf
StatusDesc string `json:"status_desc"`
// statistics
CurrentConns int64 `json:"current_conns"`
@ -110,24 +104,16 @@ func GetProxyMetrics(proxyName string) *ServerMetric {
}
}
func SetProxyInfo(proxyName string, proxyType, bindAddr string,
useEncryption, useGzip, privilegeMode bool, customDomains []string,
listenPort int64) {
func SetProxyInfo(p config.ProxyServerConf) {
smMutex.Lock()
info, ok := ServerMetricInfoMap[proxyName]
info, ok := ServerMetricInfoMap[p.Name]
if !ok {
info = &ServerMetric{}
info.Daily = make([]*DailyServerStats, 0)
}
info.Name = proxyName
info.Type = proxyType
info.UseEncryption = useEncryption
info.UseGzip = useGzip
info.PrivilegeMode = privilegeMode
info.BindAddr = bindAddr
info.ListenPort = listenPort
info.CustomDomains = customDomains
ServerMetricInfoMap[proxyName] = info
info.ProxyServerConf = p
ServerMetricInfoMap[p.Name] = info
smMutex.Unlock()
}
@ -137,7 +123,7 @@ func SetStatus(proxyName string, status int64) {
smMutex.RUnlock()
if ok {
metric.mutex.Lock()
metric.Status = consts.StatusStr[status]
metric.StatusDesc = consts.StatusStr[status]
metric.mutex.Unlock()
}
}

View File

@ -300,9 +300,8 @@ func loadProxyConf(confFile string) (proxyServers map[string]*ProxyServer, err e
}
// set metric statistics of all proxies
for name, p := range proxyServers {
metric.SetProxyInfo(name, p.Type, p.BindAddr, p.UseEncryption, p.UseGzip,
p.PrivilegeMode, p.CustomDomains, p.ListenPort)
for _, p := range proxyServers {
metric.SetProxyInfo(*p.ProxyServerConf)
}
return proxyServers, nil
}
@ -363,8 +362,7 @@ func CreateProxy(s *ProxyServer) error {
}
}
ProxyServers[s.Name] = s
metric.SetProxyInfo(s.Name, s.Type, s.BindAddr, s.UseEncryption, s.UseGzip,
s.PrivilegeMode, s.CustomDomains, s.ListenPort)
metric.SetProxyInfo(*s.ProxyServerConf)
s.Init()
return nil
}

View File

@ -33,14 +33,9 @@ type Listener interface {
}
type ProxyServer struct {
config.BaseConf
BindAddr string
ListenPort int64
CustomDomains []string
Locations []string
*config.ProxyServerConf
Status int64
CtlConn *conn.Conn // control connection with frpc
CtlConn *conn.Conn `json:"-"` // control connection with frpc
listeners []Listener // accept new connection from remote users
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
@ -49,8 +44,9 @@ type ProxyServer struct {
}
func NewProxyServer() (p *ProxyServer) {
psc := &config.ProxyServerConf{CustomDomains: make([]string, 0)}
p = &ProxyServer{
CustomDomains: make([]string, 0),
ProxyServerConf: psc,
}
return p
}

View File

@ -19,7 +19,7 @@ import (
"fmt"
"io"
"net"
"strings"
//"strings"
"sync"
"time"
@ -86,7 +86,7 @@ func (v *VhostMuxer) ListenByRouter(name string, domains []string, locations []s
accept: make(chan *conn.Conn),
}
v.registryRouter.add(name, domain, locations, l)
ls = append(ls)
ls = append(ls, l)
}
return ls
@ -129,17 +129,19 @@ func (v *VhostMuxer) handle(c *conn.Conn) {
return
}
name = strings.ToLower(name)
//name = strings.ToLower(name)
l, ok := v.getListener(name)
if !ok {
return
}
if err = sConn.SetDeadline(time.Time{}); err != nil {
log.Error("set dead line err: %v", err)
return
}
c.SetTcpConn(sConn)
log.Debug("handle request: %s", c.GetRemoteAddr())
l.accept <- c
}
@ -153,10 +155,12 @@ type Listener struct {
}
func (l *Listener) Accept() (*conn.Conn, error) {
log.Debug("[%s][%s] now to accept ...", l.name, l.domain)
conn, ok := <-l.accept
if !ok {
return nil, fmt.Errorf("Listener closed")
}
log.Debug("[%s][%s] accept something ...", l.name, l.domain)
// if rewriteFunc is exist and rewriteHost is set
// rewrite http requests with a modified host header