按照以下步骤进行操作:
prometheus
的可执行文件,这是普罗米修斯服务器的主要组件。data
的文件夹。prometheus.yml
的文件,并在其中定义您要监控的目标和指标。请参考普罗米修斯文档以获取更多详细信息和示例配置。# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["10.0.0.219:9090"]
- job_name: 'pushgateway'
static_configs:
- targets: ['10.0.0.219:9091','10.0.0.218:9091']
labels:
instance: pushgateway
# 添加 Node Exporter 监控配置
- job_name: 'node exporter'
static_configs:
- targets: ['10.0.0.219:9100', '192.168.4.241:9100', '192.168.4.240:9100']
#持久化
remote_write:
- url: "http://10.0.0.218:8087/receive"
./prometheus --config.file=prometheus.yml --storage.tsdb.path=data
http://10.0.0.219:9090
来访问普罗米修斯的Web界面。nohup ./pushgateway &
http://localhost:9091
来访问Pushgateway的Web界面。1.下载页面https://grafana.com/grafana/download?pg=get
2.解压
tar -zxvf grafana-enterprise-10.2.3.linux-amd64.tar.gz
3.修改邮箱告警配置文件
/azhangjs/grafana/conf/defaults.ini
[smtp]
enabled = true
host = smtp.sina.com:25
user = zhang_jushun@sina.com
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = 11221222
;cert_file =
;key_file =
;skip_verify = true
from_address = zhang_jushun@sina.com
from_name = Grafana
ehlo_identity =
startTLS_policy =
4.启动命令
nohup ./grafana-server >1.txt &
5.访问 http://10.0.0.58:3000 账号 admin 密码默认 admin
6.配置普罗米修斯数据源
7.下载dashboards模板,导入dashboards
附录:
常用dashboards
https://grafana.com/grafana/dashboards/
来自官方文档: https://prometheus.io/docs/operating/integrations/#remote-endpoints-and-storage
InfluxDB相比其他时序数据库具有以下优势:
总之,InfluxDB在时序数据处理方面具有出色的性能和灵活性,适用于大规模的实时监控、传感器数据、日志数据等应用场景,并且具有丰富的生态系统和集成支持。
按照以下步骤进行操作:
wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.7.5_linux_amd64.tar.gz
tar xvfz influxdb2-2.7.5_linux_amd64.tar.gz
nohup ./influxdb2-2.7.4/usr/bin/influxd >1.txt &
[http://10.0.0.218:8086/](http://10.0.0.218:8086/)
。如果成功打开了管理界面,则说明 InfluxDB 安装成功。按照以下步骤进行操作:
wget https://dl.influxdata.com/telegraf/releases/telegraf-1.29.2_linux_amd64.tar.gz
tar xf telegraf-1.29.2_linux_amd64.tar.gz
telegraf.conf
文件,根据你的需求进行配置。你可以设置数据收集的插件、输出目标、认证方式等等。###############################################################################
# OUTPUT PLUGINS #
###############################################################################
# Configuration for sending metrics to InfluxDB 2.0
# 配置将指标输出到 InfluxDB 2.0
[[outputs.influxdb_v2]]
# 这里的 urls 指向 InfluxDB 的地址,可以是多个
urls = ["http://127.0.0.1:8086"]
# 这里的 Token 为 InfluxDB 中创建的 Token
# 推荐使用环境变量的方式传入,本例为了方便直接把 token 写到配置文件中了
#token = "$INFLUX_TOKEN"
token = "asdfghjkxxxxxxxxxxxxxxxxxxxxxx=="
# InfluxDB 的 organization 名称
organization = "dsg"
# 数据要输出到的 bucket 名称
bucket = "telegraf"
# 配置监听端口和path,使之可以接收数据,这里会应用到Prometheus的配置文件中
[[inputs.http_listener_v2]]
## Address and port to host HTTP listener on
# 监听端口
service_address = ":8087"
## Path to listen to.
# 设置接收数据的path,对应的HTTP地址为 http://ip:8087/receive
path = "/receive"
## Data format to consume.
# 接收从Prometheus中出入过来的格式数据
data_format = "prometheusremotewrite"
# Read metrics from one or many prometheus clients
# 读取 Prometheus 这个服务自身的指标数据(跟 Prometheus 写入数据到 InfluxDB 没有关系)
[[inputs.prometheus]]
## An array of urls to scrape metrics from.
# 采集一下 prometheus 这个服务的指标数据,可以观察是否能正常写入数据到 bucket 中
# 该 url 为本例安装的 Prometheus 服务的指标地址,数组格式可以是多个
urls = ["http://10.0.0.219:9090/metrics"]
# Telegraf 提供了很多 inputs.xxxx 获取服务指标的插件可以直接使用,详见官网
# 以下配置随便获取一些本机数据
[[inputs.cpu]]
percpu = true
totalcpu = true
collect_cpu_time = false
report_active = false
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
[[inputs.diskio]]
fieldpass = ["read_bytes","write_bytes","reads","writes"]
[[inputs.mem]]
fieldpass = ["available","total","available_percent","cached","buffered"]
[[inputs.net]]
interfaces = ["eth*"]
fieldpass = ["bytes_recv","bytes_sent"]
[[inputs.processes]]
interval = "10m"
fielddrop = ["wait","idle","unknown"]
[[inputs.swap]]
# no configuration
[[inputs.system]]
interval = "2m"
fielddrop = ["uptime_format"]
nohup ./telegraf --config ../../etc/telegraf/telegraf.conf &
<!-- The client -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.15.0</version>
</dependency>
<!-- Hotspot JVM metrics-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.15.0</version>
</dependency>
<!-- Exposition HTTPServer-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.15.0</version>
</dependency>
<!-- Pushgateway exposition-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
<version>0.15.0</version>
</dependency>
package com.dsg.push.controller;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.WriteApiBlocking;
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Gauge;
import io.prometheus.client.exporter.PushGateway;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
@RestController
public class MyController {
@GetMapping("/my-endpoint")
public void myEndpoint() throws IOException, InterruptedException {
// 业务逻辑代
CollectorRegistry registry = new CollectorRegistry();
Gauge durationM = Gauge.build().name("azhangjs_cpu_used").help("服务的cpu、内存等使用率指标").labelNames("l").register(registry);
Gauge durationDb = Gauge.build().name("azhangjs_aff_db_connect").help("数据库的最大连接数、当前连接数指标").labelNames("l").register(registry);
// 创建一个Random对象
Random random = new Random();
Boolean flag = true;
while(true) {
try {
//db
int randomInRange3 = random.nextInt(1000) + 1;
int randomInRange4 = random.nextInt(1000) + 1;
durationDb.labels("max_connections").set(randomInRange3);
durationDb.labels("max_used_connections").set(randomInRange4);
float randomInRange1 = random.nextInt(100) + random.nextFloat();
float randomInRange2 = random.nextInt(100) + random.nextFloat();
durationM.labels("192.168.0.100").set(randomInRange1);
durationM.labels("192.168.0.101").set(randomInRange2);
System.out.println("------"+randomInRange3+"------"+randomInRange4+"------"+randomInRange1+"------"+randomInRange2);
} finally {
if(flag) {
PushGateway pg = new PushGateway("10.0.0.219:9091");
//按照instance推送
Map<String, String> insMap = new HashMap<>();
insMap.put("instance", "dsgscheduler219");
pg.pushAdd(registry, "azhangjs_monitor", insMap);
flag = false;
}else {
PushGateway pg = new PushGateway("10.0.0.218:9091");
//按照instance推送
Map<String, String> insMap = new HashMap<>();
insMap.put("instance", "dsgscheduler218");
pg.pushAdd(registry, "azhangjs_monitor", insMap);
flag = true;
}
Thread.sleep(100);
}
}
}
}