# Problem doing join two measurements

**URL:** <https://community.influxdata.com/t/problem-doing-join-two-measurements/13867>\
**Category:** Systems\
**Created:** [April 15, 2020, 3:59pm UTC](https://community.influxdata.com/t/problem-doing-join-two-measurements/13867 "2020-04-15T15:59:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorge\_Valles\_Sanz](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jorge_valles_sanz/32/2835_2.png) [@Jorge\_Valles\_Sanz](https://community.influxdata.com/u/Jorge_Valles_Sanz)\
**Post date:** [April 15, 2020, 3:59pm UTC](https://community.influxdata.com/t/problem-doing-join-two-measurements/13867/1 "2020-04-15T15:59:19Z")

</div>

Hello, Im trying to solve the following problem. I have a measurement from kubernetes wich exposes the max number of instance from hpa and the other one which exposes the current number of instances running, both metrics have a tag “hpa” and “deployment” wich content its the same. Im trying to obtain the percent running respect the total, everything its working fine until the join node.  
I obtain the metrics from prometheus via telegraf so maybe the problem its from here. This is the tickscript code and task results.

var measurement\_replicas = ‘kube\_deployment\_status\_replicas’

var measurement\_total = ‘kube\_hpa\_spec\_max\_replicas’

var name = ‘Porting - 80% instances’

var message = '{{ .ID }} is {{ .Level }} value : {{ index .Fields “percent\_instance” }} ’

var idTag = ‘alertID’

var filter = lambda: “job” == ‘kubernetes-pods’ AND “deployment” == ‘atp’ OR “deployment” == ‘crossbenefits’ OR “deployment” == ‘servicetestmanagement’ OR “deployment” == ‘products’ OR “deployment” == ‘salesmanagement’ OR “deployment” == ‘mdggateway’ OR “deployment” == ‘customerviewmdg’ OR “deployment” == ‘xplmobileinsurance’

var filter2 = lambda: “job” == ‘kubernetes-service-endpoints’

var idVar = name + ‘-{{.Group}}’

var levelTag = ‘level’

var messageField = ‘message’

var durationField = ‘duration’

var triggerType = ‘threshold’

var crit = 0

var replicas\_running = stream  
|from()  
.database(db)  
.retentionPolicy(rp)  
.measurement(measurement\_replicas)  
.where(filter)  
.groupBy(‘deployment’)  
|window()  
.period(5m)  
.every(1m)  
|last(‘value’)  
.as(‘value’)

var replicas\_total = stream  
|from()  
.database(db)  
.retentionPolicy(rp)  
.measurement(measurement\_total)  
.where(filter2)  
.groupBy(‘hpa’)  
|window()  
.period(10m)  
.every(1m)  
|last(‘value’)  
.as(‘value’)  
|eval(lambda: “hpa”)  
.as(‘deployment’)  
.keep()  
.tags(‘deployment’)  
|delete()  
.tag(‘hpa’)

replicas\_total  
|join(replicas\_running)  
.as(‘replicas\_total’, ‘replicas\_running’)  
.on(‘deployment’)  
.tolerance(2m)  
.fill(0.0)  
|eval(lambda: float(100.0 \* “replicas\_running.value”) / float(“replicas\_total.value”))  
.as(‘percent\_instance’)  
|alert()  
.crit(lambda: “percent\_instance” \>= crit)  
.stateChangesOnly()  
.message(message)  
.id(idVar)  
.idTag(idTag)  
.levelTag(levelTag)  
.messageField(messageField)  
.durationField(durationField)  
.log(’/var/lib/kapacitor/test.log’)

DOT:  
digraph TEST-PODS-STREAM {  
graph [throughput=“0.00 points/s”];

stream0 [avg\_exec\_time\_ns=“0s” errors=“0” working\_cardinality=“0”];  
stream0 -\> from4 [processed=“928”];  
stream0 -\> from1 [processed=“928”];

from4 [avg\_exec\_time\_ns=“1.934µs” errors=“0” working\_cardinality=“0”];  
from4 -\> window5 [processed=“232”];

window5 [avg\_exec\_time\_ns=“1.447µs” errors=“0” working\_cardinality=“8”];  
window5 -\> last6 [processed=“64”];

last6 [avg\_exec\_time\_ns=“9.236µs” errors=“0” working\_cardinality=“8”];  
last6 -\> eval7 [processed=“64”];

eval7 [avg\_exec\_time\_ns=“8.885µs” errors=“0” working\_cardinality=“8”];  
eval7 -\> delete8 [processed=“64”];

delete8 [avg\_exec\_time\_ns=“5.446µs” errors=“0” fields\_deleted=“0” tags\_deleted=“64” working\_cardinality=“0”];  
delete8 -\> join10 [processed=“64”];

from1 [avg\_exec\_time\_ns=“3.328µs” errors=“0” working\_cardinality=“0”];  
from1 -\> window2 [processed=“232”];

window2 [avg\_exec\_time\_ns=“2.747µs” errors=“0” working\_cardinality=“8”];  
window2 -\> last3 [processed=“72”];

last3 [avg\_exec\_time\_ns=“10.633µs” errors=“0” working\_cardinality=“8”];  
last3 -\> join10 [processed=“72”];

join10 [avg\_exec\_time\_ns=“4.794µs” errors=“0” working\_cardinality=“0”];  
join10 -\> eval11 [processed=“0”];

eval11 [avg\_exec\_time\_ns=“0s” errors=“0” working\_cardinality=“0”];  
eval11 -\> alert12 [processed=“0”];

alert12 [alerts\_inhibited=“0” alerts\_triggered=“0” avg\_exec\_time\_ns=“0s” crits\_triggered=“0” errors=“0” infos\_triggered=“0” oks\_triggered=“0” warns\_triggered=“0” working\_cardinality=“0”];

Thanks!

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [April 15, 2020, 6:11pm UTC](https://community.influxdata.com/t/problem-doing-join-two-measurements/13867/2 "2020-04-15T18:11:35Z")

</div>

Hello @Jorge_Valles_Sanz,  
Welcome! What version of Influxdb are you running? Have you considered performing a [join](https://docs.influxdata.com/flux/v0.65/guides/join/#sidebar) with flux instead?

---

<div class="post-metadata">

**Author:** ![Jorge\_Valles\_Sanz](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jorge_valles_sanz/32/2835_2.png) [@Jorge\_Valles\_Sanz](https://community.influxdata.com/u/Jorge_Valles_Sanz)\
**Post date:** [April 16, 2020, 8:07am UTC](https://community.influxdata.com/t/problem-doing-join-two-measurements/13867/3 "2020-04-16T08:07:10Z")

</div>

Hello @Anaisdg, thanks for the reply.  
I’m using Influx 1.7.9, on the other hand, I haven’t considered using the stream, I just started in this Tick Stack “world” for a week now. I did not know the existence of flow until you have commented on it.

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [April 16, 2020, 2:17pm UTC](https://community.influxdata.com/t/problem-doing-join-two-measurements/13867/4 "2020-04-16T14:17:41Z")

</div>

@Jorge_Valles_Sanz,  
I recommend [enabling flux](https://docs.influxdata.com/flux/v0.50/introduction/installation/) and then trying out some joins. This [blog](https://www.influxdata.com/blog/influxdb-how-to-do-joins-math-across-measurements/) could be a useful addition.

---

<div class="post-metadata">

**Author:** ![Jorge\_Valles\_Sanz](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jorge_valles_sanz/32/2835_2.png) [@Jorge\_Valles\_Sanz](https://community.influxdata.com/u/Jorge_Valles_Sanz)\
**Post date:** [April 17, 2020, 8:01am UTC](https://community.influxdata.com/t/problem-doing-join-two-measurements/13867/5 "2020-04-17T08:01:52Z")

</div>

Hi again i was finally able to fix the tickscript and the join node its working properly. Thanks for your time, I will check the links you attached to consider the update.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/3X/2/f/2feb065bdfd5e4b7728243aa3b9192ad3e8447c1.png) [@system](https://community.influxdata.com/u/system)\
**Post date:** [June 16, 2020, 4:18pm UTC](https://community.influxdata.com/t/problem-doing-join-two-measurements/13867/6 "2020-06-16T16:18:59Z")

</div>

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.
