-
Notifications
You must be signed in to change notification settings - Fork 3
/
sys_m_license.go
64 lines (51 loc) · 1.81 KB
/
sys_m_license.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Scrape `sys_m_license`.
package collector
import (
"database/sql"
_ "github.com/SAP/go-hdb/driver"
"github.com/prometheus/client_golang/prometheus"
)
const (
// Scrape query.
licenseStatusQuery = `select hardware_key,system_id,product_limit,days_between(TO_SECONDDATE(CURRENT_TIMESTAMP),TO_SECONDDATE(expiration_date)) as expire_days from sys.m_license`
// Subsystem.
licenseStatus = "sys_m_license"
)
// Metric descriptors.
var (
licenseStatusLabels = []string{"hardware_key", "system_id", "product_limit"}
licenseStatusDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, licenseStatus, "expire_days"),
"License expire days from sys.m_service_statistics.",
licenseStatusLabels, nil)
)
// ScrapeserviceStatistics collects from `sys.m_service_statistics`.
type ScrapeLicenseStatus struct{}
// Name of the Scraper. Should be unique.
func (ScrapeLicenseStatus) Name() string {
return licenseStatus
}
// Help describes the role of the Scraper.
func (ScrapeLicenseStatus) Help() string {
return "Collect info from sys.m_service_statistics"
}
// Scrape collects data from database connection and sends it over channel as prometheus metric.
func (ScrapeLicenseStatus) Scrape(db *sql.DB, ch chan<- prometheus.Metric) error {
licenseStatusRows, err := db.Query(licenseStatusQuery)
if err != nil {
return err
}
defer licenseStatusRows.Close()
var hardware_key string
var system_id string
var product_limit string
var expire_days float64
for licenseStatusRows.Next() {
if err := licenseStatusRows.Scan(&hardware_key, &system_id, &product_limit, &expire_days); err != nil {
return err
}
licenseStatusLabelValues := []string{hardware_key, system_id, product_limit}
ch <- prometheus.MustNewConstMetric(licenseStatusDesc, prometheus.GaugeValue, expire_days, licenseStatusLabelValues...)
}
return nil
}