mirror of https://github.com/fatedier/frp
Merge 458a8bad52
into e6dacf3a67
commit
7e701eb762
|
@ -68,6 +68,12 @@ func (m *serverMetrics) CloseProxy(name string, proxyType string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *serverMetrics) ProxyStatus(name string, proxyType string, online bool) {
|
||||||
|
for _, v := range m.ms {
|
||||||
|
v.ProxyStatus(name, proxyType, online)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (m *serverMetrics) OpenConnection(name string, proxyType string) {
|
func (m *serverMetrics) OpenConnection(name string, proxyType string) {
|
||||||
for _, v := range m.ms {
|
for _, v := range m.ms {
|
||||||
v.OpenConnection(name, proxyType)
|
v.OpenConnection(name, proxyType)
|
||||||
|
|
|
@ -133,6 +133,20 @@ func (m *serverMetrics) CloseProxy(name string, proxyType string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *serverMetrics) ProxyStatus(name string, proxyType string, online bool) {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
proxyStats, ok := m.info.ProxyStatistics[name]
|
||||||
|
if ok {
|
||||||
|
if online {
|
||||||
|
proxyStats.Status = "online"
|
||||||
|
} else {
|
||||||
|
proxyStats.Status = "offline"
|
||||||
|
}
|
||||||
|
m.info.ProxyStatistics[name] = proxyStats
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (m *serverMetrics) OpenConnection(name string, _ string) {
|
func (m *serverMetrics) OpenConnection(name string, _ string) {
|
||||||
m.info.CurConns.Inc(1)
|
m.info.CurConns.Inc(1)
|
||||||
|
|
||||||
|
@ -217,6 +231,7 @@ func (m *serverMetrics) GetProxiesByType(proxyType string) []*ProxyStats {
|
||||||
TodayTrafficIn: proxyStats.TrafficIn.TodayCount(),
|
TodayTrafficIn: proxyStats.TrafficIn.TodayCount(),
|
||||||
TodayTrafficOut: proxyStats.TrafficOut.TodayCount(),
|
TodayTrafficOut: proxyStats.TrafficOut.TodayCount(),
|
||||||
CurConns: int64(proxyStats.CurConns.Count()),
|
CurConns: int64(proxyStats.CurConns.Count()),
|
||||||
|
Status: proxyStats.Status,
|
||||||
}
|
}
|
||||||
if !proxyStats.LastStartTime.IsZero() {
|
if !proxyStats.LastStartTime.IsZero() {
|
||||||
ps.LastStartTime = proxyStats.LastStartTime.Format("01-02 15:04:05")
|
ps.LastStartTime = proxyStats.LastStartTime.Format("01-02 15:04:05")
|
||||||
|
@ -248,6 +263,7 @@ func (m *serverMetrics) GetProxiesByTypeAndName(proxyType string, proxyName stri
|
||||||
TodayTrafficIn: proxyStats.TrafficIn.TodayCount(),
|
TodayTrafficIn: proxyStats.TrafficIn.TodayCount(),
|
||||||
TodayTrafficOut: proxyStats.TrafficOut.TodayCount(),
|
TodayTrafficOut: proxyStats.TrafficOut.TodayCount(),
|
||||||
CurConns: int64(proxyStats.CurConns.Count()),
|
CurConns: int64(proxyStats.CurConns.Count()),
|
||||||
|
Status: proxyStats.Status,
|
||||||
}
|
}
|
||||||
if !proxyStats.LastStartTime.IsZero() {
|
if !proxyStats.LastStartTime.IsZero() {
|
||||||
res.LastStartTime = proxyStats.LastStartTime.Format("01-02 15:04:05")
|
res.LastStartTime = proxyStats.LastStartTime.Format("01-02 15:04:05")
|
||||||
|
|
|
@ -40,6 +40,7 @@ type ProxyStats struct {
|
||||||
LastStartTime string
|
LastStartTime string
|
||||||
LastCloseTime string
|
LastCloseTime string
|
||||||
CurConns int64
|
CurConns int64
|
||||||
|
Status string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProxyTrafficInfo struct {
|
type ProxyTrafficInfo struct {
|
||||||
|
@ -56,6 +57,7 @@ type ProxyStatistics struct {
|
||||||
CurConns metric.Counter
|
CurConns metric.Counter
|
||||||
LastStartTime time.Time
|
LastStartTime time.Time
|
||||||
LastCloseTime time.Time
|
LastCloseTime time.Time
|
||||||
|
Status string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerStatistics struct {
|
type ServerStatistics struct {
|
||||||
|
|
|
@ -16,6 +16,7 @@ var ServerMetrics metrics.ServerMetrics = newServerMetrics()
|
||||||
type serverMetrics struct {
|
type serverMetrics struct {
|
||||||
clientCount prometheus.Gauge
|
clientCount prometheus.Gauge
|
||||||
proxyCount *prometheus.GaugeVec
|
proxyCount *prometheus.GaugeVec
|
||||||
|
proxyStatus *prometheus.GaugeVec
|
||||||
connectionCount *prometheus.GaugeVec
|
connectionCount *prometheus.GaugeVec
|
||||||
trafficIn *prometheus.CounterVec
|
trafficIn *prometheus.CounterVec
|
||||||
trafficOut *prometheus.CounterVec
|
trafficOut *prometheus.CounterVec
|
||||||
|
@ -37,6 +38,13 @@ func (m *serverMetrics) CloseProxy(_ string, proxyType string) {
|
||||||
m.proxyCount.WithLabelValues(proxyType).Dec()
|
m.proxyCount.WithLabelValues(proxyType).Dec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *serverMetrics) ProxyStatus(name string, proxyType string, online bool) {
|
||||||
|
if online {
|
||||||
|
m.proxyStatus.WithLabelValues(name, proxyType).Set(1)
|
||||||
|
}
|
||||||
|
m.proxyStatus.WithLabelValues(name, proxyType).Set(0)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *serverMetrics) OpenConnection(name string, proxyType string) {
|
func (m *serverMetrics) OpenConnection(name string, proxyType string) {
|
||||||
m.connectionCount.WithLabelValues(name, proxyType).Inc()
|
m.connectionCount.WithLabelValues(name, proxyType).Inc()
|
||||||
}
|
}
|
||||||
|
@ -67,6 +75,12 @@ func newServerMetrics() *serverMetrics {
|
||||||
Name: "proxy_counts",
|
Name: "proxy_counts",
|
||||||
Help: "The current proxy counts",
|
Help: "The current proxy counts",
|
||||||
}, []string{"type"}),
|
}, []string{"type"}),
|
||||||
|
proxyStatus: prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: serverSubsystem,
|
||||||
|
Name: "proxy_status",
|
||||||
|
Help: "The current proxy status",
|
||||||
|
}, []string{"name", "type"}),
|
||||||
connectionCount: prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
connectionCount: prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Subsystem: serverSubsystem,
|
Subsystem: serverSubsystem,
|
||||||
|
|
|
@ -17,6 +17,7 @@ package server
|
||||||
import (
|
import (
|
||||||
"cmp"
|
"cmp"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/fatedier/frp/server/metrics"
|
||||||
"net/http"
|
"net/http"
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
|
@ -253,11 +254,13 @@ func (svr *Service) getProxyStatsByType(proxyType string) (proxyInfos []*ProxySt
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
proxyInfo.Status = "online"
|
proxyInfo.Status = "online"
|
||||||
|
metrics.Server.ProxyStatus(pxy.GetName(), pxy.GetConfigurer().GetBaseConfig().Type, true)
|
||||||
if pxy.GetLoginMsg() != nil {
|
if pxy.GetLoginMsg() != nil {
|
||||||
proxyInfo.ClientVersion = pxy.GetLoginMsg().Version
|
proxyInfo.ClientVersion = pxy.GetLoginMsg().Version
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
proxyInfo.Status = "offline"
|
proxyInfo.Status = "offline"
|
||||||
|
metrics.Server.ProxyStatus(pxy.GetName(), pxy.GetConfigurer().GetBaseConfig().Type, false)
|
||||||
}
|
}
|
||||||
proxyInfo.Name = ps.Name
|
proxyInfo.Name = ps.Name
|
||||||
proxyInfo.TodayTrafficIn = ps.TodayTrafficIn
|
proxyInfo.TodayTrafficIn = ps.TodayTrafficIn
|
||||||
|
|
|
@ -9,6 +9,7 @@ type ServerMetrics interface {
|
||||||
CloseClient()
|
CloseClient()
|
||||||
NewProxy(name string, proxyType string)
|
NewProxy(name string, proxyType string)
|
||||||
CloseProxy(name string, proxyType string)
|
CloseProxy(name string, proxyType string)
|
||||||
|
ProxyStatus(name string, proxyType string, online bool)
|
||||||
OpenConnection(name string, proxyType string)
|
OpenConnection(name string, proxyType string)
|
||||||
CloseConnection(name string, proxyType string)
|
CloseConnection(name string, proxyType string)
|
||||||
AddTrafficIn(name string, proxyType string, trafficBytes int64)
|
AddTrafficIn(name string, proxyType string, trafficBytes int64)
|
||||||
|
@ -31,6 +32,7 @@ func (noopServerMetrics) NewClient() {}
|
||||||
func (noopServerMetrics) CloseClient() {}
|
func (noopServerMetrics) CloseClient() {}
|
||||||
func (noopServerMetrics) NewProxy(string, string) {}
|
func (noopServerMetrics) NewProxy(string, string) {}
|
||||||
func (noopServerMetrics) CloseProxy(string, string) {}
|
func (noopServerMetrics) CloseProxy(string, string) {}
|
||||||
|
func (noopServerMetrics) ProxyStatus(string, string, bool) {}
|
||||||
func (noopServerMetrics) OpenConnection(string, string) {}
|
func (noopServerMetrics) OpenConnection(string, string) {}
|
||||||
func (noopServerMetrics) CloseConnection(string, string) {}
|
func (noopServerMetrics) CloseConnection(string, string) {}
|
||||||
func (noopServerMetrics) AddTrafficIn(string, string, int64) {}
|
func (noopServerMetrics) AddTrafficIn(string, string, int64) {}
|
||||||
|
|
Loading…
Reference in New Issue