一、前言
关于使用tensuns自带的grafana监控模板,监控redis-exporter接口会有一些数据丢失的问题,需要自行修改一下grafana模板的json
二、修改模板
redis grafana模板id:17507
主要是针对cpu使用率和内存使用率做一个说明,因为我在使用该模板时cpu使用率和内存使用率数据缺失
cpu是因为redis_exporter的数据收集中并没有redis_cpu_util这个数据项,所以显示就自然没有数据可以在prometheus查询该项会发现为空,需要使用node_exporter收集的cpu数据来展示
内存使用率会显示一个无穷大的数据,因为内存使用率是使用redis_exporter收集的redis_memory_used_bytes和redis_memory_max_bytes来计算的,我显示无穷大的原因是在配置redis时并没有给redis配置maxmemory最大内存限制,而redis_memory_max_bytes就是取得maxmemory的数据,所以需要给redis配置maxmemory
以下是我修改以后的json文件
修改cpu%项
"editorMode": "code","exemplar": false,"expr": "redis_cpu_util * on (iid) group_right redis_up{account=~\"$account\",group=~\"$group\"} or label_replace(( 1- avg(rate(node_cpu_seconds_total{mode=\"idle\"}[2m])) by (instance))*100,\"nodehost\",\"$1\",\"instance\",\"(.*):.*\") * on (nodehost) group_left(vendor,account,group,name,region,instance) label_replace(redis_up{account=~\"$account\",group=~\"$group\"},\"nodehost\",\"$1\",\"instance\",\"(.*):.*\")", #更改该项获取数据的配置,改成获取node_exporter监控的cpu参数"format": "table","hide": false,"instant": true,"interval": "","legendFormat": "__auto","refId": "B"},
修改CPU使用率项
"targets": [{"datasource": {"type": "prometheus","uid": "b270c2e2-cc3e-426b-a9ef-80a48217de5f"},"exemplar": true,"expr": "(1 - avg(rate(node_cpu_seconds_total{instance=~\"$node_host:.+\",mode=\"idle\"}[2m])) by (instance))*100", #修改该项为从node_exporter获取cpu监控数据"interval": "2m","legendFormat": "CPU使用率","refId": "A"}
还需要增加一个关于node_host的取值,redis_exporter的grafana模板原本的json是没有node_host
{"current": {"selected": false,"text": "10.1.60.19:6379","value": "10.1.60.19:6379"},"datasource": {"type": "prometheus","uid": "b270c2e2-cc3e-426b-a9ef-80a48217de5f"},"definition": "label_values(redis_up{vendor=~\"$vendor\",account=~\"$account\",group=~\"$group\",name=~\"$name\"}, instance)","hide": 0,"includeAll": false,"multi": false,"name": "instance","options": [],"query": {"query": "label_values(redis_up{vendor=~\"$vendor\",account=~\"$account\",group=~\"$group\",name=~\"$name\"}, instance)","refId": "StandardVariableQuery"},"refresh": 2,"regex": "","skipUrlSync": false,"sort": 1,"tagValuesQuery": "","tagsQuery": "","type": "query","useTags": false}, #在此处插入以下内容{"allFormat": "glob","current": {"selected": false,"text": "10.1.60.19","value": "10.1.60.19"},"datasource": {"type": "prometheus","uid": "b270c2e2-cc3e-426b-a9ef-80a48217de5f"},"definition": "label_values(redis_up{vendor=~\"$vendor\",account=~\"$account\",group=~\"$group\",name=~\"$name\"}, instance)","hide": 2,"includeAll": false,"label": "NodeHost","multi": false,"multiFormat": "regex values","name": "node_host", #取node_host值"options": [],"query": {"query": "label_values(redis_up{vendor=~\"$vendor\",account=~\"$account\",group=~\"$group\",name=~\"$name\"}, instance)","refId": "StandardVariableQuery"},"refresh": 2,"refresh_on_load": false,"regex": "/(.*):.*/","skipUrlSync": false,"sort": 5,"type": "query","useTags": false}, #到此处截止{"current": {"isNone": true,"selected": false,"text": "None","value": ""},"datasource": {"type": "prometheus","uid": "b270c2e2-cc3e-426b-a9ef-80a48217de5f"},"definition": "label_values(redis_up{vendor=~\"$vendor\",account=~\"$account\",group=~\"$group\",name=~\"$name\"}, iid)","hide": 2,"includeAll": false,"multi": false,"name": "iid","options": [],"query": {"query": "label_values(redis_up{vendor=~\"$vendor\",account=~\"$account\",group=~\"$group\",name=~\"$name\"}, iid)","refId": "StandardVariableQuery"},"refresh": 2,"regex": "","skipUrlSync": false,"sort": 1,"tagValuesQuery": "","tagsQuery": "","type": "query","useTags": false}
配置完成后可以查看获取数据的语句是否能正确执行
以上就是使用redis grafana模板时的一些问题