Browse Source

add prometheus

master
刘技 5 years ago
parent
commit
a060979d3d
4 changed files with 60 additions and 0 deletions
  1. 4
      k8s.yaml
  2. 24
      pom.xml
  3. 6
      spring-boot-docker.iml
  4. 26
      src/main/java/com/neo/controller/DockerController.java

4
k8s.yaml

@ -35,6 +35,10 @@ metadata:
namespace: backend
labels:
app: jenkins-backend-demo
annotations:
prometheus.io/scrape: 'true'
#prometheus.io/path: '/metrics'
prometheus.io/port: '30011'
spec:
selector:
app: jenkins-backend-demo

24
pom.xml

@ -34,6 +34,30 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- The client -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.9.0</version>
</dependency>
<!-- Hotspot JVM metrics-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.9.0</version>
</dependency>
<!-- Exposition HTTPServer-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.9.0</version>
</dependency>
<!-- Pushgateway exposition-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
<version>0.9.0</version>
</dependency>
</dependencies>
<build>

6
spring-boot-docker.iml

@ -80,5 +80,11 @@
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.4.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.0.4.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.5.1" level="project" />
<orderEntry type="library" name="Maven: io.prometheus:simpleclient:0.9.0" level="project" />
<orderEntry type="library" name="Maven: io.prometheus:simpleclient_hotspot:0.9.0" level="project" />
<orderEntry type="library" name="Maven: io.prometheus:simpleclient_httpserver:0.9.0" level="project" />
<orderEntry type="library" name="Maven: io.prometheus:simpleclient_common:0.9.0" level="project" />
<orderEntry type="library" name="Maven: io.prometheus:simpleclient_pushgateway:0.9.0" level="project" />
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.3.0" level="project" />
</component>
</module>

26
src/main/java/com/neo/controller/DockerController.java

@ -2,12 +2,38 @@ package com.neo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.prometheus.client.Counter;
@RestController
public class DockerController {
// Counter
// static final Counter requests = Counter.build()
// .name("requests_total").help("Total requests.").register();
static final Counter requests = Counter.build()
.name("my_library_requests_total").help("Total requests.")
.labelNames("method").register();
@RequestMapping("/metrics")
public String indexmetrics() {
// Counter
// requests.inc();
requests.labels("get").inc();
return "Hello metrics! ";
}
@RequestMapping("/")
public String index() {
// Counter
// requests.inc();
requests.labels("get").inc();
return "Hello Docker! ";
}
}
Loading…
Cancel
Save