详细使用情况
node
https://github.com/siimon/prom-client/blob/master/README.md
java
https://github.com/prometheus/client_java/blob/master/README.md
0、spring boot metrics
0.1:pom
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>0.1.0</version>
</dependency>
0、2:java boot class
@SpringBootApplication
@EnableAutoConfiguration
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
public class SendEmailApplication {
public static void main(String[] args) {
SpringApplication.run(SendEmailApplication.class, args);
}
@Bean
public ServletRegistrationBean dispacherRegistration(DispatcherServlet servlet) {
return new ServletRegistrationBean(servlet, "/sendgrid-email/*");
}
}
api open info
不想对外开放这个api,需要配置
1、yml:
management:
security:
enabled: true
context-path: /actuator
security:
user:
name: jack
password: iamflying
2、java
package net.wecash.brazil.datacollect.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.util.StringUtils;
/**
* @author lishulong
* date: 2018/2/7
* desc: 验证拦截
* @version 1.0
*/
@Configuration
@EnableWebSecurity
public class ActuatorSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private Environment environment;
/***
* 对management.context-path的路径进行拦截验证
* @param http
* @throws Exception
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
String contextPath = environment.getProperty("management.context-path");
if (StringUtils.isEmpty(contextPath)) contextPath = "";
http.csrf().disable();
http.authorizeRequests()
.antMatchers("/**" + contextPath + "/**")
.authenticated()
.anyRequest().permitAll()
.and().httpBasic();
// super.configure(http);
}
}
3、就会对/actuator进行验证
request
http://172.25.12.202:1225/sendgrid-email/prometheus
result
# HELP httpsessions_max httpsessions_max
# TYPE httpsessions_max gauge
httpsessions_max -1.0
# HELP httpsessions_active httpsessions_active
# TYPE httpsessions_active gauge
httpsessions_active 0.0
# HELP mem mem
# TYPE mem gauge
mem 379437.0
# HELP mem_free mem_free
# TYPE mem_free gauge
mem_free 134341.0
# HELP processors processors
# TYPE processors gauge
processors 4.0
# HELP instance_uptime instance_uptime
# TYPE instance_uptime gauge
instance_uptime 1272037.0
# HELP uptime uptime
# TYPE uptime gauge
uptime 1276384.0
# HELP systemload_average systemload_average
# TYPE systemload_average gauge
systemload_average 2.65673828125
# HELP heap_committed heap_committed
# TYPE heap_committed gauge
heap_committed 325632.0
# HELP heap_init heap_init
# TYPE heap_init gauge
heap_init 131072.0
# HELP heap_used heap_used
# TYPE heap_used gauge
heap_used 191290.0
# HELP heap heap
# TYPE heap gauge
heap 1864192.0
# HELP nonheap_committed nonheap_committed
# TYPE nonheap_committed gauge
nonheap_committed 55192.0
# HELP nonheap_init nonheap_init
# TYPE nonheap_init gauge
nonheap_init 2496.0
# HELP nonheap_used nonheap_used
# TYPE nonheap_used gauge
nonheap_used 53805.0
# HELP nonheap nonheap
# TYPE nonheap gauge
nonheap 0.0
# HELP threads_peak threads_peak
# TYPE threads_peak gauge
threads_peak 43.0
# HELP threads_daemon threads_daemon
# TYPE threads_daemon gauge
threads_daemon 26.0
# HELP threads_totalStarted threads_totalStarted
# TYPE threads_totalStarted gauge
threads_totalStarted 59.0
# HELP threads threads
# TYPE threads gauge
threads 28.0
# HELP classes classes
# TYPE classes gauge
classes 7911.0
# HELP classes_loaded classes_loaded
# TYPE classes_loaded gauge
classes_loaded 7911.0
# HELP classes_unloaded classes_unloaded
# TYPE classes_unloaded gauge
classes_unloaded 0.0
# HELP gc_ps_scavenge_count gc_ps_scavenge_count
# TYPE gc_ps_scavenge_count gauge
gc_ps_scavenge_count 9.0
# HELP gc_ps_scavenge_time gc_ps_scavenge_time
# TYPE gc_ps_scavenge_time gauge
gc_ps_scavenge_time 119.0
# HELP gc_ps_marksweep_count gc_ps_marksweep_count
# TYPE gc_ps_marksweep_count gauge
gc_ps_marksweep_count 2.0
# HELP gc_ps_marksweep_time gc_ps_marksweep_time
# TYPE gc_ps_marksweep_time gauge
gc_ps_marksweep_time 121.0
# HELP gauge_response_metrics gauge_response_metrics
# TYPE gauge_response_metrics gauge
gauge_response_metrics 59.0
# HELP gauge_response_prometheus gauge_response_prometheus
# TYPE gauge_response_prometheus gauge
gauge_response_prometheus 2.0
# HELP gauge_response_unmapped gauge_response_unmapped
# TYPE gauge_response_unmapped gauge
gauge_response_unmapped 2.0
# HELP gauge_response_star_star gauge_response_star_star
# TYPE gauge_response_star_star gauge
gauge_response_star_star 1.0
# HELP counter_status_200_metrics counter_status_200_metrics
# TYPE counter_status_200_metrics gauge
counter_status_200_metrics 1.0
# HELP counter_status_404_star_star counter_status_404_star_star
# TYPE counter_status_404_star_star gauge
counter_status_404_star_star 16.0
# HELP counter_status_200_prometheus counter_status_200_prometheus
# TYPE counter_status_200_prometheus gauge
counter_status_200_prometheus 68.0
# HELP counter_status_404_unmapped counter_status_404_unmapped
# TYPE counter_status_404_unmapped gauge
counter_status_404_unmapped 8.0
1、docker install prometheus
docker run -d -p 9090:9090 --name prome -v /home/lishulong/conf/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
prometheus 配置文件
root@ubuntu:/home/lishulong/conf# ls
prometheus.yml
root@ubuntu:/home/lishulong/conf# pwd
/home/lishulong/conf
root@ubuntu:/home/lishulong/conf# cat prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'sendgrid-email'
metrics_path: /sendgrid-email/prometheus
static_configs:
- targets: ['172.25.12.202:1225']
root@ubuntu:/home/lishulong/conf#
2、docker install grafana
root@ubuntu:/home/lishulong/conf# docker pull grafana/grafana
Using default tag: latest
latest: Pulling from grafana/grafana
c6b13209f43b: Pull complete
a3ed95caeb02: Pull complete
051738ac6f7e: Pull complete
66e042ba6513: Pull complete
Digest: sha256:f45edaaed369e61a652755c9a8ffbd822daf7b80433b7fb2da49f1d4322cc3d2
Status: Downloaded newer image for grafana/grafana:latest
root@ubuntu:/home/lishulong/conf# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
grafana/grafana latest 5d1d85717268 5 weeks ago 284MB
prom/prometheus latest 67141fa03496 2 months ago 80.2MB
root@ubuntu:/home/lishulong/conf# docker run --name grafana -d -p 3000:3000 grafana/grafana
9a18463687bc675150b053f2b70f0849c5575d1c43a4d6d6a93d950d09d605f4