# How to write a Telegraf Processor to change the hostname (fot GCE for instance)

**URL:** <https://community.influxdata.com/t/how-to-write-a-telegraf-processor-to-change-the-hostname-fot-gce-for-instance/1480>\
**Category:** Telegraf\
**Tags:** telegraf\
**Created:** [June 30, 2017, 4:03pm UTC](https://community.influxdata.com/t/how-to-write-a-telegraf-processor-to-change-the-hostname-fot-gce-for-instance/1480 "2017-06-30T16:03:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nilct](https://avatars.discourse-cdn.com/v4/letter/n/d07c76/32.png) [@Nilct](https://community.influxdata.com/u/Nilct)\
**Post date:** [June 30, 2017, 4:03pm UTC](https://community.influxdata.com/t/how-to-write-a-telegraf-processor-to-change-the-hostname-fot-gce-for-instance/1480/1 "2017-06-30T16:03:07Z")

</div>

I am using Telegraf to collect docker and system metrics (so far). It is deployed on a swarm on Google Cloud.

If I use the official plugins I don’t have the right hostname (as in a **GCE swarm** ). On my custom plugins, I simply launch a request to [http://metadata.google.internal/computeMetadata/v1/instance/name](http://metadata.google.internal/computeMetadata/v1/instance/name) (go code):

```auto
	req, err := http.NewRequest("GET", "http://metadata.google.internal/computeMetadata/v1/instance/name", nil)
	if err != nil {
		return "", err
	}
	req.Header.Set("Metadata-Flavor", "Google")

```

It works but I wish to use the official plugins ( **docker** and **system** at least) as much as possible.

It seems that rewriting the hostname could be a task done by a **Processor** (as presented in [Aggregator and Processor Plugins | InfluxData Documentation Archive](https://docs.influxdata.com/telegraf/v1.3/concepts/aggregator_processor_plugins/)).  
But I can’t find any example of processors that could help me create my own.

So I have 3 questions :  
1- can a processor solve my problem, ie rewrite the hostname tag (which is added by telegraf if I am not mistaken)  
2- can a processor be a program (in my case in go) ?  
3- is there such an example (in any language) and where ?

---

<div class="post-metadata">

**Author:** ![jackzampolin](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jackzampolin/32/5_2.png) [@jackzampolin](https://community.influxdata.com/u/jackzampolin)\
**Post date:** [July 5, 2017, 5:42pm UTC](https://community.influxdata.com/t/how-to-write-a-telegraf-processor-to-change-the-hostname-fot-gce-for-instance/1480/2 "2017-07-05T17:42:24Z")

</div>

@Nilct I’ve done this in Kubernetes by using the [Downward API](https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/) to inject a `HOSTNAME` into the telegraf container. It looks like you could do the same with that gocode you list above. I use that env to explicitly set the the `[agent]hostname = "$HOSTNAME"` in the config file. Does that work for for you?

---

<div class="post-metadata">

**Author:** ![Nilct](https://avatars.discourse-cdn.com/v4/letter/n/d07c76/32.png) [@Nilct](https://community.influxdata.com/u/Nilct)\
**Post date:** [July 6, 2017, 4:53pm UTC](https://community.influxdata.com/t/how-to-write-a-telegraf-processor-to-change-the-hostname-fot-gce-for-instance/1480/3 "2017-07-06T16:53:23Z")

</div>

That would could work on our pods (the deployment depends on k8s config files) but we also have containers on workers deployed via docker-compose on a swarm (the container is built on the manager then deployed on any worker as needed).

I will nevertheless investigate this API, thanks !
