【一键部署】使用Prometheus 监控 SQLServer数据库 简单易懂 Docker部署

先上效果图,DIY模板代码在最后,自取

安装SQLServer监控客户端,使用Docker的方式

注意客户端可以不一定需要安装在数据库服务器上,因为数据库服务器不一定有Docker服务,可以安装任何能与数据库、Prometheus服务器通信的服务器上即可

sudo docker run -d -e SERVER=数据库IP地址 -e USERNAME=数据库用户名 -e PASSWORD=数据库密码 -e DEBUG=app -p 4000:4000 --name prometheus-mssql-

exporter awaragi/prometheus-mssql-exporter

我们数据库的用户名可以使用sa用户,但是我们出于安全考虑,也可以专门创建一个给Prometheus使用的用户

创建Prometheus专用user的语句 ,如果用sa用户就不用创建

#创建用户名为prometheus,密码为Cal7dp5q0v1,默认库为master的用户

CREATE LOGIN prometheus WITH PASSWORD = 'Cal7dp5q0v1', DEFAULT_DATABASE = master;

#进入master库,并创建登录名、创建数据库用户、以及为用户授予权限

USE master;

GO

CREATE USER prometheus FOR LOGIN prometheus WITH DEFAULT_SCHEMA = dbo;

GRANT VIEW ANY DEFINITION TO prometheus;

GRANT VIEW SERVER STATE TO prometheus;

 此时我们就可以用我们创建的用户,安装SQLServer监控客户端

sudo docker run -d -e SERVER=192.168.0.110  -e USERNAME=prometheus -e PASSWORD=Cal7dp5q0v1 -e DEBUG=app -p 4001:4000 --name mssql-1 awaragi/prometheus-mssql-exporter

 剩下的在Prometheus服务器端进行配置

首先是/etc/prometheus/prometheus.yml配置文件,我们通过文件去动态加载需要监控的数据库服务器和标签🏷,⚠️注意修改prometheus.yml配置文件需要热加载或者重启服务来加载配置

 - job_name: 'SQLserver'
    scrape_interval: 5m
    file_sd_configs:
      - files: ['/etc/prometheus/conf/sqlserver.yml']
        refresh_interval: 10m

 查看/etc/prometheus/conf/sqlserver.yml

这个sqlserver.yml文件不需要重启Prometheus,添加即可热加载

- targets: 
  - "192.168.0.2:4000"
  labels:  
    hostname: "192.168.0.110"
    nodename: "OA数据库"
    systemname: "OA系统"

进入Prometheus查看即可 

因为存在自定义的情况,所以以下内容可以复制并保存为josn文件,然后导入Grafana仪表盘即可使用,如有问题可以留言

{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "__elements": {},
  "__requires": [
    {
      "type": "panel",
      "id": "gauge",
      "name": "Gauge",
      "version": ""
    },
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "10.2.0"
    },
    {
      "type": "panel",
      "id": "graph",
      "name": "Graph (old)",
      "version": ""
    },
    {
      "type": "datasource",
      "id": "prometheus",
      "name": "Prometheus",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "stat",
      "name": "Stat",
      "version": ""
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": ""
    },
    {
      "type": "panel",
      "id": "timeseries",
      "name": "Time series",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "datasource",
          "uid": "grafana"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "description": "Works with and awaragi/prometheus-mssql-exporter",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "gnetId": 13919,
  "graphTooltip": 0,
  "id": null,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_PROMETHEUS}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "max": 1,
          "min": 1,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 4,
        "x": 0,
        "y": 0
      },
      "id": 91,
      "options": {
        "minVizHeight": 75,
        "minVizWidth": 75,
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "pluginVersion": "10.2.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "editorMode": "code",
          "expr": "count(up{job=\"$Job\"})",
          "instant": false,
          "legendFormat": "__auto",
          "range": true,
          "refId": "A"
        }
      ],
      "title": "$Job服务器总数量",
      "type": "gauge"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_PROMETHEUS}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "max": 1,
          "min": 1,
          "noValue": "0",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 1
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 4,
        "x": 4,
        "y": 0
      },
      "id": 94,
      "options": {
        "minVizHeight": 75,
        "minVizWidth": 75,
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "pluginVersion": "10.2.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "editorMode": "code",
          "expr": "count(up{job=\"$Job\"}!=1)",
          "instant": false,
          "legendFormat": "__auto",
          "range": true,
          "refId": "A"
        }
      ],
      "title": "$Job服务器离线数量",
      "type": "gauge"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_PROMETHEUS}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "max": 1,
          "min": 1,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 4,
        "x": 8,
        "y": 0
      },
      "id": 92,
      "options": {
        "minVizHeight": 75,
        "minVizWidth": 75,
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "pluginVersion": "10.2.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "editorMode": "code",
          "expr": "count(mssql_database_state{job=\"$Job\"})",
          "instant": false,
          "legendFormat": "__auto",
          "range": true,
          "refId": "A"
        }
      ],
      "title": "$Job数据库总数量",
      "type": "gauge"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_PROMETHEUS}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "max": 1,
          "min": 1,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 1
              }
            ]
          },
          "unit": "none"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 4,
        "x": 12,
        "y": 0
      },
      "id": 95,
      "options": {
        "minVizHeight": 75,
        "minVizWidth": 75,
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "pluginVersion": "10.2.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "editorMode": "code",
          "expr": "count(mssql_database_state{job=\"$Job\"}!=0)",
          "instant": false,
          "legendFormat": "__auto",
          "range": true,
          "refId": "A"
        }
      ],
      "title": "$Job异常数据库",
      "type": "gauge"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_PROMETHEUS}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [
            {
              "options": {
                "0": {
                  "index": 0,
                  "text": "正常"
                },
                "1": {
                  "index": 1,
                  "text": "还原中"
                },
                "2": {
                  "index": 2,
                  "text": "恢复中"
                },
                "3": {
                  "index": 3,
                  "text": "等待恢复"
                },
                "4": {
                  "index": 4,
                  "text": "可疑"
                },
                "5": {
                  "index": 5,
                  "text": "紧急情况"
                },
                "6": {
                  "index": 6,
                  "text": "脱机"
                },
                "7": {
                  "index": 7,
                  "text": "拷贝中"
                },
                "10": {
                  "index": 8,
                  "text": "等待脱机"
                }
              },
              "type": "value"
            }
          ],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "red",
                "value": null
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 8,
        "x": 16,
        "y": 0
      },
      "id": 93,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "value_and_name"
      },
      "pluginVersion": "10.2.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "mssql_database_state!=0",
          "format": "time_series",
          "instant": false,
          "interval": "",
          "legendFormat": "{{nodename}}{{database}}",
          "range": true,
          "refId": "A"
        }
      ],
      "title": "异常数据库状态",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_PROMETHEUS}"
      },
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "center",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          },
          "decimals": 0,
          "displayName": "",
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "short"
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Value #LT"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "Server local time"
              },
              {
                "id": "unit",
                "value": "Date & time"
              },
              {
                "id": "decimals",
                "value": 2
              },
              {
                "id": "unit",
                "value": "time: YYYY-MM-DD HH:mm:ss"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #TM"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "物理内存"
              },
              {
                "id": "unit",
                "value": "kbytes"
              },
              {
                "id": "decimals",
                "value": 0
              },
              {
                "id": "custom.align",
                "value": "auto"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #TPF"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "page faults数量"
              },
              {
                "id": "unit",
                "value": "string"
              },
              {
                "id": "decimals",
                "value": 2
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #TM"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "物理内存"
              },
              {
                "id": "unit",
                "value": "kbytes"
              },
              {
                "id": "decimals",
                "value": 0
              },
              {
                "id": "custom.align",
                "value": "center"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #PF"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "Pagefile总空间"
              },
              {
                "id": "unit",
                "value": "kbytes"
              },
              {
                "id": "custom.align"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #APF"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "Pagefile可用空间"
              },
              {
                "id": "unit",
                "value": "kbytes"
              },
              {
                "id": "custom.align"
              },
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "rgba(245, 54, 54, 0.9)",
                      "value": null
                    },
                    {
                      "color": "rgba(237, 129, 40, 0.89)",
                      "value": 259200
                    },
                    {
                      "color": "rgba(50, 172, 45, 0.97)",
                      "value": 432000
                    }
                  ]
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #RA"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "可用内存"
              },
              {
                "id": "unit",
                "value": "kbytes"
              },
              {
                "id": "decimals",
                "value": 2
              },
              {
                "id": "custom.cellOptions",
                "value": {
                  "type": "color-background"
                }
              },
              {
                "id": "custom.align"
              },
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "rgba(245, 54, 54, 0.9)",
                      "value": null
                    },
                    {
                      "color": "rgba(237, 129, 40, 0.89)",
                      "value": 104856
                    },
                    {
                      "color": "green",
                      "value": 314571.9999
                    }
                  ]
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #BR"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "每秒批处理请求数"
              },
              {
                "id": "unit",
                "value": "short"
              },
              {
                "id": "decimals",
                "value": 2
              },
              {
                "id": "custom.align"
              },
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "rgba(50, 172, 45, 0.97)",
                      "value": null
                    },
                    {
                      "color": "rgba(237, 129, 40, 0.89)",
                      "value": 60
                    },
                    {
                      "color": "rgba(245, 54, 54, 0.9)",
                      "value": 80
                    }
                  ]
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #PLE"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "页平均寿命 (sec)"
              },
              {
                "id": "unit",
                "value": "dtdurations"
              },
              {
                "id": "custom.cellOptions",
                "value": {
                  "type": "color-background"
                }
              },
              {
                "id": "custom.align"
              },
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "rgba(245, 54, 54, 0.9)",
                      "value": null
                    },
                    {
                      "color": "rgba(237, 129, 40, 0.89)",
                      "value": 300
                    },
                    {
                      "color": "green",
                      "value": 600
                    }
                  ]
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #DL"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "死锁"
              },
              {
                "id": "unit",
                "value": "none"
              },
              {
                "id": "custom.cellOptions",
                "value": {
                  "type": "color-background"
                }
              },
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "green",
                      "value": null
                    },
                    {
                      "color": "rgba(237, 129, 40, 0.89)",
                      "value": 1
                    },
                    {
                      "color": "rgba(245, 54, 54, 0.9)",
                      "value": 10
                    }
                  ]
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #UE"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "事务错误/秒"
              },
              {
                "id": "unit",
                "value": "none"
              },
              {
                "id": "decimals"
              },
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "green",
                      "value": null
                    }
                  ]
                }
              },
              {
                "id": "custom.cellOptions",
                "value": {
                  "type": "color-background"
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #KC"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "杀死错误连接数/秒"
              },
              {
                "id": "unit",
                "value": "none"
              },
              {
                "id": "decimals"
              },
              {
                "id": "custom.cellOptions",
                "value": {
                  "type": "color-background"
                }
              },
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "green",
                      "value": null
                    },
                    {
                      "color": "rgba(237, 129, 40, 0.89)",
                      "value": 1
                    },
                    {
                      "color": "rgba(245, 54, 54, 0.9)",
                      "value": 10
                    }
                  ]
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #DBC"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "Total databases"
              },
              {
                "id": "unit",
                "value": "short"
              },
              {
                "id": "decimals",
                "value": 2
              },
              {
                "id": "custom.align"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #A"
            },
            "properties": [
              {
                "id": "unit",
                "value": "percentunit"
              },
              {
                "id": "decimals",
                "value": 0
              },
              {
                "id": "custom.cellOptions",
                "value": {
                  "type": "color-background"
                }
              },
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "green",
                      "value": null
                    },
                    {
                      "color": "yellow",
                      "value": 0.8
                    },
                    {
                      "color": "red",
                      "value": 0.9
                    }
                  ]
                }
              },
              {
                "id": "displayName",
                "value": "内存使用率"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "系统名称"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 94
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "服务器名称"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 155
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "IP地址"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 123
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "物理内存"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 90
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "内存使用率"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 92
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "可用内存"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 98
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Total pagefile size"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 143
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Pagefile 可用空间"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 133
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Total page faults"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 130
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Batch reqs / sec"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 132
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Page life expectancy (sec)"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 199
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Deadlocks"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 106
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "User errors / sec"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 149
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Pagefile总空间"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 121
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Pagefile可用空间"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 133
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "page faults数量"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 129
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "每秒批处理请求数"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 135
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "死锁"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 116
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 6
      },
      "id": 45,
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true,
        "sortBy": []
      },
      "pluginVersion": "10.2.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "expr": "mssql_instance_local_time{job=~\"$Job\"}*1000",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "refId": "LT"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "editorMode": "code",
          "expr": "mssql_total_physical_memory_kb{job=~\"$Job\"}-0",
          "format": "table",
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "refId": "TM"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "editorMode": "code",
          "expr": "mssql_available_physical_memory_kb{job=~\"$Job\"}-0",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "{{label_name}}",
          "refId": "RA"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "expr": "mssql_total_page_file_kb{job=~\"$Job\"}-0",
          "format": "table",
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "refId": "PF"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "expr": "mssql_available_page_file_kb{job=~\"$Job\"}-0",
          "format": "table",
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "refId": "APF"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "expr": "mssql_page_fault_count{job=~\"$Job\"}-0",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "Total page faults",
          "refId": "TPF"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "expr": "mssql_batch_requests{job=~\"$Job\"}-0",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "refId": "BR"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "expr": "mssql_page_life_expectancy{job=~\"$Job\"}-0",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "refId": "PLE"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "expr": "mssql_deadlocks{job=~\"$Job\"}-0",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "refId": "DL"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "expr": "mssql_user_errors{job=~\"$Job\"}-0",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "refId": "UE"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "expr": "mssql_kill_connection_errors{job=~\"$Job\"}-0",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "refId": "KC"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "expr": "sum(mssql_database_state{job=~\"$Job\"})",
          "format": "table",
          "hide": true,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "refId": "DBC"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "editorMode": "code",
          "expr": "(mssql_total_physical_memory_kb{job=~\"$Job\"}-mssql_available_physical_memory_kb{job=~\"$Job\"})/mssql_total_physical_memory_kb{job=~\"$Job\"}-0",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "{{label_name}}",
          "refId": "A"
        }
      ],
      "title": "$Job:资源概述",
      "transformations": [
        {
          "id": "merge",
          "options": {
            "reducers": []
          }
        },
        {
          "id": "filterFieldsByName",
          "options": {
            "include": {}
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {
              "Time": true,
              "Value #LT": true,
              "instance": true,
              "job": true
            },
            "indexByName": {
              "Time": 1,
              "Value #A": 8,
              "Value #APF": 11,
              "Value #BR": 13,
              "Value #DL": 15,
              "Value #KC": 17,
              "Value #LT": 6,
              "Value #PF": 10,
              "Value #PLE": 14,
              "Value #RA": 9,
              "Value #TM": 7,
              "Value #TPF": 12,
              "Value #UE": 16,
              "hostname": 3,
              "instance": 4,
              "job": 5,
              "nodename": 2,
              "systemname": 0
            },
            "renameByName": {
              "Value #LT": "",
              "Value #PF": "",
              "Value #RA": "",
              "Value #TM": "",
              "hostname": "IP地址",
              "instance": "",
              "nodename": "服务器名称",
              "systemname": "系统名称"
            }
          }
        }
      ],
      "type": "table"
    },
    {
      "collapsed": false,
      "datasource": {
        "type": "prometheus",
        "uid": "c4687b94-89db-475b-8bd4-c328f38d7315"
      },
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 14
      },
      "id": 4,
      "panels": [],
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "c4687b94-89db-475b-8bd4-c328f38d7315"
          },
          "refId": "A"
        }
      ],
      "title": "$database-数据库详情",
      "type": "row"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_PROMETHEUS}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisBorderShow": false,
            "axisCenteredZero": false,
            "axisColorMode": "text",
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "insertNulls": false,
            "lineInterpolation": "smooth",
            "lineWidth": 2,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "min": -1,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 11,
        "w": 24,
        "x": 0,
        "y": 15
      },
      "id": 90,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "table",
          "placement": "right",
          "showLegend": true,
          "sortBy": "Name",
          "sortDesc": true
        },
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "editorMode": "code",
          "expr": "mssql_connections{job=\"$Job\",database=~\"$database\"}",
          "instant": false,
          "legendFormat": "{{nodename}}-{{database}}",
          "range": true,
          "refId": "A"
        }
      ],
      "title": "数据库连接情况",
      "type": "timeseries"
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_PROMETHEUS}"
      },
      "fill": 1,
      "fillGradient": 4,
      "gridPos": {
        "h": 11,
        "w": 24,
        "x": 0,
        "y": 26
      },
      "hiddenSeries": false,
      "id": 8,
      "legend": {
        "alignAsTable": true,
        "avg": false,
        "current": true,
        "max": false,
        "min": false,
        "rightSide": true,
        "show": true,
        "total": false,
        "values": true
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "null",
      "options": {
        "alertThreshold": true
      },
      "percentage": false,
      "pluginVersion": "10.2.0",
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "expr": "mssql_log_growths",
          "interval": "",
          "legendFormat": "{{database}}",
          "refId": "A"
        }
      ],
      "thresholds": [],
      "timeRegions": [],
      "title": "DB Log growth since last restart",
      "tooltip": {
        "shared": true,
        "sort": 2,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "mode": "time",
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "$$hashKey": "object:584",
          "format": "short",
          "logBase": 1,
          "show": true
        },
        {
          "$$hashKey": "object:585",
          "format": "short",
          "logBase": 1,
          "show": true
        }
      ],
      "yaxis": {
        "align": false
      }
    }
  ],
  "refresh": "",
  "schemaVersion": 38,
  "tags": [],
  "templating": {
    "list": [
      {
        "current": {},
        "datasource": {
          "type": "prometheus",
          "uid": "${DS_PROMETHEUS}"
        },
        "definition": "label_values(mssql_instance_local_time, job)",
        "hide": 0,
        "includeAll": false,
        "multi": false,
        "name": "Job",
        "options": [],
        "query": {
          "query": "label_values(mssql_instance_local_time, job)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "current": {},
        "datasource": {
          "type": "prometheus",
          "uid": "${DS_PROMETHEUS}"
        },
        "definition": "label_values(mssql_connections,database)",
        "hide": 0,
        "includeAll": true,
        "multi": false,
        "name": "database",
        "options": [],
        "query": {
          "query": "label_values(mssql_connections,database)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      }
    ]
  },
  "time": {
    "from": "now-1h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "数据库-SQL Server",
  "uid": "9J6ObCEMz",
  "version": 21,
  "weekStart": ""
}

  • 18
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Prometheus监控 SQL Server,需要安装 SQL Server Exporter。SQL Server Exporter 是一个开源工具,它可以定期查询 SQL Server 并将指标导出到 Prometheus 中。以下是一些步骤: 1. 下载 SQL Server Exporter 可以从 GitHub 上下载 SQL Server Exporter 的二进制文件。下载后,解压缩文件并将可执行文件复制到所需的位置。 2. 配置 SQL Server Exporter 在 SQL Server Exporter 的配置文件中,您需要指定 SQL Server 实例的连接字符串和要导出的指标列表。例如,以下是一个配置文件示例: ``` --- global: scrape_interval: 15s evaluation_interval: 15s scrape_configs: - job_name: 'sqlserver' static_configs: - targets: ['localhost:9119'] params: query: ['select * from sys.dm_os_performance_counters'] ``` 3. 启动 SQL Server Exporter 使用以下命令启动 SQL Server Exporter: ``` sql_exporter.exe <config-file> ``` 4. 配置 PrometheusPrometheus 的配置文件中,您需要添加一个作业来抓取 SQL Server Exporter 导出的指标。例如,以下是一个配置文件示例: ``` scrape_configs: - job_name: 'sqlserver' static_configs: - targets: ['localhost:9119'] ``` 5. 启动 Prometheus 使用以下命令启动 Prometheus: ``` prometheus.exe --config.file=<config-file> ``` 6. 查看指标 访问 Prometheus 的 Web 界面并导航到“Graph”选项卡。在“Metrics”输入框中输入您想要查看的指标名称。您应该能够看到 SQL Server Exporter 导出的指标并可以使用 Prometheus 查询语言来查询它们。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值