Add appname to basic metrics (#547)

* Add app labels to queued/running/completed/failed metrics

* Add app labels to queued/running/completed/failed metrics

* Add app labels to queued/running/completed/failed metrics
This commit is contained in:
Nigel Deakin
2017-11-28 16:17:24 +00:00
committed by Reed Allman
parent 778c8b0495
commit 954f69e74a
3 changed files with 45 additions and 34 deletions

View File

@@ -192,7 +192,7 @@ func (a *agent) Submit(callI Call) error {
}
// increment queued count
a.stats.Enqueue(callI.Model().Path)
a.stats.Enqueue(callI.Model().AppName, callI.Model().Path)
call := callI.(*call)
ctx := call.req.Context()
@@ -209,7 +209,7 @@ func (a *agent) Submit(callI Call) error {
slot, err := a.getSlot(ctx, call) // find ram available / running
if err != nil {
a.stats.Dequeue(callI.Model().Path)
a.stats.Dequeue(callI.Model().AppName, callI.Model().Path)
return transformTimeout(err, true)
}
// TODO if the call times out & container is created, we need
@@ -219,12 +219,12 @@ func (a *agent) Submit(callI Call) error {
// TODO Start is checking the timer now, we could do it here, too.
err = call.Start(ctx, a)
if err != nil {
a.stats.Dequeue(callI.Model().Path)
a.stats.Dequeue(callI.Model().AppName, callI.Model().Path)
return transformTimeout(err, true)
}
// decrement queued count, increment running count
a.stats.DequeueAndStart(callI.Model().Path)
a.stats.DequeueAndStart(callI.Model().AppName, callI.Model().Path)
err = slot.exec(ctx, call)
// pass this error (nil or otherwise) to end directly, to store status, etc
@@ -232,10 +232,10 @@ func (a *agent) Submit(callI Call) error {
if err == nil {
// decrement running count, increment completed count
a.stats.Complete(callI.Model().Path)
a.stats.Complete(callI.Model().AppName, callI.Model().Path)
} else {
// decrement running count, increment failed count
a.stats.Failed(callI.Model().Path)
a.stats.Failed(callI.Model().AppName, callI.Model().Path)
}
// TODO: we need to allocate more time to store the call + logs in case the call timed out,

View File

@@ -53,28 +53,28 @@ var (
Name: "fn_api_queued",
Help: "Queued requests by path",
},
[](string){"path"},
[](string){"app", "path"},
)
fnRunning = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "fn_api_running",
Help: "Running requests by path",
},
[](string){"path"},
[](string){"app", "path"},
)
fnCompleted = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "fn_api_completed",
Help: "Completed requests by path",
},
[](string){"path"},
[](string){"app", "path"},
)
fnFailed = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "fn_api_failed",
Help: "Failed requests by path",
},
[](string){"path"},
[](string){"app", "path"},
)
)
@@ -98,79 +98,79 @@ func (s *stats) getStatsForFunction(path string) *functionStats {
return thisFunctionStats
}
func (s *stats) Enqueue(path string) {
func (s *stats) Enqueue(app string, path string) {
s.mu.Lock()
s.queue++
s.getStatsForFunction(path).queue++
fnQueued.WithLabelValues(path).Inc()
fnQueued.WithLabelValues(app, path).Inc()
s.mu.Unlock()
}
// Call when a function has been queued but cannot be started because of an error
func (s *stats) Dequeue(path string) {
func (s *stats) Dequeue(app string, path string) {
s.mu.Lock()
s.queue--
s.getStatsForFunction(path).queue--
fnQueued.WithLabelValues(path).Dec()
fnQueued.WithLabelValues(app, path).Dec()
s.mu.Unlock()
}
func (s *stats) DequeueAndStart(path string) {
func (s *stats) DequeueAndStart(app string, path string) {
s.mu.Lock()
s.queue--
s.getStatsForFunction(path).queue--
fnQueued.WithLabelValues(path).Dec()
fnQueued.WithLabelValues(app, path).Dec()
s.running++
s.getStatsForFunction(path).running++
fnRunning.WithLabelValues(path).Inc()
fnRunning.WithLabelValues(app, path).Inc()
s.mu.Unlock()
}
func (s *stats) Complete(path string) {
func (s *stats) Complete(app string, path string) {
s.mu.Lock()
s.running--
s.getStatsForFunction(path).running--
fnRunning.WithLabelValues(path).Dec()
fnRunning.WithLabelValues(app, path).Dec()
s.complete++
s.getStatsForFunction(path).complete++
fnCompleted.WithLabelValues(path).Inc()
fnCompleted.WithLabelValues(app, path).Inc()
s.mu.Unlock()
}
func (s *stats) Failed(path string) {
func (s *stats) Failed(app string, path string) {
s.mu.Lock()
s.running--
s.getStatsForFunction(path).running--
fnRunning.WithLabelValues(path).Dec()
fnRunning.WithLabelValues(app, path).Dec()
s.failed++
s.getStatsForFunction(path).failed++
fnFailed.WithLabelValues(path).Inc()
fnFailed.WithLabelValues(app, path).Inc()
s.mu.Unlock()
}
func (s *stats) DequeueAndFail(path string) {
func (s *stats) DequeueAndFail(app string, path string) {
s.mu.Lock()
s.queue--
s.getStatsForFunction(path).queue--
fnQueued.WithLabelValues(path).Dec()
fnQueued.WithLabelValues(app, path).Dec()
s.failed++
s.getStatsForFunction(path).failed++
fnFailed.WithLabelValues(path).Inc()
fnFailed.WithLabelValues(app, path).Inc()
s.mu.Unlock()
}

View File

@@ -14,7 +14,7 @@
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "4.5.2"
"version": "4.6.2"
},
{
"type": "panel",
@@ -36,7 +36,17 @@
}
],
"annotations": {
"list": []
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
@@ -44,7 +54,7 @@
"hideControls": false,
"id": null,
"links": [],
"refresh": false,
"refresh": "30s",
"rows": [
{
"collapse": false,
@@ -721,6 +731,7 @@
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 3,
"stack": false,
@@ -731,7 +742,7 @@
"format": "time_series",
"interval": "",
"intervalFactor": 1,
"legendFormat": "{{path}}",
"legendFormat": "{{app}} {{path}}",
"refId": "A",
"step": 1
}
@@ -814,7 +825,7 @@
"expr": "fn_api_running",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{path}}",
"legendFormat": "{{app}} {{path}}",
"refId": "A",
"step": 2
}
@@ -896,7 +907,7 @@
"expr": "fn_api_completed",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{path}}",
"legendFormat": "{{app}} {{path}}",
"refId": "A",
"step": 2
}
@@ -978,7 +989,7 @@
"expr": "fn_api_failed",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{path}}",
"legendFormat": "{{app}} {{path}}",
"refId": "A",
"step": 2
}
@@ -1065,5 +1076,5 @@
},
"timezone": "",
"title": "Fn usage",
"version": 1
"version": 5
}