您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
hyperf服务监控对接grafana及prometheus
发布时间:2022-11-16 00:37:11编辑:雪饮阅读()
配置data source
configuration=>data source=>Add data source然后选择列表里面的prometheus
然后Http段里面的URL里面就填写我们的prometheus的地址,如:
hyperf接入
step1
这边hyperf用的是2.2.3
安装metric组件
composer require hyperf/metric
生成metric配置(会生成在config/autoload/metric.php)
php bin/hyperf.php vendor:publish hyperf/metric
由于我们前面prometheus以及pushgateway都是使用的默认端口,包括我们grafana都是使用的默认端口,当然最重要的是prometheus使用的是默认端口。
所以接下来只要你redis扩展有安装,swoole扩展有安装(我这里是4.8.12)
step2
那么接下来我们只需要修改下之前promethus新增的那个target的job_name为稍微正规点的名称,那么以hyperf默认创建的skeleton(配置文件config/autoload/metric.php中prometheus配置段中的APP_NAME)
如:
[root@localhost ~]# cat /root/microService/prometheus-2.37.2.linux-amd64/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: ["localhost:9090"]
- job_name: "skeleton"
static_configs:
- targets: ['localhost:9091']
labels:
instance: localhost
step3
配置文件config/autoload/metric.php中prometheus配置段中的mode修改为Constants::PUSH_MODE(这里是演示下以推送模式,默认是抓取模式)
step4
在hyperf官网下载一个grafana.json的一个关于hyperf在grafana上的面板的示例的一个导入文件。
然后在grafana的dashboards=>import中导入该grafana.json
然后进入新的面板后,然后启动hyperf服务开始推送到prometheus
php -c /www/server/php/74/etc/php-cli.ini bin/hyperf.php start
然后稍等片刻, hyperf服务的一个典型的一个系统状态等的监控面板中就有相关数据了。
关键字词:hyperf,对接,grafana,prometheus,服务监控