[小白系列]Ubuntu安装教程-安装prometheus和Grafana

Docker安装prometheus

拉取镜像

docker pull prom/prometheus

配置文件prometheus.yml

在/data/prometheus/建立prometheus.yml配置文件。(/data/prometheus/可根据自己需要调整)

复制代码
global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# 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'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:9090']

启动服务

(/data/prometheus 改为你的目录)

docker run -d --name prometheus --restart always -p 9090:9090 -v /data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

启动时加上--web.enable-lifecycle启用远程热加载配置文件

调用指令是curl -X POST http://localhost:9090/-/reload

访问

http://IP:9090/query

IP改为你服务器的IP地址

Docker安装Grafana

拉取镜像

docker pull grafana/grafana-oss

启动

docker run -d --name=grafana --restart always -p 3000:3000 grafana/grafana-oss

访问

http://IP:3000

默认用户名密码 admin admin 登录提示修改密码

配置DataSource

注意添加Prometheus时可以顺便添加上Dashboards

点击import

Docker安装node-exporter

安装

docker pull prom/node-exporter

docker run -d --name node_exporter --restart always -p 9100:9100 prom/node-exporter

下面不知道干嘛的,暂时记录

docker run -d --name node_exporter --restart always -p 9100:9100 -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" prom/node-exporter

验证

要验证node_exporter是否成功运行,可以访问主机的9100端口,通常可以通过以下URL在浏览器中查看指标数据(假设你的Docker宿主机IP为HOST_IP):

http://HOST_IP:9100 或者 http://HOST_IP:9100/metrics

prometheus配置

在prometheus.yml中再增加一个job

复制代码
 - job_name: 'node_exporter'
    static_configs:
      - targets: ['192.168.60.33:9100']

Grafana配置Node-exporter的Dashboards

dashboars地址: Grafana dashboards | Grafana Labs

找到node exporter full

选择 Copy ID to clipboard

登录grafana

填写ID,然后点击[Load]

注意选择一个配置的promethus数据源

相关推荐
欧先生^_^1 天前
ingress-nginx 开启 Prometheus 监控 + Grafana 查看指标
nginx·grafana·prometheus
Jeremy_Lee1231 天前
grafana 批量视图备份及恢复(含数据源)
前端·网络·grafana
全栈工程师修炼指南1 天前
Grafana 地图本土化方案:使用高德地图API平替GeoMap地图指南
grafana
临水逸1 天前
可视化大屏工具对比:GoView、DataRoom、积木JimuBI、Metabase、DataEase、Apache Superset 与 Grafana
apache·grafana
XMYX-02 天前
Spring Boot + Prometheus 实现应用监控(基于 Actuator 和 Micrometer)
spring boot·后端·prometheus
SailingCoder2 天前
grafana-mcp-analyzer:基于 MCP 的轻量 AI 分析监控图表的运维神器!
运维·人工智能·typescript·node.js·grafana
xbd_zc4 天前
【使用 Loki + Promtail + Grafana 搭建轻量级容器日志分析平台】
grafana·loki·promtail
时间裂缝里的猫-O-4 天前
@Prometheus 监控-MySQL (Mysqld Exporter)
数据库·mysql·prometheus
qq_312920115 天前
K8S上使用helm部署 Prometheus + Grafana
kubernetes·grafana·prometheus
MyikJ7 天前
Java 面试实录:从Spring到微服务的技术探讨
java·spring boot·微服务·kafka·spring security·grafana·prometheus