Metrics

Every docker node created on tsuru has a tsuru agent(a.k.a node-container),called big-sibling, running as a container. One of it’s responsibilities iscollecting and reporting metrics, such as cpu and memory usage, from both it’shost and other applications and containers running on the same host.

tsuru metrics architecture overview
Overview of all components involved on collecting, ingesting and displaying metrics.

Big-sibling will report metrics to a logstash component, which can be remote or local.This logstash must be configured to output metrics elasticsearch, where they will be storedand where the tsuru dashboard fetches them to display graphics.

The following section will walkthrough the installation and configuration of these components.

Installing

You will need a Elasticsearchand a Logstash installed.Installing these components is beyond the scope of the documentation, please refer to their documentation for that.

After having both components installed, we can move on to configuring each one of them.

Configuring bs

We need to configure big-sibling, to send metrics to our logstash.

You should use _tsuru node-container-update big-sibling –env NAME=VALUE_to define the config values.

The available configs are:

METRICS_INTERVAL is the interval in seconds between metrics collecting andreporting from bs to the metric backend. The default value is 60 seconds.

METRICS_BACKEND is the metric backend. Only ‘logstash’ is supported right now.

Logstash specific configs:

METRICS_LOGSTASH_CLIENT is the client name used to identify who is sending themetric. The default value is tsuru.

METRICS_LOGSTASH_PORT is the Logstash port. The default value is 1984.

METRICS_LOGSTASH_HOST is the Logstash host. The default value is localhost.

Configuring Logstash

tsuru sends data to Logstash using udp protocol and the message is formatted injson. We need to define a custom logstash configuration to be able to parse themetrics sent by big-sibling and send them to our elasticsearch cluster. The followingconfiguration does the job, refer to the logstash documentationfor information regarding setting this configuration.

  1. input {
  2. udp {
  3. port => 1984
  4. }
  5. }
  6.  
  7. filter {
  8. json {
  9. source => "message"
  10. }
  11.  
  12. if "_jsonparsefailure" in [tags] {
  13. mutate {
  14. add_field => {
  15. client => "error"
  16. metric => "metric_error"
  17. }
  18. }
  19. }
  20. }
  21.  
  22. output {
  23. elasticsearch {
  24. hosts => ["http://ELASTICSEARCH_HOST:ELASTICSEARCH_PORT"]
  25. index => ".measure-%{client}-%{+YYYY.MM.dd}"
  26. document_type => "%{metric}"
  27. template => "/etc/logstash/template.json"
  28. template_name => "tsuru-template"
  29. }
  30. }

Where ELASTICSEARCH_HOST must point to your elasticsearch host and ELASTICSEARCH_PORTmust point to your elasticsearch port. Refer to the elasticsearch plugin configurationfor more information. The file “/etc/logstash/tsuru-template.json” should have the following contents:

  1. {
  2. "order": 0,
  3. "template": ".measure-*",
  4. "settings": {
  5. "index.refresh_interval": "5s"
  6. },
  7. "mappings": {
  8. "_default_": {
  9. "dynamic_templates": [
  10. {
  11. "string_fields": {
  12. "mapping": {
  13. "omit_norms": true,
  14. "type": "multi_field",
  15. "fields": {
  16. "raw": {
  17. "index": "not_analyzed",
  18. "ignore_above": 256,
  19. "type": "string"
  20. },
  21. "{name}": {
  22. "index": "analyzed",
  23. "type": "string"
  24. }
  25. }
  26. },
  27. "match_mapping_type": "string",
  28. "match": "*"
  29. }
  30. }
  31. ],
  32. "properties": {
  33. "geoip": {
  34. "dynamic": true,
  35. "path": "full",
  36. "properties": {
  37. "location": {
  38. "type": "geo_point"
  39. }
  40. },
  41. "type": "object"
  42. },
  43. "@version": {
  44. "index": "not_analyzed",
  45. "type": "string"
  46. }
  47. },
  48. "_all": {
  49. "enabled": true
  50. }
  51. }
  52. },
  53. "aliases": {}
  54. }

Configuring Elasticsearch

tsuru requires an elasticsearch with groovy dynamic scripting enabled, since elasticsearchv1.4.3, it’s off by default and needs to be explicitly enabled on the config file.

For elasticsearch 2.x, scripting can be enabled by setting the following configuration:

  1. script.engine.groovy.inline.aggs: true
  2. script.engine.groovy.inline.mapping: false
  3. script.engine.groovy.inline.search: false
  4. script.engine.groovy.inline.update: false
  5. script.engine.groovy.inline.plugin: false

For more information, check the elasticsearch scripting docs

Configuring the Dashboard

tsuru-dashboard can be used to show a graphic for each metric byapplication. This configuration can be set by using some environmentvariables on the dashboard (if you are running the dashboard as a tsuru application,those can be set by tsuru env-set -a tsuru-dashboard).

ELASTICSEARCH_HOST this environment must point to your elasticsearch host.

ELASTICSEARCH_INDEX this environment must be set to “.measure-$client”, where $clientis the client name configured on big-sibling (defaults to tsuru).

It is also possible to display metrics about other containers (not only tsuru applications),collected by big-sibling (including it’s own metrics). To do so, tsuru dashboardhas an environment variable that controls what containers should have their metricsdisplayed on the Components page.

METRICS_COMPONENTS must contain a list of containers names that will have theirmetrics displayed. For example: METRICS_COMPONENTS=big-sibling, will display big-siblingcontainer metrics.

原文: https://docs.tsuru.io/1.6/advanced_topics/metrics.html