Prometheus + Grafana
Prometheus
ubuntu安装prometheus非常简单:
apt update
apt install prometheus
systemctl enable prometheus
systemctl enable prometheus-node-exporter
apt安装prometheus和prometheus-node-exporter之后便带有基本配置,无需修改。
确保开启服务开启:
systemctl status prometheus
systemctl status prometheus-node-exporter
顺便使用它监控mongodb,安装prometheus-mongodb-exporter:
apt install prometheus-mongodb-exporter
systemctl enable prometheus-mongodb-exporter
此外由于mongodb开启了密码验证,需要注意mongodb用户的权限:mongodb_exporter github链接

然后需要修改 /etc/default/prometheus-mongodb-exporter 中的 ARGS 如下:
# ARGS='-mongodb.uri="mongodb://localhost:27017"'
ARGS='-mongodb.uri="mongodb://xxx:xxxxx@localhost:27017"'
mongodb URI格式如下:
mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[database][?options]]
如果 username 或 password 包含 @ : / % 四种符号需要使用 百分号编码.
错误添加需要删除时用db.getSiblingDB("admin").dropUser("mongodb_exporter")
然后重启一下服务
systemctl restart prometheus-mongodb-exporter
Grafana
安装:
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
apt update
apt install grafana
配置:
配置文件为 /etc/grafana/grafana.ini,注意如下内容:
...
[server]
domain = www.xxxx.com
enforce_domain = true
root_url = %(protocol)s://%(domain)s/grafana
...
[security]
admin_password = xxxx
然后访问 www.xxxx.com/grafana 登录,用户名admin,密码为上面设置的admin_password。
然后按照 [这里][https://github.com/percona/grafana-dashboards] 配置数据源使用prometheus,并导入面板。一般导入这些即可:

(注意:json中的pmm-singlestat-panel可能需要替换为singlestat)
使用Viewer角色用户登录查看
上述Dashboard配置好之后,不应继续使用admin登录系统。
在设置中“邀请”用户,填写自己的邮箱然后通过邮箱链接设置密码,即可以自己的邮箱登录grafana。


注:
使用prometheus监控两台服务器,配置文件 /etc/prometheus/prometheus.yml 内容如下:
# Sample config for Prometheus.
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
evaluation_interval: 15s # By default, scrape targets every 15 seconds.
# scrape_timeout is set to the global default (10s).
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'example'
# Load and evaluate rules in this file every 'evaluation_interval' seconds.
rule_files:
# - "first.rules"
# - "second.rules"
# 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
scrape_timeout: 5s
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: "web-server"
# If prometheus-node-exporter is installed, grab stats about the local
# machine by default.
static_configs:
- targets: ['localhost:9100']
- job_name: "worker-node1"
static_configs:
- targets: ['192.168.0.5:9100']
这个配置是没问题的,在另一台机器 (192.168.0.5) 上安装并启用 prometheus-node-exporter 即可。
但如果你仅仅修改了某个job_name(而没有修改ip),比如把web-server改为node,那么grafana界面中的singlestat panel将不能正确显示,显示“Only queries that return single...”,
这是因为singlestat只能显示一个结果,而查询语句查到了两个结果。解决方式是删除之前的数据系列:
首先停止prometheus服务,传入
--web.enable-admin-api参数手动运行然后这样删除:
curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]={instance="localhost:9100"}'
参考链接:Prometheus: Delete Time Series Metrcs
注2:上述情况的查询语句可能是这样的(可以在grafana中看到):

(可以用instance="xxxxx"或job="xxxxx")
清理数据参考链接:
https://prometheus.io/docs/prometheus/2.3/querying/api/#delete-series
https://www.alibabacloud.com/help/zh/doc-detail/56246.htm
prometheus 默认是9090端口:

Prometheus + Grafana的更多相关文章
- 使用 Prometheus + Grafana 对 Kubernetes 进行性能监控的实践
1 什么是 Kubernetes? Kubernetes 是 Google 开源的容器集群管理系统,其管理操作包括部署,调度和节点集群间扩展等. 如下图所示为目前 Kubernetes 的架构图,由 ...
- cAdvisor+Prometheus+Grafana监控docker
cAdvisor+Prometheus+Grafana监控docker 一.cAdvisor(需要监控的主机都要安装) 官方地址:https://github.com/google/cadvisor ...
- 基于Docker+Prometheus+Grafana监控SpringBoot健康信息
在微服务体系当中,监控是必不可少的.当系统环境超过指定的阀值以后,需要提醒指定的运维人员或开发人员进行有效的防范,从而降低系统宕机的风险.在CNCF云计算平台中,Prometheus+Grafana是 ...
- prometheus + grafana部署RabbitMQ监控
prometheus + grafana部署RabbitMQ监控 1.grafana导入dashboards https://grafana.com/dashboards/2121 2.expor ...
- Kubernetes+Prometheus+Grafana部署笔记
一.基础概念 1.1 基础概念 Kubernetes(通常写成“k8s”)Kubernetes是Google开源的容器集群管理系统.其设计目标是在主机集群之间提供一个能够自动化部署.可拓展.应用容器可 ...
- [转帖]Prometheus+Grafana监控Kubernetes
原博客的位置: https://blog.csdn.net/shenhonglei1234/article/details/80503353 感谢原作者 这里记录一下自己试验过程中遇到的问题: . 自 ...
- Prometheus+Grafana监控部署实践
参考文档: Prometheus github:https://github.com/prometheus grafana github:https://github.com/grafana/graf ...
- Prometheus+Grafana搭建监控系统
之前在业务中遇到服务器负载过高问题,由于没有监控,一直没发现,直到业务方反馈网站打开速度慢,才发现问题.这样显得开发很被动.所以是时候搭建一套监控系统了. 由于是业余时间自己捯饬,所以神马业务层面的监 ...
- Spring Boot 2.x监控数据可视化(Actuator + Prometheus + Grafana手把手)
TIPS 本文基于Spring Boot 2.1.4,理论支持Spring Boot 2.x所有版本 众所周知,Spring Boot有个子项目Spring Boot Actuator,它为应用提供了 ...
- Prometheus Grafana可视化展示Linux资源使用率
Prometheus Grafana可视化展示Linux资源使用率 Grfana官方仪表盘下载:https://grafana.com/dashboards 数据源推荐:https://grafan ...
随机推荐
- Git的配置与基本操作
Git是一个版本控制软件,它可以让我们能够拍摄处于可行状态的项目的快照,修改项目(如实现新功能)后,如果项目不能正常运行,可以恢复到前一个可行状态. 通过使用版本控制,我们可以无忧无虑的改进项目,不用 ...
- centos 7 网卡绑定 bond0 开机无法自启
https://blog.csdn.net/u012881151/article/details/54910847 1.环境CentOS Linux release 7.2.1511 (Core)li ...
- 虚拟机CentOS7安装docker并搭建Gitlab私服
一.下载安装虚拟机和CentOS7系统 这些流程比较简单不会有什么坑,这里不再阐述 二.安装docker 1.Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验 ...
- CF1182 D Complete Mirror——思路
题目:http://codeforces.com/contest/1182/problem/D 很好的思路是从度数为1的点和直径来入手. 找一条直径.看看直径的两个端点是否合法. 如果都不合法,那么根 ...
- EZOJ #375高速公路
分析 我们可以先跑一遍全价的最短路 之后我们枚举这个第k大的价格w[i] 将其它边减这个边的权值和0取max 在跑出最短路之后加上减去的费用,即w[i]*k 我们发现如果价值大于w[i]的边小于k个 ...
- 凉经-乐糖游戏-PHP开发实习生
收到面试通知当天因为学校出事要求我明天必须回去,所以就买当晚的火车票,然后跟公司说学校有事明天没法去面试了,公司人事比较好给我安排到当天下午面试.公司规模不是很大,但位置好下了地铁到,可能因为招的是实 ...
- python web自动化测试框架搭建(功能&接口)——通用模块
1.通用模块: config.conf: 公共配置文件,配置报告.日志.截图路径,以及邮件相关配置 [report] reportpath = E:\workspace\WebAutomation\s ...
- curl 中关于 CURLINFO_HEADER_SIZE 的 BUG 定位及修复
curl 官方下载页面 CentOS7 默认安装的 curl 版本太低了,需要升级为最新版. 1. 问题描述 对接了一个接口,用来下载 PDF 文件.使用 curl 下载后,文件老是报错无法打开.接口 ...
- 【FICO系列】SAP FICO模块-完工入库后的差异凭证处理
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[FICO系列]SAP FICO模块-完工入库后 ...
- 上海站赛后总结&反思
上海站赛后总结&反思 赛后反思一下,本应该做出3~4题的场,最后只出了2题. 先回顾一下比赛,比赛开始10分钟,队友dy就想出了B题是trie树的模板题,然后让mqy码,第一次交的时候有地方打 ...