-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
918 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>sofa-rpc-metrics</artifactId> | ||
<groupId>com.alipay.sofa</groupId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>sofa-rpc-metrics-prometheus</artifactId> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>sofa-rpc-api</artifactId> | ||
</dependency> | ||
|
||
<!-- prometheus client --> | ||
<dependency> | ||
<groupId>io.prometheus</groupId> | ||
<artifactId>simpleclient</artifactId> | ||
</dependency> | ||
|
||
<!-- test scope --> | ||
<dependency> | ||
<groupId>io.prometheus</groupId> | ||
<artifactId>simpleclient_httpserver</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>sofa-rpc-log</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<sourceDirectory>src/main/java</sourceDirectory> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>false</filtering> | ||
<includes> | ||
<include>**/**</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
<testSourceDirectory>src/test/java</testSourceDirectory> | ||
<testResources> | ||
<testResource> | ||
<directory>src/test/resources</directory> | ||
<filtering>false</filtering> | ||
<includes> | ||
<include>**/**</include> | ||
</includes> | ||
</testResource> | ||
</testResources> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<encoding>${project.build.sourceEncoding}</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<configuration> | ||
<skip>${module.install.skip}</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<configuration> | ||
<skip>${module.deploy.skip}</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skipTests>${skipTests}</skipTests> | ||
<includes> | ||
<include>**/*Test.java</include> | ||
</includes> | ||
<forkMode>once</forkMode> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
238 changes: 238 additions & 0 deletions
238
...trics-prometheus/src/main/java/com/alipay/sofa/rpc/metrics/prometheus/MetricsBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 com.alipay.sofa.rpc.metrics.prometheus; | ||
|
||
import io.prometheus.client.Counter; | ||
import io.prometheus.client.Gauge; | ||
import io.prometheus.client.Histogram; | ||
|
||
public class MetricsBuilder { | ||
public static final String BYTES = "bytes"; | ||
|
||
public static final String TASKS = "tasks"; | ||
|
||
public static final String THREADS = "threads"; | ||
|
||
private Histogram.Builder clientTotalBuilder = Histogram.build(); | ||
|
||
private Histogram.Builder clientFailBuilder = Histogram.build(); | ||
|
||
private Histogram.Builder serverTotalBuilder = Histogram.build(); | ||
|
||
private Histogram.Builder serverFailBuilder = Histogram.build(); | ||
|
||
private Histogram.Builder requestSizeBuilder = Histogram.build(); | ||
|
||
private Histogram.Builder responseSizeBuilder = Histogram.build(); | ||
|
||
private Counter.Builder providerCounterBuilder = Counter.build(); | ||
|
||
private Counter.Builder consumerCounterBuilder = Counter.build(); | ||
|
||
private Gauge.Builder threadPoolConfigCoreBuilder = Gauge.build(); | ||
|
||
private Gauge.Builder threadPoolConfigMaxBuilder = Gauge.build(); | ||
|
||
private Gauge.Builder threadPoolConfigQueueBuilder = Gauge.build(); | ||
|
||
private Gauge.Builder threadPoolActiveBuilder = Gauge.build(); | ||
|
||
private Gauge.Builder threadPoolIdleBuilder = Gauge.build(); | ||
|
||
private Gauge.Builder threadPoolQueueBuilder = Gauge.build(); | ||
|
||
public Histogram.Builder getClientTotalBuilder() { | ||
return clientTotalBuilder; | ||
} | ||
|
||
public Histogram.Builder getClientFailBuilder() { | ||
return clientFailBuilder; | ||
} | ||
|
||
public Histogram.Builder getServerTotalBuilder() { | ||
return serverTotalBuilder; | ||
} | ||
|
||
public Histogram.Builder getServerFailBuilder() { | ||
return serverFailBuilder; | ||
} | ||
|
||
public Histogram.Builder getRequestSizeBuilder() { | ||
return requestSizeBuilder; | ||
} | ||
|
||
public Histogram.Builder getResponseSizeBuilder() { | ||
return responseSizeBuilder; | ||
} | ||
|
||
public Counter.Builder getProviderCounterBuilder() { | ||
return providerCounterBuilder; | ||
} | ||
|
||
public Counter.Builder getConsumerCounterBuilder() { | ||
return consumerCounterBuilder; | ||
} | ||
|
||
public Gauge.Builder getThreadPoolConfigCoreBuilder() { | ||
return threadPoolConfigCoreBuilder; | ||
} | ||
|
||
public Gauge.Builder getThreadPoolConfigMaxBuilder() { | ||
return threadPoolConfigMaxBuilder; | ||
} | ||
|
||
public Gauge.Builder getThreadPoolConfigQueueBuilder() { | ||
return threadPoolConfigQueueBuilder; | ||
} | ||
|
||
public Gauge.Builder getThreadPoolActiveBuilder() { | ||
return threadPoolActiveBuilder; | ||
} | ||
|
||
public Gauge.Builder getThreadPoolIdleBuilder() { | ||
return threadPoolIdleBuilder; | ||
} | ||
|
||
public Gauge.Builder getThreadPoolQueueBuilder() { | ||
return threadPoolQueueBuilder; | ||
} | ||
|
||
Histogram buildClientTotal(String[] labelNames) { | ||
return clientTotalBuilder | ||
.name("sofa_client_total") | ||
.help("sofa_client_total") | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Histogram buildClientFail(String[] labelNames) { | ||
return clientFailBuilder | ||
.name("sofa_client_fail") | ||
.help("sofa_client_fail") | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Histogram buildServerTotal(String[] labelNames) { | ||
return serverTotalBuilder | ||
.name("sofa_server_total") | ||
.help("sofa_server_total") | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Histogram buildServerFail(String[] labelNames) { | ||
return serverFailBuilder | ||
.name("sofa_server_fail") | ||
.help("sofa_server_fail") | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Histogram buildRequestSize(String[] labelNames) { | ||
return requestSizeBuilder | ||
.name("sofa_request_size") | ||
.help("sofa_request_size") | ||
.unit(BYTES) | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Histogram buildResponseSize(String[] labelNames) { | ||
return responseSizeBuilder | ||
.name("sofa_response_size") | ||
.help("sofa_response_size") | ||
.unit(BYTES) | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Counter buildProviderCounter(String[] labelNames) { | ||
return providerCounterBuilder | ||
.name("sofa_provider") | ||
.help("sofa_provider") | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Counter buildConsumerCounter(String[] labelNames) { | ||
return consumerCounterBuilder | ||
.name("sofa_consumer") | ||
.help("sofa_consumer") | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Gauge buildThreadPoolConfigCore(String[] labelNames) { | ||
return threadPoolConfigCoreBuilder | ||
.name("sofa_threadpool_config_core") | ||
.help("sofa_threadpool_config_core") | ||
.unit(THREADS) | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Gauge buildThreadPoolConfigMax(String[] labelNames) { | ||
return threadPoolConfigMaxBuilder | ||
.name("sofa_threadpool_config_max") | ||
.help("sofa_threadpool_config_max") | ||
.unit(THREADS) | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Gauge buildThreadPoolConfigQueue(String[] labelNames) { | ||
return threadPoolConfigQueueBuilder | ||
.name("sofa_threadpool_config_queue") | ||
.help("sofa_threadpool_config_queue") | ||
.unit(TASKS) | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Gauge buildThreadPoolActive(String[] labelNames) { | ||
return threadPoolActiveBuilder | ||
.name("sofa_threadpool_active") | ||
.help("sofa_threadpool_active") | ||
.unit(THREADS) | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Gauge buildThreadPoolIdle(String[] labelNames) { | ||
return threadPoolIdleBuilder | ||
.name("sofa_threadpool_idle") | ||
.help("sofa_threadpool_idle") | ||
.unit(THREADS) | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
Gauge buildThreadPoolQueue(String[] labelNames) { | ||
return threadPoolQueueBuilder | ||
.name("sofa_threadpool_queue_size") | ||
.help("sofa_threadpool_queue_size") | ||
.unit(TASKS) | ||
.labelNames(labelNames) | ||
.create(); | ||
} | ||
|
||
public static MetricsBuilder defaultOf() { | ||
return new MetricsBuilder(); | ||
} | ||
|
||
} |
Oops, something went wrong.