@@ -8,25 +8,9 @@ import (
88 "net/http"
99 "time"
1010
11- "github.com/go-chassis/go-chassis/third_party/forked/afex/hystrix-go/hystrix/metric_collector"
1211 "github.com/rcrowley/go-metrics"
1312)
1413
15- // CseCollector is a struct to keeps metric information of Http requests
16- type CseCollector struct {
17- attempts string
18- errors string
19- successes string
20- failures string
21- rejects string
22- shortCircuits string
23- timeouts string
24- fallbackSuccesses string
25- fallbackFailures string
26- totalDuration string
27- runDuration string
28- }
29-
3014// CseCollectorConfig is a struct to keep monitoring information
3115type CseCollectorConfig struct {
3216 // CseMonitorAddr is the http address of the csemonitor server
@@ -43,127 +27,3 @@ type CseCollectorConfig struct {
4327func InitializeCseCollector (config * CseCollectorConfig , r metrics.Registry , app , version , service , env string ) {
4428 go NewReporter (r , config .CseMonitorAddr , config .Header , config .TimeInterval , config .TLSConfig , app , version , service , env ).Run ()
4529}
46-
47- // NewCseCollector creates a new Collector Object
48- func NewCseCollector (name string ) metricCollector.MetricCollector {
49- return & CseCollector {
50- attempts : name + ".attempts" ,
51- errors : name + ".errors" ,
52- successes : name + ".successes" ,
53- failures : name + ".failures" ,
54- rejects : name + ".rejects" ,
55- shortCircuits : name + ".shortCircuits" ,
56- timeouts : name + ".timeouts" ,
57- fallbackSuccesses : name + ".fallbackSuccesses" ,
58- fallbackFailures : name + ".fallbackFailures" ,
59- totalDuration : name + ".totalDuration" ,
60- runDuration : name + ".runDuration" ,
61- }
62- }
63-
64- func (c * CseCollector ) incrementCounterMetric (prefix string ) {
65- count , ok := metrics .GetOrRegister (prefix , metrics .NewCounter ).(metrics.Counter )
66- if ! ok {
67- return
68- }
69- count .Inc (1 )
70- }
71-
72- func (c * CseCollector ) updateTimerMetric (prefix string , dur time.Duration ) {
73- count , ok := metrics .GetOrRegister (prefix , metrics .NewTimer ).(metrics.Timer )
74- if ! ok {
75- return
76- }
77- count .Update (dur )
78- }
79-
80- func (c * CseCollector ) cleanMetric (prefix string ) {
81- count , ok := metrics .GetOrRegister (prefix , metrics .NewCounter ).(metrics.Counter )
82- if ! ok {
83- return
84- }
85- count .Clear ()
86- }
87-
88- // IncrementAttempts function increments the number of calls to this circuit.
89- // This registers as a counter
90- func (c * CseCollector ) IncrementAttempts () {
91- c .incrementCounterMetric (c .attempts )
92- }
93-
94- // IncrementErrors function increments the number of unsuccessful attempts.
95- // Attempts minus Errors will equal successes.
96- // Errors are result from an attempt that is not a success.
97- // This registers as a counter
98- func (c * CseCollector ) IncrementErrors () {
99- c .incrementCounterMetric (c .errors )
100-
101- }
102-
103- // IncrementSuccesses function increments the number of requests that succeed.
104- // This registers as a counter
105- func (c * CseCollector ) IncrementSuccesses () {
106- c .incrementCounterMetric (c .successes )
107-
108- }
109-
110- // IncrementFailures function increments the number of requests that fail.
111- // This registers as a counter
112- func (c * CseCollector ) IncrementFailures () {
113- c .incrementCounterMetric (c .failures )
114- }
115-
116- // IncrementRejects function increments the number of requests that are rejected.
117- // This registers as a counter
118- func (c * CseCollector ) IncrementRejects () {
119- c .incrementCounterMetric (c .rejects )
120- }
121-
122- // IncrementShortCircuits function increments the number of requests that short circuited due to the circuit being open.
123- // This registers as a counter
124- func (c * CseCollector ) IncrementShortCircuits () {
125- c .incrementCounterMetric (c .shortCircuits )
126- }
127-
128- // IncrementTimeouts function increments the number of timeouts that occurred in the circuit breaker.
129- // This registers as a counter
130- func (c * CseCollector ) IncrementTimeouts () {
131- c .incrementCounterMetric (c .timeouts )
132- }
133-
134- // IncrementFallbackSuccesses function increments the number of successes that occurred during the execution of the fallback function.
135- // This registers as a counter
136- func (c * CseCollector ) IncrementFallbackSuccesses () {
137- c .incrementCounterMetric (c .fallbackSuccesses )
138- }
139-
140- // IncrementFallbackFailures function increments the number of failures that occurred during the execution of the fallback function.
141- // This registers as a counter
142- func (c * CseCollector ) IncrementFallbackFailures () {
143- c .incrementCounterMetric (c .fallbackFailures )
144- }
145-
146- // UpdateTotalDuration function updates the internal counter of how long we've run for.
147- // This registers as a timer
148- func (c * CseCollector ) UpdateTotalDuration (timeSinceStart time.Duration ) {
149- c .updateTimerMetric (c .totalDuration , timeSinceStart )
150- }
151-
152- // UpdateRunDuration function updates the internal counter of how long the last run took.
153- // This registers as a timer
154- func (c * CseCollector ) UpdateRunDuration (runDuration time.Duration ) {
155- c .updateTimerMetric (c .runDuration , runDuration )
156- }
157-
158- // Reset function is a noop operation in this collector.
159- func (c * CseCollector ) Reset () {
160- c .cleanMetric (c .attempts )
161- c .cleanMetric (c .failures )
162- c .cleanMetric (c .successes )
163- c .cleanMetric (c .shortCircuits )
164- c .cleanMetric (c .errors )
165- c .cleanMetric (c .rejects )
166- c .cleanMetric (c .timeouts )
167- c .cleanMetric (c .fallbackSuccesses )
168- c .cleanMetric (c .fallbackFailures )
169- }
0 commit comments