-
Notifications
You must be signed in to change notification settings - Fork 52
/
prometheus.go
44 lines (37 loc) · 997 Bytes
/
prometheus.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
// Copyright (c) 2024 Hemi Labs, Inc.
// Use of this source code is governed by the MIT License,
// which can be found in the LICENSE file.
//go:build !js && !wasm
package popm
import (
"context"
"errors"
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/hemilabs/heminetwork/service/deucalion"
)
func (m *Miner) handlePrometheus(ctx context.Context) error {
d, err := deucalion.New(&deucalion.Config{
ListenAddress: m.cfg.PrometheusListenAddress,
})
if err != nil {
return fmt.Errorf("create server: %w", err)
}
cs := []prometheus.Collector{
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Subsystem: promSubsystem,
Name: "running",
Help: "Is pop miner service running.",
}, m.promRunning),
}
m.wg.Add(1)
go func() {
defer m.wg.Done()
if err := d.Run(ctx, cs); !errors.Is(err, context.Canceled) {
log.Errorf("prometheus terminated with error: %v", err)
return
}
log.Infof("prometheus clean shutdown")
}()
return nil
}