forked from newrelic/nri-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon_parameters.go
55 lines (47 loc) · 2.5 KB
/
common_parameters.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
package commonparameters
import (
"github.com/newrelic/infra-integrations-sdk/v3/log"
"github.com/newrelic/nri-postgresql/src/args"
)
// The maximum number records that can be fetched in a single metrics
const MaxQueryCountThreshold = 30
// DefaultQueryMonitoringCountThreshold is the default threshold for the number of queries to monitor.
const DefaultQueryMonitoringCountThreshold = 20
// DefaultQueryResponseTimeThreshold is the default threshold for the response time of a query.
const DefaultQueryResponseTimeThreshold = 500
type CommonParameters struct {
Version uint64
Databases string
QueryMonitoringCountThreshold int
QueryMonitoringResponseTimeThreshold int
Host string
Port string
}
func SetCommonParameters(args args.ArgumentList, version uint64, databases string) *CommonParameters {
return &CommonParameters{
Version: version,
Databases: databases, // comma separated database names
QueryMonitoringCountThreshold: validateAndGetQueryMonitoringCountThreshold(args),
QueryMonitoringResponseTimeThreshold: validateAndGetQueryMonitoringResponseTimeThreshold(args),
Host: args.Hostname,
Port: args.Port,
}
}
func validateAndGetQueryMonitoringResponseTimeThreshold(args args.ArgumentList) int {
if args.QueryMonitoringResponseTimeThreshold < 0 {
log.Warn("QueryResponseTimeThreshold should be greater than or equal to 0 but the input is %d, setting value to default which is %d", args.QueryMonitoringResponseTimeThreshold, DefaultQueryResponseTimeThreshold)
return DefaultQueryResponseTimeThreshold
}
return args.QueryMonitoringResponseTimeThreshold
}
func validateAndGetQueryMonitoringCountThreshold(args args.ArgumentList) int {
if args.QueryMonitoringCountThreshold < 0 {
log.Warn("QueryCountThreshold should be greater than 0 but the input is %d, setting value to default which is %d", args.QueryMonitoringCountThreshold, DefaultQueryMonitoringCountThreshold)
return DefaultQueryMonitoringCountThreshold
}
if args.QueryMonitoringCountThreshold > MaxQueryCountThreshold {
log.Warn("QueryCountThreshold should be less than or equal to max limit but the input is %d, setting value to max limit which is %d", args.QueryMonitoringCountThreshold, MaxQueryCountThreshold)
return MaxQueryCountThreshold
}
return args.QueryMonitoringCountThreshold
}