Browse Source
* Moved resetting ruleEngineStats to Consumer * Moved counters to Map in TbCoreConsumerStats * Added actuator and MetricsService * Added metrics to core and rule_engine consumers * Replaced summary with counters * Removed most setters and getters from TbRuleEngine stats * Added stats to Transport consumer * Added JsInvoke actuator stats * Removed MetricsServicepull/3063/head
committed by
GitHub
20 changed files with 598 additions and 96 deletions
@ -0,0 +1,33 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.metrics; |
|||
|
|||
import io.micrometer.core.instrument.Counter; |
|||
|
|||
public class StubCounter implements Counter { |
|||
@Override |
|||
public void increment(double amount) {} |
|||
|
|||
@Override |
|||
public double count() { |
|||
return 0; |
|||
} |
|||
|
|||
@Override |
|||
public Id getId() { |
|||
return null; |
|||
} |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.stats; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.actors.JsInvokeStats; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
|
|||
@Service |
|||
public class DefaultJsInvokeStats implements JsInvokeStats { |
|||
private static final String REQUESTS = "requests"; |
|||
private static final String RESPONSES = "responses"; |
|||
private static final String FAILURES = "failures"; |
|||
|
|||
private StatsCounter requestsCounter; |
|||
private StatsCounter responsesCounter; |
|||
private StatsCounter failuresCounter; |
|||
|
|||
@Autowired |
|||
private StatsCounterFactory counterFactory; |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
String key = StatsType.JS_INVOKE.getName(); |
|||
this.requestsCounter = counterFactory.createStatsCounter(key, REQUESTS); |
|||
this.responsesCounter = counterFactory.createStatsCounter(key, RESPONSES); |
|||
this.failuresCounter = counterFactory.createStatsCounter(key, FAILURES); |
|||
} |
|||
|
|||
@Override |
|||
public void incrementRequests(int amount) { |
|||
requestsCounter.add(amount); |
|||
} |
|||
|
|||
@Override |
|||
public void incrementResponses(int amount) { |
|||
responsesCounter.add(amount); |
|||
} |
|||
|
|||
@Override |
|||
public void incrementFailures(int amount) { |
|||
failuresCounter.add(amount); |
|||
} |
|||
|
|||
@Override |
|||
public int getRequests() { |
|||
return requestsCounter.get(); |
|||
} |
|||
|
|||
@Override |
|||
public int getResponses() { |
|||
return responsesCounter.get(); |
|||
} |
|||
|
|||
@Override |
|||
public int getFailures() { |
|||
return failuresCounter.get(); |
|||
} |
|||
|
|||
@Override |
|||
public void reset() { |
|||
requestsCounter.clear(); |
|||
responsesCounter.clear(); |
|||
failuresCounter.clear(); |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.stats; |
|||
|
|||
import org.thingsboard.server.queue.stats.QueueStats; |
|||
|
|||
public class DefaultQueueStats implements QueueStats { |
|||
private final StatsCounter totalCounter; |
|||
private final StatsCounter successfulCounter; |
|||
private final StatsCounter failedCounter; |
|||
|
|||
public DefaultQueueStats(StatsCounter totalCounter, StatsCounter successfulCounter, StatsCounter failedCounter) { |
|||
this.totalCounter = totalCounter; |
|||
this.successfulCounter = successfulCounter; |
|||
this.failedCounter = failedCounter; |
|||
} |
|||
|
|||
@Override |
|||
public void incrementTotal(int amount) { |
|||
totalCounter.add(amount); |
|||
} |
|||
|
|||
@Override |
|||
public void incrementSuccessful(int amount) { |
|||
successfulCounter.add(amount); |
|||
} |
|||
|
|||
@Override |
|||
public void incrementFailed(int amount) { |
|||
failedCounter.add(amount); |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.stats; |
|||
|
|||
import io.micrometer.core.instrument.Counter; |
|||
|
|||
import java.util.concurrent.atomic.AtomicInteger; |
|||
|
|||
public class StatsCounter { |
|||
private final AtomicInteger aiCounter; |
|||
private final Counter micrometerCounter; |
|||
private final String name; |
|||
|
|||
public StatsCounter(AtomicInteger aiCounter, Counter micrometerCounter, String name) { |
|||
this.aiCounter = aiCounter; |
|||
this.micrometerCounter = micrometerCounter; |
|||
this.name = name; |
|||
} |
|||
|
|||
public void increment() { |
|||
aiCounter.incrementAndGet(); |
|||
micrometerCounter.increment(); |
|||
} |
|||
|
|||
public void clear() { |
|||
aiCounter.set(0); |
|||
} |
|||
|
|||
public int get() { |
|||
return aiCounter.get(); |
|||
} |
|||
|
|||
public void add(int delta){ |
|||
aiCounter.addAndGet(delta); |
|||
micrometerCounter.increment(delta); |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.stats; |
|||
|
|||
import io.micrometer.core.instrument.Counter; |
|||
import io.micrometer.core.instrument.MeterRegistry; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.service.metrics.StubCounter; |
|||
|
|||
import java.util.concurrent.atomic.AtomicInteger; |
|||
|
|||
@Service |
|||
public class StatsCounterFactory { |
|||
private static final String STATS_NAME_TAG = "statsName"; |
|||
|
|||
private static final Counter STUB_COUNTER = new StubCounter(); |
|||
|
|||
@Autowired |
|||
private MeterRegistry meterRegistry; |
|||
|
|||
@Value("${metrics.enabled}") |
|||
private Boolean metricsEnabled; |
|||
|
|||
public StatsCounter createStatsCounter(String key, String statsName) { |
|||
return new StatsCounter( |
|||
new AtomicInteger(0), |
|||
metricsEnabled ? |
|||
meterRegistry.counter(key, STATS_NAME_TAG, statsName) |
|||
: STUB_COUNTER, |
|||
statsName |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.stats; |
|||
|
|||
public enum StatsType { |
|||
RULE_ENGINE("ruleEngine"), CORE("core"), TRANSPORT("transport"), JS_INVOKE("jsInvoke"); |
|||
|
|||
private String name; |
|||
|
|||
StatsType(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.actors; |
|||
|
|||
public interface JsInvokeStats { |
|||
default void incrementRequests() { |
|||
incrementRequests(1); |
|||
} |
|||
|
|||
void incrementRequests(int amount); |
|||
|
|||
default void incrementResponses() { |
|||
incrementResponses(1); |
|||
} |
|||
|
|||
void incrementResponses(int amount); |
|||
|
|||
default void incrementFailures() { |
|||
incrementFailures(1); |
|||
} |
|||
|
|||
void incrementFailures(int amount); |
|||
|
|||
int getRequests(); |
|||
|
|||
int getResponses(); |
|||
|
|||
int getFailures(); |
|||
|
|||
void reset(); |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.queue.stats; |
|||
|
|||
public interface QueueStats { |
|||
default void incrementTotal() { |
|||
incrementTotal(1); |
|||
} |
|||
|
|||
void incrementTotal(int amount); |
|||
|
|||
default void incrementSuccessful() { |
|||
incrementSuccessful(1); |
|||
} |
|||
|
|||
void incrementSuccessful(int amount); |
|||
|
|||
|
|||
default void incrementFailed() { |
|||
incrementFailed(1); |
|||
} |
|||
|
|||
void incrementFailed(int amount); |
|||
} |
|||
Loading…
Reference in new issue