资讯动态

Grafana监控可视化

发布时间:2026/8/8 14:53:03 来源:尧图企业网站定制
GrafanaGrafana是一款用开源数据可视化工具可以做数据监控和数据统计用于监控的可视化带有告警功能。Grafana 配置Dashboards(仪表板)可以使用 Prometheus 监控 在Grafana的仪表板上进行可视化。详情见 https://blog.csdn.net/Hu_wen/article/details/136940949Dashboards(仪表板)示例查看Dashboards(仪表板)配置左上角的 DataSource 是数据源 Application 是应用名称。新建Dashboards(仪表板)数据源连好后就可以开始把指标画成图表了。点击左侧菜单栏的Dashboards然后点击右上角的New→\rightarrow→New dashboard。点击Add visualization添加可视化面板。选择数据源在页面左下角或上方选择刚刚配置好的数据源如 Prometheus。编写查询与指标Query在底部的查询编辑框中输入或选择你要监控的指标表达式。例如Prometheus 语法输入 node_cpu_seconds_total 来查看 CPU 使用情况。配置图表样式右侧面板 Panel SettingsPanel title给这个图表起个名字。Visualization选择图表类型。常见的有Time series折线图/时序图最常用、Stat单值大数字适合看当前QPS或总内存、Bar chart柱状图。Unit在右侧Standard options→\rightarrow→Unit中可以把数值单位改成合适的格式如百分比percent(0-100)、字节bytes等。点击右上角的Apply应用图表就会被保存到面板中。Dashboards(仪表板)变量Dashboards(仪表板)配置导入Dashboards(仪表板)可以使用 仪表板配置的 Json Model 进行仪表板配置的 导入直接生成对应的仪表板。{ annotations: { list: [ { builtIn: 1, datasource: { type: grafana, uid: -- Grafana -- }, enable: true, hide: true, iconColor: rgba(0, 211, 255, 1), name: Annotations Alerts, target: { limit: 100, matchAny: false, tags: [], type: dashboard }, type: dashboard } ] }, editable: true, fiscalYearStartMonth: 0, graphTooltip: 0, id: 10027, links: [], liveNow: false, panels: [ { datasource: { type: prometheus, uid: ${datasource} }, fieldConfig: { defaults: { color: { mode: continuous-BlPu }, mappings: [], thresholds: { mode: absolute, steps: [ { color: green, value: null }, { color: red, value: 80 } ] }, unit: none }, overrides: [] }, gridPos: { h: 5, w: 10, x: 0, y: 0 }, id: 11, options: { colorMode: background, graphMode: none, justifyMode: auto, orientation: horizontal, reduceOptions: { calcs: [ lastNotNull ], fields: , values: false }, textMode: value_and_name }, pluginVersion: 9.3.2, targets: [ { datasource: { type: prometheus, uid: ${datasource} }, editorMode: code, expr: sum(http_server_requests_seconds_count), legendFormat: 总请求次数, range: true, refId: A } ], type: stat }, { datasource: { type: prometheus, uid: ${datasource} }, fieldConfig: { defaults: { color: { mode: thresholds }, custom: { align: auto, displayMode: auto, filterable: false, inspect: false, minWidth: 50 }, mappings: [], thresholds: { mode: absolute, steps: [ { color: green, value: null }, { color: #EAB839, value: 10 }, { color: red, value: 80 } ] } }, overrides: [ { matcher: { id: byName, options: Value }, properties: [ { id: custom.displayMode, value: color-background }, { id: displayName, value: 发生次数 } ] } ] }, gridPos: { h: 10, w: 14, x: 10, y: 0 }, id: 9, options: { footer: { enablePagination: false, fields: [], reducer: [ sum ], show: true }, showHeader: true, sortBy: [ { desc: true, displayName: 发生次数 } ] }, pluginVersion: 9.3.2, targets: [ { datasource: { type: prometheus, uid: ${datasource} }, editorMode: code, exemplar: false, expr: sum(http_server_requests_seconds_count{outcome!\SUCCESS\}) by (app, application, uri, status), format: table, instant: true, legendFormat: {{app}}{{application}} - {{uri}} - {{status}}, range: false, refId: A } ], title: 异常请求次数, transformations: [ { id: filterFieldsByName, options: { include: { names: [ app, status, uri, application, Value ] } } } ], type: table }, { datasource: { type: prometheus, uid: ${datasource} }, fieldConfig: { defaults: { mappings: [], thresholds: { mode: absolute, steps: [ { color: green, value: null }, { color: red, value: 80 } ] }, unit: ms }, overrides: [] }, gridPos: { h: 5, w: 5, x: 0, y: 5 }, id: 12, options: { colorMode: background, graphMode: area, justifyMode: auto, orientation: horizontal, reduceOptions: { calcs: [ lastNotNull ], fields: , values: false }, textMode: value_and_name }, pluginVersion: 9.3.2, targets: [ { datasource: { type: prometheus, uid: ${datasource} }, editorMode: code, expr: sum(http_server_requests_seconds_sum{app!xxl-job-admin, uri!~\/getHealth|/metrics\}) / sum(http_server_requests_seconds_count{app!xxl-job-admin, uri!~\/getHealth|/metrics\}), legendFormat: 总平均响应时间, range: true, refId: A } ], type: stat }, { datasource: { type: prometheus, uid: ${datasource} }, fieldConfig: { defaults: { mappings: [], thresholds: { mode: absolute, steps: [ { color: green, value: null }, { color: red, value: 80 } ] }, unit: reqps }, overrides: [] }, gridPos: { h: 5, w: 5, x: 5, y: 5 }, id: 13, options: { colorMode: background, graphMode: area, justifyMode: auto, orientation: horizontal, reduceOptions: { calcs: [ lastNotNull ], fields: , values: false }, textMode: value_and_name }, pluginVersion: 9.3.2, targets: [ { datasource: { type: prometheus, uid: ${datasource} }, editorMode: code, expr: sum(rate(http_server_requests_seconds_count)), legendFormat: 当前并发数, range: true, refId: A } ], type: stat }, { datasource: { type: prometheus, uid: ${datasource} }, fieldConfig: { defaults: { color: { mode: thresholds }, custom: { align: auto, displayMode: auto, inspect: false }, mappings: [], noValue: 0, thresholds: { mode: absolute, steps: [ { color: green, value: null }, { color: red, value: 80 } ] }, unit: none }, overrides: [ { matcher: { id: byName, options: method_name }, properties: [ { id: custom.width, value: 640 } ] }, { matcher: { id: byName, options: 最大值 }, properties: [ { id: unit, value: ms }, { id: thresholds, value: { mode: absolute, steps: [ { color: green, value: null }, { color: #EAB839, value: 50 }, { color: red, value: 80 } ] } }, { id: custom.displayMode, value: color-background } ] } ] }, gridPos: { h: 13, w: 24, x: 0, y: 10 }, id: 5, options: { footer: { enablePagination: false, fields: , reducer: [ sum ], show: false }, showHeader: true, sortBy: [ { desc: true, displayName: 最大值 } ] }, pluginVersion: 9.3.2, targets: [ { datasource: { type: prometheus, uid: ${datasource} }, editorMode: code, exemplar: false, expr: dubbo_method_tp90, format: time_series, instant: false, legendFormat: __auto, range: true, refId: A } ], title: Panel Title, transformations: [ { disabled: true, id: labelsToFields, options: { keepLabels: [ host, namespace, pod ], mode: rows } }, { id: reduce, options: { includeTimeField: false, labelsToFields: true, mode: seriesToRows, reducers: [ last ] } }, { id: organize, options: { excludeByName: { Field: true, __name__: true, env: true, instance: true, job: true, namespace: false, node: true, pod_template_hash: true }, indexByName: { Field: 0, Last: 16, __name__: 1, app: 4, application: 15, buildVersion: 5, env: 6, group: 8, host: 9, instance: 10, job: 11, method_name: 12, namespace: 7, node: 2, pod: 3, pod_template_hash: 13, region: 14 }, renameByName: { Last: 最大值, application: , job: , method_name: 方法名, namespace: } } } ], type: table }, { datasource: { type: prometheus, uid: ${datasource} }, fieldConfig: { defaults: { color: { mode: palette-classic }, custom: { axisCenteredZero: false, axisColorMode: text, axisLabel: , axisPlacement: auto, barAlignment: 0, drawStyle: line, fillOpacity: 0, gradientMode: none, hideFrom: { legend: false, tooltip: false, viz: false }, lineInterpolation: linear, lineWidth: 1, pointSize: 5, scaleDistribution: { type: linear }, showPoints: auto, spanNulls: false, stacking: { group: A, mode: none }, thresholdsStyle: { mode: off } }, mappings: [], thresholds: { mode: absolute, steps: [ { color: green }, { color: red, value: 80 } ] }, unit: reqps }, overrides: [] }, gridPos: { h: 12, w: 24, x: 0, y: 23 }, id: 2, options: { legend: { calcs: [ max ], displayMode: table, placement: right, showLegend: true, sortBy: Max, sortDesc: true }, tooltip: { mode: single, sort: none } }, targets: [ { datasource: { type: prometheus, uid: ${datasource} }, editorMode: code, expr: rate(http_server_requests_seconds_count{outcome!\SUCCESS\}), legendFormat: {{application}}{{app}} - {{uri}}, range: true, refId: A } ], title: 接口平均响应时间, type: timeseries }, { datasource: { type: prometheus, uid: ${datasource} }, fieldConfig: { defaults: { color: { mode: palette-classic }, custom: { axisCenteredZero: false, axisColorMode: text, axisLabel: , axisPlacement: auto, barAlignment: 0, drawStyle: line, fillOpacity: 0, gradientMode: none, hideFrom: { legend: false, tooltip: false, viz: false }, lineInterpolation: linear, lineWidth: 1, pointSize: 5, scaleDistribution: { type: linear }, showPoints: auto, spanNulls: false, stacking: { group: A, mode: none }, thresholdsStyle: { mode: off } }, mappings: [], thresholds: { mode: absolute, steps: [ { color: green }, { color: red, value: 80 } ] }, unit: ms }, overrides: [] }, gridPos: { h: 12, w: 24, x: 0, y: 35 }, id: 7, options: { legend: { calcs: [ max ], displayMode: table, placement: right, showLegend: true, sortBy: Max, sortDesc: true }, tooltip: { mode: single, sort: none } }, targets: [ { datasource: { type: prometheus, uid: ${datasource} }, editorMode: code, expr: sum by (app, application, uri) (http_server_requests_seconds_sum{app!xxl-job-admin, uri!~\/getHealth|/metrics\}) / sum by (app, application, uri) (http_server_requests_seconds_count{app!xxl-job-admin, uri!~\/getHealth|/metrics\}), legendFormat: {{application}}{{app}} - {{uri}}, range: true, refId: A } ], title: 接口平均响应时间, type: timeseries }, { datasource: { type: prometheus, uid: ${datasource} }, fieldConfig: { defaults: { color: { mode: palette-classic }, custom: { axisCenteredZero: false, axisColorMode: text, axisLabel: , axisPlacement: auto, barAlignment: 0, drawStyle: line, fillOpacity: 0, gradientMode: none, hideFrom: { legend: false, tooltip: false, viz: false }, lineInterpolation: linear, lineWidth: 1, pointSize: 5, scaleDistribution: { type: linear }, showPoints: auto, spanNulls: false, stacking: { group: A, mode: none }, thresholdsStyle: { mode: off } }, mappings: [], thresholds: { mode: absolute, steps: [ { color: green }, { color: red, value: 80 } ] }, unit: ms }, overrides: [] }, gridPos: { h: 12, w: 24, x: 0, y: 47 }, id: 3, options: { legend: { calcs: [ max ], displayMode: table, placement: right, showLegend: true, sortBy: Max, sortDesc: true }, tooltip: { mode: single, sort: none } }, targets: [ { datasource: { type: prometheus, uid: ${datasource} }, editorMode: code, expr: max by (app, application, uri) (http_server_requests_seconds_max{app!xxl-job-admin, uri!~\/getHealth|/metrics\}), legendFormat: {{application}}{{app}} - {{uri}}, range: true, refId: A } ], title: 接口最大响应时间, type: timeseries }, { datasource: { type: prometheus, uid: ${datasource} }, fieldConfig: { defaults: { color: { mode: palette-classic }, custom: { axisCenteredZero: false, axisColorMode: text, axisLabel: , axisPlacement: auto, barAlignment: 0, drawStyle: line, fillOpacity: 0, gradientMode: none, hideFrom: { legend: false, tooltip: false, viz: false }, lineInterpolation: linear, lineWidth: 1, pointSize: 5, scaleDistribution: { type: linear }, showPoints: auto, spanNulls: false, stacking: { group: A, mode: none }, thresholdsStyle: { mode: off } }, mappings: [], thresholds: { mode: absolute, steps: [ { color: green }, { color: red, value: 80 } ] }, unit: none }, overrides: [] }, gridPos: { h: 12, w: 24, x: 0, y: 59 }, id: 6, options: { legend: { calcs: [ mean, max, last ], displayMode: table, placement: right, showLegend: true }, tooltip: { mode: single, sort: none } }, targets: [ { datasource: { type: prometheus, uid: ${datasource} }, editorMode: code, expr: sum by (app, application, uri) (rate(http_server_requests_seconds_count{app!xxl-job-admin, uri!~\/getHealth|/metrics\}[1m])), legendFormat: {{application}}{{app}} - {{uri}}, range: true, refId: A } ], title: 接口每秒并发数, type: timeseries } ], schemaVersion: 37, style: dark, tags: [], templating: { list: [ { current: { selected: true, text: Victoriametrics-cntest, value: Victoriametrics-cntest }, hide: 0, includeAll: false, label: DataSource, multi: false, name: datasource, options: [], query: prometheus, queryValue: , refresh: 1, regex: , skipUrlSync: false, type: datasource } ] }, time: { from: now-24h, to: now }, timepicker: {}, timezone: , title: 业务指标, uid: A79GypqHz, version: 5, weekStart: }

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价