Skip to content

Commit

Permalink
feat: add tick feature
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackDark committed Oct 30, 2024
1 parent 29ef147 commit 1c80ad5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# prometheus_turbotstat_exporter
An prometheus exporter for turbotstat (for monitoring different C-states and pkg-states)
An prometheus exporter for turbotstat (for monitoring different C-states and pkg-states).

## Example scrape output

Part of the output from the scrape:

```txt
...
turbostat_cpu_states_percent{num_cpu="6",type="c1e"} 0.03
turbostat_cpu_states_percent{num_cpu="6",type="c3"} 0.05
turbostat_cpu_states_percent{num_cpu="6",type="c6"} 1.37
turbostat_cpu_states_percent{num_cpu="6",type="c7s"} 0
turbostat_cpu_states_percent{num_cpu="6",type="c8"} 1.11
turbostat_cpu_states_percent{num_cpu="6",type="c9"} 0.13
turbostat_cpu_states_percent{num_cpu="6",type="poll"} 0
turbostat_cpu_states_percent{num_cpu="7",type="c1"} 0.01
turbostat_cpu_states_percent{num_cpu="7",type="c10"} 96.91
turbostat_cpu_states_percent{num_cpu="7",type="c1e"} 0.03
turbostat_cpu_states_percent{num_cpu="7",type="c3"} 0.01
turbostat_cpu_states_percent{num_cpu="7",type="c6"} 1.36
...
```
37 changes: 30 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"slices"
"strconv"
"strings"
"time"

"bufio"

Expand Down Expand Up @@ -400,7 +401,6 @@ func parseOutput(input io.Reader) ([]string, []map[string]interface{}) {
}

func Update() {
// TODO maybe run the execution in the background and just return the current values?
reader := executeProgram(defaultSleepTimer)
_, data := parseOutput(&reader)

Expand Down Expand Up @@ -437,12 +437,14 @@ func Update() {
type helloWorldhandler struct{}

func (h helloWorldhandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Update()
if !isBackgroundMode {
Update()
}
promhttp.Handler().ServeHTTP(w, r)
}

var listOfMetrics []metricMapping = nil
var defaultSleepTimer int = 5
var defaultSleepTimer = 5
var isCommandCat = false
var isBackgroundMode = false
var backgroundCollectSeconds = 30
Expand Down Expand Up @@ -514,6 +516,31 @@ func main() {

listOfMetrics = buildMetricList(&reader)

if isBackgroundMode {
log.Debugf("Starting ticker")
ticker := time.NewTicker(time.Duration(backgroundCollectSeconds) * time.Second)
quit := make(chan struct{})
manualTick := make(chan bool)

go func() {
for {
select {
case <-ticker.C:
log.Debugf("Ticker update")
Update()
case <-manualTick:
log.Debugf("Manual tick update")
Update()
case <-quit:
log.Debugf("Stop background updater")
ticker.Stop()
return
}
}
}()
manualTick <- true
}

//foo := newFooCollector()

http.Handle("/metrics", helloWorldhandler{})
Expand Down Expand Up @@ -555,10 +582,6 @@ func test1() {
panic(err)
}

if err != nil { // Load clients from file
panic(err)
}

for _, client := range maps {
fmt.Println("Hello", client)
}
Expand Down

0 comments on commit 1c80ad5

Please sign in to comment.