# prometheus存储的是时序数据,即按相同时序(相同名称和标签),以时间维度存储连续的数据的集合。
docker pull prom/prometheus
# Grafana全面瓦解 美观、强大的可视化监控指标展示工具
docker pull grafana/grafana
# linux 信息导出
docker pull prom/node-exporter
# redis 信息导出
docker pull oliver006/redis_exporter
docker run -d -p 9100:9100 -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" prom/node-exporter
# 访问url查看收集的信息
http://localhost:9100/metrics
# 创建文件存储配置文件
mkdir /data/prometheus
vim prometheus.yml
vim prometheus.yml
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: linux83
static_configs:
- targets: ['192.168.204.83:9100']
labels:
instance: linux83
# 启动prometheus
# 访问http://localhost:9090
docker run -d -p 9090:9090 -v /data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
查看开启的任务项
# 创建存储地址
mkdir /data/grafana/storage
chmod 777 /data/grafana/storage
# 启动 grafana
docker run -d -p 3000:3000 --name=grafana -v /data/grafana/storage:/var/lib/grafana grafana/grafana
# 访问网页 默认账号密码都是admin
http://localhost:3000/login
添加数据源 点击 Data Sources
选择Prometheus
https://grafana.com/dashboards
linuxl 监控模板 导入node-exporter监控模板,选择import
在网页上查找想要的模板
本地填入模板编号,load
我用的 8919
pom依赖
org.springframework.boot
spring-boot-starter-actuator
io.micrometer
micrometer-registry-prometheus
1.1.3
配置
spring.application.name=SpringBootPrometheus
# 监控端点配置
# 自定义端点路径 将 /actuator/{id}为/manage/{id}
#management.endpoints.web.base-path=/manage
management.endpoints.web.exposure.include=*
management.metrics.tags.application=${spring.application.name}
启动类
@SpringBootApplication
public class FreemarkerApplication {
@Value("${spring.application.name}")
private String application;
public static void main(String[] args) {
SpringApplication.run(FreemarkerApplication.class, args);
}
@Bean
MeterRegistryCustomizer configurer() {
return (registry) -> registry.config().commonTags("application", application);
}
}
访问url 查看获取的信息 http://localhost:8080/actuator/prometheus
修改prometheus 配置,添加springBoot信息。 vim /data/prometheus/prometheus.yml
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['192.168.204.83:9090']
labels:
instance: prometheus
- job_name: linux83
static_configs:
- targets: ['192.168.204.83:9100']
labels:
instance: linux83
- job_name: SpringBoot8080
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['192.168.1.4:8080']
labels:
instance: java8080
重启prometheus
docker restart prom/prometheus
添加监控模板
我用的 11378
数据源
# 拉取镜像
docker pull oliver006/redis_exporter
# 启动容器
docker run -d --name redis_exporter -p 9121:9121 oliver006/redis_exporter -redis.addr 192.168.204.83:6360 -redis.password 123456
# 访问url查看信息 localhost:9121/metrics
获取监控模板 2751