elastic / elasticsearch-metrics-reporter-java

Metrics reporter, which reports to elasticsearch
Apache License 2.0
230 stars 103 forks source link

Add an "host" field in the json sent to Elasticsearch #40

Closed YLombardi closed 8 years ago

YLombardi commented 8 years ago

Hi.

I plan to use ElasticsearchReporter on multiple servers. Is it possible to add a field "host" in the json to know which server send which metrics ?

Currently it send this :

{
  "_index": "metrology-2016-06",
  "_type": "timer",
  "_id": "AVWQsplNqBq4isHHxQPD",
  "_score": null,
  "_source": {
    "name": "MyMetrics",
    "@timestamp": "2016-06-27T07:11:12.000+0000",
    "count": 2,
    "max": 166.991269,
    "mean": 103.27135402715979,
    "min": 45.902752,
    "p50": 45.902752,
    "p75": 166.991269,
    "p95": 166.991269,
    "p98": 166.991269,
    "p99": 166.991269,
    "p999": 166.991269,
    "stddev": 60.460916659287676,
    "m1_rate": 2.964393875e-314,
    "m5_rate": 1.4821969375e-313,
    "m15_rate": 1.0686501380195562e-111,
    "mean_rate": 0.000008751477547862074,
    "duration_units": "milliseconds",
    "rate_units": "calls/second"
  },
  "fields": {
    "@timestamp": [
      1467011472000
    ]
  },
  "highlight": {
    "name": [
      "@kibana-highlighted-field@MyMetrics@/kibana-highlighted-field@"
    ]
  },
  "sort": [
    1467011472000
  ]
}

I want to add "host": serverName in the "_source" part of the json.

YLombardi commented 8 years ago

I found a solution.

In my configuration I add :

HashMap<String, Object> additionnalFields = new HashMap<>();
additionnalFields.put("host", InetAddress.getLocalHost().getHostName());
ElasticsearchReporter.additionalFields(additionnalFields);