/
prometheus-config.go
99 lines (84 loc) · 3.52 KB
/
prometheus-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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package config
import (
"github.com/Seb369888/smartnode/shared/types/config"
)
// Constants
const prometheusTag string = "prom/prometheus:v2.44.0"
// Defaults
const defaultPrometheusPort uint16 = 9091
const defaultPrometheusOpenPort bool = false
// Configuration for Prometheus
type PrometheusConfig struct {
Title string `yaml:"-"`
// The port to serve metrics on
Port config.Parameter `yaml:"port,omitempty"`
// Toggle for forwarding the API port outside of Docker
OpenPort config.Parameter `yaml:"openPort,omitempty"`
// The Docker Hub tag for Prometheus
ContainerTag config.Parameter `yaml:"containerTag,omitempty"`
// Custom command line flags
AdditionalFlags config.Parameter `yaml:"additionalFlags,omitempty"`
}
// Generates a new Prometheus config
func NewPrometheusConfig(cfg *RocketPoolConfig) *PrometheusConfig {
return &PrometheusConfig{
Title: "Prometheus Settings",
Port: config.Parameter{
ID: "port",
Name: "Prometheus Port",
Description: "The port Prometheus should make its statistics available on.",
Type: config.ParameterType_Uint16,
Default: map[config.Network]interface{}{config.Network_All: defaultPrometheusPort},
AffectsContainers: []config.ContainerID{config.ContainerID_Prometheus},
EnvironmentVariables: []string{"PROMETHEUS_PORT"},
CanBeBlank: true,
OverwriteOnUpgrade: false,
},
OpenPort: config.Parameter{
ID: "openPort",
Name: "Expose Prometheus Port",
Description: "Enable this to expose Prometheus's port to your local network, so other machines can access it too.",
Type: config.ParameterType_Bool,
Default: map[config.Network]interface{}{config.Network_All: defaultPrometheusOpenPort},
AffectsContainers: []config.ContainerID{config.ContainerID_Prometheus},
EnvironmentVariables: []string{"PROMETHEUS_OPEN_PORT"},
CanBeBlank: false,
OverwriteOnUpgrade: false,
},
ContainerTag: config.Parameter{
ID: "containerTag",
Name: "Prometheus Container Tag",
Description: "The tag name of the Prometheus container you want to use on Docker Hub.",
Type: config.ParameterType_String,
Default: map[config.Network]interface{}{config.Network_All: prometheusTag},
AffectsContainers: []config.ContainerID{config.ContainerID_Prometheus},
EnvironmentVariables: []string{"PROMETHEUS_CONTAINER_TAG"},
CanBeBlank: false,
OverwriteOnUpgrade: true,
},
AdditionalFlags: config.Parameter{
ID: "additionalFlags",
Name: "Additional Prometheus Flags",
Description: "Additional custom command line flags you want to pass to Prometheus, to take advantage of other settings that the Smartnode's configuration doesn't cover.",
Type: config.ParameterType_String,
Default: map[config.Network]interface{}{config.Network_All: ""},
AffectsContainers: []config.ContainerID{config.ContainerID_Grafana},
EnvironmentVariables: []string{},
CanBeBlank: true,
OverwriteOnUpgrade: false,
},
}
}
// Get the parameters for this config
func (cfg *PrometheusConfig) GetParameters() []*config.Parameter {
return []*config.Parameter{
&cfg.Port,
&cfg.OpenPort,
&cfg.ContainerTag,
&cfg.AdditionalFlags,
}
}
// The the title for the config
func (cfg *PrometheusConfig) GetConfigTitle() string {
return cfg.Title
}