diff options
author | Sean E. Russell <ser@ser1.net> | 2020-02-18 13:47:52 -0600 |
---|---|---|
committer | Sean E. Russell <ser@ser1.net> | 2020-02-18 13:47:52 -0600 |
commit | 5e779839015531bd723d962755e477e85e13d081 (patch) | |
tree | 351ff3eb58dbdb168efbc4740f4b434a74c2c083 /widgets/temp.go | |
parent | f96a97c3d8f5b8cd87a6e2f1fd1d0a4032c429a7 (diff) | |
parent | 5ccfc7cbc6f406192e1eb20d84dcfa49814e57ad (diff) |
Merge branch 'metrics' into v3.4.x; also fixes a bug in some of the widgets where it wasn't checking that metrics were enabled and was causing panics.
Diffstat (limited to 'widgets/temp.go')
-rw-r--r-- | widgets/temp.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/widgets/temp.go b/widgets/temp.go index 86e6e76..7ae3ef1 100644 --- a/widgets/temp.go +++ b/widgets/temp.go @@ -7,6 +7,7 @@ import ( "time" ui "github.com/gizak/termui/v3" + "github.com/prometheus/client_golang/prometheus" "github.com/xxxserxxx/gotop/utils" ) @@ -27,6 +28,7 @@ type TempWidget struct { TempLowColor ui.Color TempHighColor ui.Color TempScale TempScale + tempsMetric map[string]prometheus.Gauge } func NewTempWidget(tempScale TempScale) *TempWidget { @@ -56,6 +58,20 @@ func NewTempWidget(tempScale TempScale) *TempWidget { return self } +func (self *TempWidget) EnableMetric() { + self.tempsMetric = make(map[string]prometheus.Gauge) + for k, v := range self.Data { + gauge := prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: "gotop", + Subsystem: "temp", + Name: k, + }) + gauge.Set(float64(v)) + prometheus.MustRegister(gauge) + self.tempsMetric[k] = gauge + } +} + // Custom Draw method instead of inheriting from a generic Widget. func (self *TempWidget) Draw(buf *ui.Buffer) { self.Block.Draw(buf) @@ -98,5 +114,8 @@ func (self *TempWidget) Draw(buf *ui.Buffer) { image.Pt(self.Inner.Max.X-4, self.Inner.Min.Y+y), ) } + if self.tempsMetric != nil { + self.tempsMetric[key].Set(float64(self.Data[key])) + } } } |