I am creating for Log exports for logs generated in Google Stackdriver Logging for all the Compute Engine VMs and Clusters present in a project.
As we know exports destination can only be Cloud Storage, Cloud Pub/Sub, BigQuery. Hence I am not able to differentiate the logs generated by multiple VMs.
For Example: There are a number of VMs present and all of them generate syslog, and have one cloud bucket as their destination, the sinks for all the VMs will export the logs in a directory named syslog in that same cloud bucket.
To overcome above problem, I followed a way in which we configure the StackDriver Logging agent and change the logName tag. See this for more details.
Using the above approach I am able to change the tag of the logName from syslog to [instance-name]-syslog and hence sinks export the syslog from that GCE instance to one folder and so on.
I am changing the tag in the /etc/google-fluentd/config.d/[APPLICATIOON-NAME].conf files manually as of now. For example, here is the /etc/google-fluentd/config.d/syslog.conf file:
<source>
@type tail
# Parse the timestamp, but still collect the entire line as 'message'
format syslog
path /var/log/syslog
pos_file /var/lib/google-fluentd/pos/syslog.pos
read_from_head true
tag syslog
</source>
Now I am replacing the syslog above with [instance-name]-syslog manually by doing ssh in all the VMs. I am looking for a way to automate the above thing. What would be the most suitable way to do this? (P.S. All the VMs are being spin up using Terraform)