-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2117 from pauljevans/pevans-merge
pcp2elasticsearch: support dynamic mapping
- Loading branch information
Showing
3 changed files
with
21 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/usr/bin/env pmpython | ||
# | ||
# Copyright (C) 2015-2021 Marko Myllynen <[email protected]> | ||
# Copyright (C) 2014-2018,2022 Red Hat. | ||
# Copyright (C) 2014-2018,2025 Red Hat. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License as published by the | ||
|
@@ -47,7 +47,7 @@ | |
CONFVER = 1 | ||
ES_SERVER = "http://localhost:9200/" | ||
ES_INDEX = "pcp" | ||
ES_SEARCH_TYPE = "pcp-metric" | ||
ES_SEARCH_TYPE = "_doc" | ||
|
||
class pcp2elasticsearch(object): | ||
""" PCP to Elasticsearch """ | ||
|
@@ -429,26 +429,6 @@ def write_es(self, timestamp): | |
|
||
ts = self.context.datetime_to_secs(self.pmfg_ts(), PM_TIME_MSEC) | ||
|
||
try: | ||
body = {'ignore': 400, | ||
'mappings': {'pcp-metric': | ||
{'properties':{'@timestamp':{'type':'epoch_milli'}, | ||
'@host-id':{'type':'string'}}}}} | ||
data = json.dumps(body).encode('utf-8') | ||
headers = {'content-type': 'application/json'} | ||
url = self.es_server + '/' + self.es_index | ||
req = httprequest.Request(url=url, data=data, headers=headers, method='PUT') | ||
with httprequest.urlopen(req) as f: | ||
f.close() | ||
if self.es_failed: | ||
sys.stderr.write("Reconnected to Elasticsearch server %s.\n" % (self.es_server)) | ||
self.es_failed = False | ||
except Exception as put_failed: | ||
if not self.es_failed: | ||
sys.stderr.write("Cannot connect to Elasticsearch server %s: %s, continuing.\n" % (self.es_server, str(put_failed))) | ||
self.es_failed = True | ||
return | ||
|
||
# Assemble all metrics into a single document | ||
# Use @-prefixed keys for metadata not coming in from PCP metrics | ||
es_doc = {'@host-id': self.es_hostid, '@timestamp': long(ts)} | ||
|
@@ -514,8 +494,9 @@ def write_es(self, timestamp): | |
insts.append({inst_key: name, last_part: value}) | ||
|
||
try: | ||
headers = {'content-type': 'application/json'} | ||
data = json.dumps(es_doc).encode('utf-8') | ||
url = self.es_server + '/' + self.es_index + '/' + self.es_search_type | ||
url = self.es_server + self.es_index + '/' + self.es_search_type | ||
req = httprequest.Request(url=url, data=data, headers=headers, method='POST') | ||
with httprequest.urlopen(req) as f: | ||
f.close() | ||
|