server.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright 2020 fatedier, fatedier@gmail.com
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package aggregate
  15. import (
  16. "github.com/fatedier/frp/pkg/metrics/mem"
  17. "github.com/fatedier/frp/pkg/metrics/prometheus"
  18. "github.com/fatedier/frp/server/metrics"
  19. )
  20. // EnableMem start to mark metrics to memory monitor system.
  21. func EnableMem() {
  22. sm.Add(mem.ServerMetrics)
  23. }
  24. // EnablePrometheus start to mark metrics to prometheus.
  25. func EnablePrometheus() {
  26. sm.Add(prometheus.ServerMetrics)
  27. }
  28. var sm *serverMetrics = &serverMetrics{}
  29. func init() {
  30. metrics.Register(sm)
  31. }
  32. type serverMetrics struct {
  33. ms []metrics.ServerMetrics
  34. }
  35. func (m *serverMetrics) Add(sm metrics.ServerMetrics) {
  36. m.ms = append(m.ms, sm)
  37. }
  38. func (m *serverMetrics) NewClient() {
  39. for _, v := range m.ms {
  40. v.NewClient()
  41. }
  42. }
  43. func (m *serverMetrics) CloseClient() {
  44. for _, v := range m.ms {
  45. v.CloseClient()
  46. }
  47. }
  48. func (m *serverMetrics) NewProxy(name string, proxyType string) {
  49. for _, v := range m.ms {
  50. v.NewProxy(name, proxyType)
  51. }
  52. }
  53. func (m *serverMetrics) CloseProxy(name string, proxyType string) {
  54. for _, v := range m.ms {
  55. v.CloseProxy(name, proxyType)
  56. }
  57. }
  58. func (m *serverMetrics) OpenConnection(name string, proxyType string) {
  59. for _, v := range m.ms {
  60. v.OpenConnection(name, proxyType)
  61. }
  62. }
  63. func (m *serverMetrics) CloseConnection(name string, proxyType string) {
  64. for _, v := range m.ms {
  65. v.CloseConnection(name, proxyType)
  66. }
  67. }
  68. func (m *serverMetrics) AddTrafficIn(name string, proxyType string, trafficBytes int64) {
  69. for _, v := range m.ms {
  70. v.AddTrafficIn(name, proxyType, trafficBytes)
  71. }
  72. }
  73. func (m *serverMetrics) AddTrafficOut(name string, proxyType string, trafficBytes int64) {
  74. for _, v := range m.ms {
  75. v.AddTrafficOut(name, proxyType, trafficBytes)
  76. }
  77. }