-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnode_exporter.go
45 lines (36 loc) · 985 Bytes
/
node_exporter.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
package config
import (
"context"
"github.com/containerd/containerd"
"github.com/urfave/cli"
)
const metricsUnit = `[Unit]
Description=prometheus node metrics
[Service]
ExecStart=/opt/containerd/bin/nodeexporter
Restart=always
[Install]
WantedBy=multi-user.target`
type NodeExporter struct {
Image string `toml:"image"`
}
func (s *NodeExporter) Name() string {
return "node-exporter"
}
func (s *NodeExporter) Run(ctx context.Context, client *containerd.Client, clix *cli.Context) error {
const name = "nodeexporter.service"
if err := install(ctx, client, s.Image, clix); err != nil {
return err
}
if err := writeUnit(name, metricsUnit); err != nil {
return err
}
return startNewService(ctx, name)
}
func (s *NodeExporter) Remove(ctx context.Context, client *containerd.Client, clix *cli.Context) error {
if err := client.ImageService().Delete(ctx, s.Image); err != nil {
return err
}
const name = "nodeexporter.service"
return disableService(ctx, name)
}