Skip to content

Commit f73ae07

Browse files
committed
added basic auth and tls support
Signed-off-by: GitMeder <moeder@t-online.de>
1 parent ffe5615 commit f73ae07

2 files changed

Lines changed: 78 additions & 16 deletions

File tree

config-local/config.yaml

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
# Example Kepler configuration for "Prometheus-based node power input"
2-
# Use this when an external system (e.g., PDU + exporter + recording rules)
3-
# already provides a power metric (watts), and Kepler should attribute it to processes.
1+
# Example Kepler configuration for "Prometheus-based node power input".
2+
#
3+
# Use this when an external monitoring system (for example:
4+
# PDU + exporter + recording rules in Prometheus / VictoriaMetrics)
5+
# already provides a power metric in watts, and Kepler should
6+
# attribute that node-level power to processes.
7+
#
8+
# This example also demonstrates how to enable HTTPS / TLS and
9+
# Basic Authentication for the Kepler HTTP server via exporter-toolkit.
10+
#
11+
# Note:
12+
# - TLS and Basic Auth are configured via web.configFile
13+
# - The referenced web-config file is not part of this YAML and must be
14+
# created separately by the operator
15+
# - Replace the example baseURL and query with environment-specific values
416

517
log:
6-
level: info # debug, info, warn, error
7-
format: text # text or json
18+
level: info
19+
format: text
820

921
host:
1022
sysfs: /sys
1123
procfs: /proc
1224

1325
monitor:
1426
interval: 5s
15-
staleness: 30s # how long samples may be considered valid
27+
staleness: 30s
1628

1729
exporter:
1830
prometheus:
@@ -25,8 +37,28 @@ exporter:
2537
# - pod
2638

2739
web:
40+
# Kepler may listen on multiple addresses / ports.
41+
# In this example:
42+
# - 28282 can be used for plain HTTP if desired
43+
# - 28443 is intended for HTTPS when configured via web.configFile
2844
listenAddresses:
29-
- :28282
45+
- 0.0.0.0:28282
46+
- :28443
47+
48+
# Path to the exporter-toolkit web configuration file.
49+
# This file can enable:
50+
# - TLS / HTTPS
51+
# - Basic Authentication
52+
#
53+
# Example contents:
54+
#
55+
# tls_server_config:
56+
# cert_file: /etc/kepler/tls/server.crt
57+
# key_file: /etc/kepler/tls/server.key
58+
#
59+
# basic_auth_users:
60+
# kepleruser: "<bcrypt-hash>"
61+
configFile: /etc/kepler/web-config.yml
3062

3163
kube:
3264
enabled: false
@@ -39,24 +71,37 @@ dev:
3971

4072
# Disable RAPL zones in this example, because node power comes from Prometheus.
4173
rapl:
74+
enabled: false
4275
zones: []
4376

4477
experimental:
45-
# Prometheus/VictoriaMetrics based power input.
46-
# Kepler queries an external Prometheus-compatible API endpoint for a single power time series (watts).
4778
prometheus-power:
4879
enabled: true
49-
baseURL: http://<PROMETHEUS_OR_VICTORIAMETRICS_HOST>:8428
50-
# The query must return exactly one time series (one sample).
51-
# Example: device_power_watts_avg{rack="R3.033",device="kub01"}
52-
query: <PROMQL_QUERY_RETURNING_SINGLE_WATTS_SERIES>
80+
81+
# Replace with your monitoring endpoint.
82+
#
83+
# Example:
84+
# https://monitoring.example.org:8428
85+
#
86+
# If authentication is required by the monitoring backend,
87+
# credentials must be provided according to the deployment model.
88+
# For local testing, credentials may be embedded in the URL,
89+
# but in production a more secure mechanism is recommended.
90+
baseURL: https://monitoring.example.org:8428
91+
92+
# Replace with an environment-specific query that returns
93+
# the node power in watts for the current machine / target.
94+
#
95+
# Example:
96+
# node_power_watts{instance="server01"}
97+
query: node_power_watts{instance="example-node"}
5398

5499
platform:
55100
redfish:
56101
enabled: false
57102

58103
hwmon:
59104
enabled: false
60-
105+
61106
gpu:
62107
enabled: false

internal/server/server.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ type APIServer struct {
2525
// input
2626
logger *slog.Logger
2727
listenAddrs []string
28+
webCfgPath string
2829

2930
// http
3031
server *http.Server
3132
mux *http.ServeMux
3233
endpointDescription string
33-
webCfgPath string
3434
}
3535

3636
var _ APIService = (*APIServer)(nil)
@@ -58,6 +58,13 @@ func WithListenAddress(addr []string) OptionFn {
5858
}
5959
}
6060

61+
// WithWebConfig sets the path to the exporter-toolkit web configuration file.
62+
//
63+
// The web config can be used to enable features such as:
64+
// - TLS / HTTPS
65+
// - Basic Authentication
66+
//
67+
// See: https://github.com/prometheus/exporter-toolkit
6168
func WithWebConfig(path string) OptionFn {
6269
return func(o *Opts) {
6370
o.webCfgPath = path
@@ -133,6 +140,10 @@ func (s *APIServer) Init() error {
133140
return nil
134141
}
135142

143+
// Run starts the HTTP server.
144+
//
145+
// If webCfgPath is set, exporter-toolkit will be used to apply web server
146+
// settings from the referenced file, including optional TLS and Basic Auth.
136147
func (s *APIServer) Run(ctx context.Context) error {
137148
s.logger.Info("Running HTTP server", "listening-on", s.listenAddrs)
138149
errCh := make(chan error)
@@ -167,6 +178,12 @@ func (s *APIServer) Shutdown() error {
167178
func (s *APIServer) Register(endpoint, summary, description string, handler http.Handler) error {
168179
s.logger.Debug("Endpoint Registered", "endpoint", endpoint)
169180
s.mux.Handle(endpoint, handler)
170-
s.endpointDescription += fmt.Sprintf("<li> <a href=\"%s\"> %s </a> %s </li>\n", endpoint, summary, description)
181+
s.endpointDescription += fmt.Sprintf(
182+
"<li><a href=\"%s\">%s</a> %s</li>\n",
183+
endpoint,
184+
summary,
185+
description,
186+
)
187+
171188
return nil
172189
}

0 commit comments

Comments
 (0)