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 // increment queued count
a.stats.Enqueue(callI.Model().Path) a.stats.Enqueue(callI.Model().AppName, callI.Model().Path)
call := callI.(*call) call := callI.(*call)
ctx := call.req.Context() 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 slot, err := a.getSlot(ctx, call) // find ram available / running
if err != nil { if err != nil {
a.stats.Dequeue(callI.Model().Path) a.stats.Dequeue(callI.Model().AppName, callI.Model().Path)
return transformTimeout(err, true) return transformTimeout(err, true)
} }
// TODO if the call times out & container is created, we need // 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. // TODO Start is checking the timer now, we could do it here, too.
err = call.Start(ctx, a) err = call.Start(ctx, a)
if err != nil { if err != nil {
a.stats.Dequeue(callI.Model().Path) a.stats.Dequeue(callI.Model().AppName, callI.Model().Path)
return transformTimeout(err, true) return transformTimeout(err, true)
} }
// decrement queued count, increment running count // 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) err = slot.exec(ctx, call)
// pass this error (nil or otherwise) to end directly, to store status, etc // 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 { if err == nil {
// decrement running count, increment completed count // decrement running count, increment completed count
a.stats.Complete(callI.Model().Path) a.stats.Complete(callI.Model().AppName, callI.Model().Path)
} else { } else {
// decrement running count, increment failed count // 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, // 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", Name: "fn_api_queued",
Help: "Queued requests by path", Help: "Queued requests by path",
}, },
[](string){"path"}, [](string){"app", "path"},
) )
fnRunning = prometheus.NewGaugeVec( fnRunning = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Name: "fn_api_running", Name: "fn_api_running",
Help: "Running requests by path", Help: "Running requests by path",
}, },
[](string){"path"}, [](string){"app", "path"},
) )
fnCompleted = prometheus.NewCounterVec( fnCompleted = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "fn_api_completed", Name: "fn_api_completed",
Help: "Completed requests by path", Help: "Completed requests by path",
}, },
[](string){"path"}, [](string){"app", "path"},
) )
fnFailed = prometheus.NewCounterVec( fnFailed = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "fn_api_failed", Name: "fn_api_failed",
Help: "Failed requests by path", Help: "Failed requests by path",
}, },
[](string){"path"}, [](string){"app", "path"},
) )
) )
@@ -98,79 +98,79 @@ func (s *stats) getStatsForFunction(path string) *functionStats {
return thisFunctionStats return thisFunctionStats
} }
func (s *stats) Enqueue(path string) { func (s *stats) Enqueue(app string, path string) {
s.mu.Lock() s.mu.Lock()
s.queue++ s.queue++
s.getStatsForFunction(path).queue++ s.getStatsForFunction(path).queue++
fnQueued.WithLabelValues(path).Inc() fnQueued.WithLabelValues(app, path).Inc()
s.mu.Unlock() s.mu.Unlock()
} }
// Call when a function has been queued but cannot be started because of an error // 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.mu.Lock()
s.queue-- s.queue--
s.getStatsForFunction(path).queue-- s.getStatsForFunction(path).queue--
fnQueued.WithLabelValues(path).Dec() fnQueued.WithLabelValues(app, path).Dec()
s.mu.Unlock() s.mu.Unlock()
} }
func (s *stats) DequeueAndStart(path string) { func (s *stats) DequeueAndStart(app string, path string) {
s.mu.Lock() s.mu.Lock()
s.queue-- s.queue--
s.getStatsForFunction(path).queue-- s.getStatsForFunction(path).queue--
fnQueued.WithLabelValues(path).Dec() fnQueued.WithLabelValues(app, path).Dec()
s.running++ s.running++
s.getStatsForFunction(path).running++ s.getStatsForFunction(path).running++
fnRunning.WithLabelValues(path).Inc() fnRunning.WithLabelValues(app, path).Inc()
s.mu.Unlock() s.mu.Unlock()
} }
func (s *stats) Complete(path string) { func (s *stats) Complete(app string, path string) {
s.mu.Lock() s.mu.Lock()
s.running-- s.running--
s.getStatsForFunction(path).running-- s.getStatsForFunction(path).running--
fnRunning.WithLabelValues(path).Dec() fnRunning.WithLabelValues(app, path).Dec()
s.complete++ s.complete++
s.getStatsForFunction(path).complete++ s.getStatsForFunction(path).complete++
fnCompleted.WithLabelValues(path).Inc() fnCompleted.WithLabelValues(app, path).Inc()
s.mu.Unlock() s.mu.Unlock()
} }
func (s *stats) Failed(path string) { func (s *stats) Failed(app string, path string) {
s.mu.Lock() s.mu.Lock()
s.running-- s.running--
s.getStatsForFunction(path).running-- s.getStatsForFunction(path).running--
fnRunning.WithLabelValues(path).Dec() fnRunning.WithLabelValues(app, path).Dec()
s.failed++ s.failed++
s.getStatsForFunction(path).failed++ s.getStatsForFunction(path).failed++
fnFailed.WithLabelValues(path).Inc() fnFailed.WithLabelValues(app, path).Inc()
s.mu.Unlock() s.mu.Unlock()
} }
func (s *stats) DequeueAndFail(path string) { func (s *stats) DequeueAndFail(app string, path string) {
s.mu.Lock() s.mu.Lock()
s.queue-- s.queue--
s.getStatsForFunction(path).queue-- s.getStatsForFunction(path).queue--
fnQueued.WithLabelValues(path).Dec() fnQueued.WithLabelValues(app, path).Dec()
s.failed++ s.failed++
s.getStatsForFunction(path).failed++ s.getStatsForFunction(path).failed++
fnFailed.WithLabelValues(path).Inc() fnFailed.WithLabelValues(app, path).Inc()
s.mu.Unlock() s.mu.Unlock()
} }

View File

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