1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

Added metric for running processes by name

This commit is contained in:
postmannen 2021-04-12 15:35:20 +02:00
parent 1acddfa8b4
commit f32dafc806
4 changed files with 18 additions and 1 deletions

View file

@ -1,6 +1,6 @@
[
{
"directory": "metrics/network/sniffer",
"directory": "vg-sin-hjemmeside",
"fileExtension": ".html",
"toNode": "ship1",
"data": ["http://vg.no"],

View file

@ -9,6 +9,7 @@ import (
"time"
"github.com/nats-io/nats.go"
"github.com/prometheus/client_golang/prometheus"
)
// processKind are either kindSubscriber or kindPublisher, and are
@ -153,6 +154,9 @@ func (p process) spawnWorker(procs *processes, natsConn *nats.Conn) {
pn = processNameGet(p.subject.name(), processKindSubscriber)
}
processName := processNameGet(p.subject.name(), p.processKind)
p.processes.promProcessesVec.With(prometheus.Labels{"processName": string(processName)})
// Start a publisher worker, which will start a go routine (process)
// That will take care of all the messages for the subject it owns.
if p.processKind == processKindPublisher {

View file

@ -32,6 +32,8 @@ type processes struct {
lastProcessID int
//
promTotalProcesses prometheus.Gauge
//
promProcessesVec *prometheus.GaugeVec
}
// newProcesses will prepare and return a *processes
@ -45,6 +47,12 @@ func newProcesses(promRegistry *prometheus.Registry) *processes {
Help: "The current number of total running processes",
})
p.promProcessesVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "running_process",
Help: "Name of the running process",
}, []string{"processName"},
)
return &p
}

View file

@ -43,6 +43,8 @@ import (
"os/exec"
"path/filepath"
"time"
"github.com/prometheus/client_golang/prometheus"
)
// Method is used to specify the actual function/method that
@ -351,6 +353,9 @@ func (m methodREQOpCommand) handler(proc process, message Message, nodeName stri
log.Printf(" ** Error: failed to stop *nats.Subscription: %v\n", err)
}
// Remove the prometheus label
proc.processes.promProcessesVec.Delete(prometheus.Labels{"processName": string(processName)})
er := fmt.Errorf("info: stopProc: stoped %v on %v", sub, message.ToNode)
sendErrorLogMessage(proc.toRingbufferCh, proc.node, er)