{"id":20900793,"url":"https://github.com/ulranh/hana_sql_exporter","last_synced_at":"2025-10-28T00:34:17.375Z","repository":{"id":57508137,"uuid":"234756931","full_name":"ulranh/hana_sql_exporter","owner":"ulranh","description":"hana_sql_exporter - SAP Hana SQL Exporter for Prometheus","archived":false,"fork":false,"pushed_at":"2024-02-12T11:02:22.000Z","size":192,"stargazers_count":28,"open_issues_count":4,"forks_count":12,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-01T15:21:43.984Z","etag":null,"topics":["database","exporter","grafana","hana","monitoring","prometheus","sap","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ulranh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-18T15:42:36.000Z","updated_at":"2024-03-11T12:34:49.000Z","dependencies_parsed_at":"2022-09-26T17:51:14.369Z","dependency_job_id":null,"html_url":"https://github.com/ulranh/hana_sql_exporter","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulranh%2Fhana_sql_exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulranh%2Fhana_sql_exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulranh%2Fhana_sql_exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulranh%2Fhana_sql_exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ulranh","download_url":"https://codeload.github.com/ulranh/hana_sql_exporter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253859336,"owners_count":21975081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","exporter","grafana","hana","monitoring","prometheus","sap","sql"],"created_at":"2024-11-18T11:22:51.343Z","updated_at":"2025-10-28T00:34:12.338Z","avatar_url":"https://github.com/ulranh.png","language":"Go","readme":"## SAP Hana SQL Exporter for Prometheus  [![CircleCI](https://circleci.com/gh/ulranh/hana_sql_exporter/tree/master.svg?style=svg)](https://circleci.com/gh/ulranh/hana_sql_exporter) [![Go Report Card](https://goreportcard.com/badge/github.com/ulranh/hana_sql_exporter)](https://goreportcard.com/report/github.com/ulranh/hana_sql_exporter)  [![Docker Pulls](https://img.shields.io/docker/pulls/ulranh/hana-sql-exporter)](https://hub.docker.com/r/ulranh/hana-sql-exporter)\n\nThe purpose of this exporter is to support monitoring SAP and SAP HanaDB  instances with [Prometheus](https://prometheus.io) and [Grafana](https://grafana.com).\n\n## Installation\n\nThe exporter can be downloaded as [released Version](https://github.com/ulranh/hana_sql_exporter/releases/latest). To build the current version you need the [Go](https://golang.org/) programming language:\n\n\n```\n$ git clone git@github.com:ulranh/hana_sql_exporter.git\n$ cd hana_sql_exporter\n$ go build\n```\n## Preparation\n\n#### Database User\nA database user is necessary for every tenant with read access for all affected schemas:\n\n```\n# Login with authorized user:\n$ create user \u003cuser\u003e password \u003cpw\u003e no force_first_password_change;\n$ alter user \u003cuser\u003e disable password lifetime;\n$ grant catalog read to \u003cuser\u003e;\n\n# Login with authorized user:\n$ grant select on schema \u003cschema\u003e to \u003cuser\u003e;\n# \u003cschema\u003e: _SYS_STATISTICS, SAPABAP1, SAPHANADB ... \n```\n\n#### Configfile\nThe next necessary piece is a [toml](https://github.com/toml-lang/toml) configuration file where the encrypted passwords, the tenant- and metric-information are stored. The expected default name is .hana_sql_exporter.toml and the expected default location of this file is the users home directory. The flag --config (-c) can be used to assign other locations or names.\n\nThe file contains a Tenants slice followed by a Metrics Slice:\n\n```\n[[Tenants]]\n  Name = \"q01\"\n  Tags = [\"abap\", \"ewm\"]\n  ConnStr = \"hanaq01.example.com:32041\"\n  User = \"dbuser1\"\n\n[[Tenants]]\n  Name = \"q02\"\n  Tags = [\"abap\", \"erp\"]\n  ConnStr = \"hanaqj1.example.com:31044\"\n  User = \"dbuser2\"\n\n[[Metrics]]\n  Name = \"hdb_backup_status\"\n  Help = \"Status of last hana backup.\"\n  MetricType = \"gauge\"\n  TagFilter = []\n  SchemaFilter = [] # the sys schema will be added automatically\n  SQL = \"select (case when state_name = 'successful' then 0 when state_name = 'running' then 1 else -1 end) as val, entry_type_name as type from \u003cSCHEMA\u003e.m_backup_catalog where entry_id in (select max(entry_id) from m_backup_catalog group by entry_type_name)\"\n\n[[Metrics]]\n  Name = \"hdb_cancelled_jobs\"\n  Help = \"Sap jobs with status cancelled/aborted (today)\"\n  MetricType = \"counter\"\n  TagFilter = [\"abap\"]\n  SchemaFilter = [\"sapabap1\", \"sapabap\",\"sapewm\"]\n  SQL = \"select count(*) from \u003cSCHEMA\u003e.tbtco where enddate=current_utcdate and status='A'\"\n```\n\nBelow is a description of the tenant and metric struct fields:\n\n#### Tenant information\n\n| Field      | Type         | Description | Example |\n| ---------- | ------------ |------------ | ------- |\n| Name       | string       | SAP Hana tenant name | \"P01\", \"q02\" |\n| Tags       | string array | Tags describing the system | [\"abap\", \"erp\"], [\"systemdb\"], [\"java\"] |\n| ConnStr | string       | Connection string \\\u003chostname\\\u003e:\\\u003ctenant sql port\\\u003e - the sql port can be selected in the following way on the system db: \"select database_name,sql_port from sys_databases.m_services\"  | \"host.domain:31041\" | \n| User       | string       | Tenant database user name | |\n\n#### Metric information\n\n| Field        | Type         | Description | Example |\n| ------------ | ------------ |------------ | ------- |\n| Name         | string       | Metric name (words separated by underscore, otherwise a panic can occur)| \"hdb_info\" |\n| Help         | string       | Metric help text | \"Hana database version and uptime\"|\n| MetricType   | string       | Type of metric | \"counter\" or \"gauge\" |\n| TagFilter    | string array | The metric will only be executed, if all values correspond with the existing tenant tags | TagFilter [\"abap\", \"erp\"] needs at least tenant Tags [\"abap\", \"erp\"] otherwise the metric will not be used |\n| SchemaFilter | string array | The metric will only be used, if the tenant user has one of schemas in SchemaFilter assigned. The first matching schema will be replaced with the \u003cSCHEMA\u003e placeholder of the select.  | [\"sapabap1\", \"sapewm\"] |\n| SQL          | string       | The select is responsible for the data retrieval. Conventionally the first column must represent the value of the metric. The following columns are used as labels and must be string values. The tenant name and the tenant usage are default labels for every metric and need not to be added in the select. | \"select days_between(start_time, current_timestamp) as uptime, version from \\\u003cSCHEMA\\\u003e.m_database\" (SCHEMA uppercase) |\n\n#### Database passwords\n\nWith the following commands the passwords for the example tenants above can be written to the Secret section of the configfile:\n```\n$ ./hana_sql_exporter pw --tenant q01 --config ./hana_sql_exporter.toml\n$ ./hana_sql_exporter pw -t qj1 -c ./.hana_sql_exporter.toml\n```\nWith one password for multiple tenants, the following notation is also possible:\n```\n$ ./hana_sql_exporter pw --tenant q01,qj1 --config ./hana_sql_exporter.toml\n```\n\n## Usage\n\nNow the web server can be started:\n#### Binary\n\nThe default port is 9658 which can be changed with the -port flag. The standard timeout is set to 10 seconds, which means that if a scrape for one metric and tenant takes more than 10 seconds, it will be aborted. This is normally only the case, if a tenant is overloaded or the selects are really extensive. In my experience the scrapes for 25 tenants and 30 metrics in one config file take approximately 250ms altogether, if all tenants are responsive. Normally I set the timeout flag to 5 seconds, the scrape timeout for the corresponding Prometheus job to 10 seconds and the scrape intervall to one minute.\n\n```\n$ ./hana_sql_exporter web --config ./hana_sql_exporter.toml --timeout 5\n```\nThen you should be able to find the desired metrics after calling ``localhost:9658/metrics`` in the browser.\n\n#### Docker\nThe Docker image can be downloaded from Docker Hub or built with the Dockerfile. Then it can be started as follows:\n```\n$ docker run -d --name=hana_exporter --restart=always -p 9658:9658 -v /home/\u003cuser\u003e/.hana_sql_exporter.toml:/app/.hana_sql_exporter.toml \u003cimage name\u003e\n```\n#### Kubernetes\nAn example config can be found in the examples folder. First of all create a sap namespace. Then apply the created configfile as configmap and start the deployment:\n```\n$ kubectl apply -f sap-namespace.yaml \n$ kubectl create configmap hana-config -n sap --from-file ./hana_sql_exporter.toml -o yaml\n$ kubectl apply -f hana-deployment.yaml\n```\n\nConfigfile changes can be applied in the following way:\n```\n$ kubectl create configmap hana-config -n sap --from-file ./hana_sql_exporter.toml -o yaml --dry-run | sudo kubectl replace -f -\n$ kubectl scale --replicas=0 -n sap deployment hana-sql-exporter\n$ kubectl scale --replicas=1 -n sap deployment hana-sql-exporter\n```\n#### Prometheus configfile\nThe necessary entries in the prometheus configfile can look something like the following:\n```\n  - job_name: sap\n        scrape_interval: 60s\n        static_configs:\n          - targets: ['172.45.111.105:9658']\n            labels:  {'instance': 'hana-exporter-test'}\n          - targets: ['hana-exporter.sap.svc.cluster.local:9658']\n            labels:  {'instance': 'hana-exporter-dev'}\n```\n\n## Result\nThe resulting information can be found in the Prometheus expression browser and can be used as normal for creating alerts or displaying dashboards in Grafana.\n\nThe image below shows for example the duration of all complete data backups. With one dashboard it is possible to detect hanging or aborted backups of all systems:\n\n ![backups](/examples/images/backups.png)\n\n## More Information\n* [Monitoring SAP and Hana Instances with Prometheus and Grafana](https://blogs.sap.com/2020/02/07/monitoring-sap-and-hana-instances-with-prometheus-and-grafana/) \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fulranh%2Fhana_sql_exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fulranh%2Fhana_sql_exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fulranh%2Fhana_sql_exporter/lists"}