Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/cmd/grafana-agent-service/config_windows.go
4094 views
1
package main
2
3
import (
4
"fmt"
5
"path/filepath"
6
7
"golang.org/x/sys/windows/registry"
8
)
9
10
// config holds configuration options to run the service.
11
type config struct {
12
// ServicePath points to the path of the managed Grafana Agent binary.
13
ServicePath string
14
15
// Args holds arguments to pass to the Grafana Agent binary. os.Args[0] is
16
// not included.
17
Args []string
18
19
// WorkingDirectory points to the working directory to run the Grafana Agent
20
// binary from.
21
WorkingDirectory string
22
}
23
24
// loadConfig loads the config from the Windows registry.
25
func loadConfig() (*config, error) {
26
// NOTE(rfratto): the key name below shouldn't be changed without being
27
// able to either migrate from the old key to the new key or supporting
28
// both the old and the new key at the same time.
29
30
agentKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `Software\Grafana\Grafana Agent Flow`, registry.READ)
31
if err != nil {
32
return nil, fmt.Errorf("failed to open registry: %w", err)
33
}
34
35
servicePath, _, err := agentKey.GetStringValue("")
36
if err != nil {
37
return nil, fmt.Errorf("failed to retrieve key (Default): %w", err)
38
}
39
40
args, _, err := agentKey.GetStringsValue("Arguments")
41
if err != nil {
42
return nil, fmt.Errorf("failed to retrieve key Arguments: %w", err)
43
}
44
45
return &config{
46
ServicePath: servicePath,
47
Args: args,
48
WorkingDirectory: filepath.Dir(servicePath),
49
}, nil
50
}
51
52