Django之添加prometheus监控
1.首先需要在prometheus.yml配置文件中配置targets:
- job_name: "test-server-191" static_configs: - targets: ["localhost:9100"]
然后重新启动prometheus, 点击查看Status 》Targets
查看Endpoint数据是否正常 UP状态
2.在django项目中,安装依赖包
pip install django-prometheus
3.在配置文件中添加内容settings.py
BASE_INSTALLED_APPS = [ ... "django_prometheus", ] MIDDLEWARE = [ "django_prometheus.middleware.PrometheusBeforeMiddleware", ... "django_prometheus.middleware.PrometheusAfterMiddleware", ]
添加路由配置:
urls.py from django.conf.urls import url url("", include("django_prometheus.urls")),
4.创建grafana面板
点击导入模板,9528