Просмотр исходного кода

Merge pull request #25 from 9seconds/stats

Simplify stats
tags/0.10
Sergey Arkhipov 7 лет назад
Родитель
Сommit
18e46241f8
Аккаунт пользователя с таким Email не найден
2 измененных файлов: 22 добавлений и 26 удалений
  1. 11
    17
      stats/channels.go
  2. 11
    9
      stats/stats.go

+ 11
- 17
stats/channels.go Просмотреть файл

40
 	}
40
 	}
41
 }
41
 }
42
 
42
 
43
-func connectionManager() { // nolint: gocyclo
43
+func connectionManager() {
44
 	for event := range connectionsChan {
44
 	for event := range connectionsChan {
45
 		instance.mutex.RLock()
45
 		instance.mutex.RLock()
46
 
46
 
53
 		switch event.connectionType {
53
 		switch event.connectionType {
54
 		case mtproto.ConnectionTypeAbridged:
54
 		case mtproto.ConnectionTypeAbridged:
55
 			if isIPv4 {
55
 			if isIPv4 {
56
-				instance.ActiveConnections.Abridged.IPv4 += inc
57
-				if event.connected {
58
-					instance.AllConnections.Abridged.IPv4 += inc
59
-				}
56
+				instance.Connections.Abridged.IPv4 += inc
60
 			} else {
57
 			} else {
61
-				instance.ActiveConnections.Abridged.IPv6 += inc
62
-				if event.connected {
63
-					instance.AllConnections.Abridged.IPv6 += inc
64
-				}
58
+				instance.Connections.Abridged.IPv6 += inc
59
+			}
60
+		case mtproto.ConnectionTypeSecure:
61
+			if isIPv4 {
62
+				instance.Connections.Secure.IPv4 += inc
63
+			} else {
64
+				instance.Connections.Secure.IPv6 += inc
65
 			}
65
 			}
66
 		default:
66
 		default:
67
 			if isIPv4 {
67
 			if isIPv4 {
68
-				instance.ActiveConnections.Intermediate.IPv4 += inc
69
-				if event.connected {
70
-					instance.AllConnections.Intermediate.IPv4 += inc
71
-				}
68
+				instance.Connections.Intermediate.IPv4 += inc
72
 			} else {
69
 			} else {
73
-				instance.ActiveConnections.Intermediate.IPv6 += inc
74
-				if event.connected {
75
-					instance.AllConnections.Intermediate.IPv6 += inc
76
-				}
70
+				instance.Connections.Intermediate.IPv6 += inc
77
 			}
71
 			}
78
 		}
72
 		}
79
 
73
 

+ 11
- 9
stats/stats.go Просмотреть файл

52
 	All          connectionType `json:"all"`
52
 	All          connectionType `json:"all"`
53
 	Abridged     connectionType `json:"abridged"`
53
 	Abridged     connectionType `json:"abridged"`
54
 	Intermediate connectionType `json:"intermediate"`
54
 	Intermediate connectionType `json:"intermediate"`
55
+	Secure       connectionType `json:"secure"`
55
 }
56
 }
56
 
57
 
57
 func (c connections) MarshalJSON() ([]byte, error) {
58
 func (c connections) MarshalJSON() ([]byte, error) {
58
-	c.All.IPv4 = c.Abridged.IPv4 + c.Intermediate.IPv4
59
-	c.All.IPv6 = c.Abridged.IPv6 + c.Intermediate.IPv6
59
+	c.All.IPv4 = c.Abridged.IPv4 + c.Intermediate.IPv4 + c.Secure.IPv4
60
+	c.All.IPv6 = c.Abridged.IPv6 + c.Intermediate.IPv6 + c.Secure.IPv6
60
 
61
 
61
 	value := struct {
62
 	value := struct {
62
 		All          connectionType `json:"all"`
63
 		All          connectionType `json:"all"`
63
 		Abridged     connectionType `json:"abridged"`
64
 		Abridged     connectionType `json:"abridged"`
64
 		Intermediate connectionType `json:"intermediate"`
65
 		Intermediate connectionType `json:"intermediate"`
66
+		Secure       connectionType `json:"secure"`
65
 	}{
67
 	}{
66
 		All:          c.All,
68
 		All:          c.All,
67
 		Abridged:     c.Abridged,
69
 		Abridged:     c.Abridged,
68
 		Intermediate: c.Intermediate,
70
 		Intermediate: c.Intermediate,
71
+		Secure:       c.Secure,
69
 	}
72
 	}
70
 
73
 
71
 	return json.Marshal(value)
74
 	return json.Marshal(value)
87
 }
90
 }
88
 
91
 
89
 type stats struct {
92
 type stats struct {
90
-	URLs              config.IPURLs `json:"urls"`
91
-	ActiveConnections connections   `json:"active_connections"`
92
-	AllConnections    connections   `json:"all_connections"`
93
-	Traffic           traffic       `json:"traffic"`
94
-	Speed             speed         `json:"speed"`
95
-	Uptime            uptime        `json:"uptime"`
96
-	Crashes           uint32        `json:"crashes"`
93
+	URLs        config.IPURLs `json:"urls"`
94
+	Connections connections   `json:"connections"`
95
+	Traffic     traffic       `json:"traffic"`
96
+	Speed       speed         `json:"speed"`
97
+	Uptime      uptime        `json:"uptime"`
98
+	Crashes     uint32        `json:"crashes"`
97
 
99
 
98
 	speedCurrent speed
100
 	speedCurrent speed
99
 	mutex        *sync.RWMutex
101
 	mutex        *sync.RWMutex

Загрузка…
Отмена
Сохранить