-
Notifications
You must be signed in to change notification settings - Fork 31
/
config.go
69 lines (58 loc) · 1.92 KB
/
config.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
65
66
67
68
69
// Package config stores some common information used in various places.
// The name in hindsight might confuse with the golang package config,
// though there is no relation between the two.
package config
import (
"strings"
"github.com/sjmudd/anonymiser"
"github.com/sjmudd/ps-top/global"
"github.com/sjmudd/ps-top/model/filter"
)
// Config holds the common information
type Config struct {
databaseFilter *filter.DatabaseFilter
status *global.Status
variables *global.Variables
wantRelativeStats bool
}
// NewConfig returns the pointer to a new (empty) config
func NewConfig(status *global.Status, variables *global.Variables, databaseFilter *filter.DatabaseFilter, wantRelativeStats bool) *Config {
return &Config{
databaseFilter: databaseFilter,
status: status,
variables: variables,
wantRelativeStats: wantRelativeStats,
}
}
// DatabaseFilter returns the database filter to apply on queries (if appropriate)
func (c Config) DatabaseFilter() *filter.DatabaseFilter {
return c.databaseFilter
}
// Hostname returns the current short hostname
func (c Config) Hostname() string {
hostname := anonymiser.Anonymise("hostname", c.variables.Get("hostname"))
if index := strings.Index(hostname, "."); index >= 0 {
hostname = hostname[0:index]
}
return hostname
}
// MySQLVersion returns the current MySQL version
func (c Config) MySQLVersion() string {
return c.variables.Get("version")
}
// Uptime returns the time that MySQL has been up (in seconds)
func (c Config) Uptime() int {
return c.status.Get("Uptime")
}
// Variables returns a pointer to global.Variables
func (c Config) Variables() *global.Variables {
return c.variables
}
// SetWantRelativeStats tells what we want to see
func (c *Config) SetWantRelativeStats(w bool) {
c.wantRelativeStats = w
}
// WantRelativeStats tells us what we have asked for
func (c Config) WantRelativeStats() bool {
return c.wantRelativeStats
}