This script seems to do the job.
Just add to the configuration for the metrics you want to replicate.
EDIT: added the field to de groupID function to create a unique entry for all fields (subscription based plugins update 1 field at a time). for opcua exclude the field “Quality”, it is always included with the other fields but also shows up on its own.
[[aggregators.starlark]]
period = "1m"
script = "./replication.star"
replication.star:
state = {}
load("logging.star", "log")
load("time.star", "time")
def add(metric):
gId = groupID(metric)
state[gId] = deepcopy(metric)
log.debug("add/update groupID: " + str(gId))
def push():
log.debug("push: " + str(len(state)) + " metrics")
metrics = []
for v in state.values():
storedmetric = deepcopy(v)
storedmetric.time = time.now().unix_nano
metrics.append(storedmetric)
return metrics
def reset():
log.debug("reset replication function")
def groupID(metric):
key = metric.name
for k, v in metric.tags.items():
key = key + "|" + k + "-" + v
for k, v in metric.fields.items():
key = key + "|" + k
return hash(key)