Skip to content

Add custom metrics to expose MSSQL server hostname #379

Description

@barywhyte

I am not sure weather I should call this improvement suggestion or weather this is by design. I am adding the following custom metrics to mssql_standard.collector.yml file. While other custom metrics such as mssql_last_elapsed_time etc are working well, I can't seem to be able to add the following metric to expose database hostname. Below was my first attempt:

- metric_name: mssql_hostname
  type: gauge
  help: 'Database server hostname'
  key_labels:
    - hostname
  query: |
    SELECT @@SERVERNAME AS hostname

Which produced error as it cannot convert string hostname to numeric gauge. Then, I tried other variations and the last that nearly worked was:

- metric_name: mssql_hostname
    type: gauge
    help: 'Database server hostname'
    key_labels:
      - hostname
    values:
      - 1
    query: |
      SELECT @@SERVERNAME AS hostname

Which produced error:
Error gathering metrics: [from Gatherer #1] [, collector="mssql_standard", query="mssql_hostname"] column(s) ["1"] missing from query result

I used 1 as a placeholder value, hoping that I can retrieve the hostname by whatever means using PromQL.

I am wondering if there is another way to expose servername/hostname on which MSSQL runs to Prometheus. I am unable to find MSSQL metrics that exposes hostname as part of its label or other attributes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions