forked from nathanielc/influxdays
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5_autoscale.tick
28 lines (26 loc) · 901 Bytes
/
5_autoscale.tick
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
dbrp "telegraf"."autogen"
// Target 100 requests per second per host
var target = 100.0
// Autoscale deployment node based on target requests per second per node.
stream
|from()
.measurement('requests')
.groupBy('host', 'deployment')
.truncate(1s)
// Compute requests per second per host
|derivative('value')
.as('requests_per_second')
.unit(1s)
.nonNegative()
// Compute total requests per second by deployment
|groupBy('deployment')
|sum('requests_per_second')
.as('total_requests')
// Scale the deployment based on target.
|k8sAutoscale()
// Get the name of the deployment from the 'deployment' tag.
.resourceNameTag('deployment')
.min(1)
.max(100)
// Set the desired number of replicas based on target.
.replicas(lambda: int(ceil("total_requests" / target)))