Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker caching using instance variable #45

Open
scalp42 opened this issue Aug 4, 2019 · 0 comments
Open

Docker caching using instance variable #45

scalp42 opened this issue Aug 4, 2019 · 0 comments

Comments

@scalp42
Copy link

scalp42 commented Aug 4, 2019

Hi @repeatedly,

Thanks for the plugin!

I have a Syslog input and I'd like to add extra fields from Docker API:

In the current form, it won't be optimized as the call Docker calls will be make on each line.

Do you have idea on how to cache these call for at least some period of time?

Here's the current form:

<filter syslog.docker.containers.**>
  @type record_modifier
  prepare_value require 'docker'
  <record>
    docker_version ${Docker.version['Version'] rescue nil}
  </record>
  <record>
    docker_image ${sha_image = Docker::Container.get(record['ident']).info['Image']; Docker::Image.get(sha_image).info['RepoTags'].first.split(':').first}
  </record>
  <record>
    docker_tag ${sha_image = Docker::Container.get(record['ident']).info['Image']; Docker::Image.get(sha_image).info['RepoTags'].first.split(':').last}
  </record>
  <record>
    docker_restart_count ${Docker::Container.get(record['ident']).info['RestartCount']}
  </record>
  <record>
    docker_started_at ${Time.parse(Docker::Container.get(record['ident']).info['State']['StartedAt']).to_s}
  </record>
  <record>
    docker_finished_at ${Time.parse(Docker::Container.get(record['ident']).info['State']['FinishedAt']).to_s}
  </record>
  <record>
    docker_container ${Docker::Container.get(record['ident']).info['Name'][1..-1]}
  </record>
  <record>
    nomad_alloc_name ${Docker::Container.get(record['ident']).info['Config']['Env'].select { |e| e.include?('NOMAD_ALLOC_NAME') }.first.split('=').last rescue nil}
  </record>
  remove_keys extradata,msgid,container_id,pid
</filter>

Any help would be much appreciated 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant