mirror of
https://github.com/nicolargo/glances.git
synced 2024-11-28 05:42:57 +03:00
Merge pull request #1438 from genevera/elasticsearch-fix
add date to index, unbreak object push
This commit is contained in:
commit
57597aa0cc
@ -57,6 +57,38 @@ class Export(GlancesExport):
|
|||||||
if not self.export_enable:
|
if not self.export_enable:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
self.index='{}-{}'.format(self.index, datetime.utcnow().strftime("%Y.%m.%d"))
|
||||||
|
template_body = {
|
||||||
|
"mappings": {
|
||||||
|
"glances": {
|
||||||
|
"dynamic_templates": [
|
||||||
|
{
|
||||||
|
"integers": {
|
||||||
|
"match_mapping_type": "long",
|
||||||
|
"mapping": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"strings": {
|
||||||
|
"match_mapping_type": "string",
|
||||||
|
"mapping": {
|
||||||
|
"type": "text",
|
||||||
|
"fields": {
|
||||||
|
"raw": {
|
||||||
|
"type": "keyword",
|
||||||
|
"ignore_above": 256
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
es = Elasticsearch(hosts=['{}:{}'.format(self.host, self.port)])
|
es = Elasticsearch(hosts=['{}:{}'.format(self.host, self.port)])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -70,7 +102,7 @@ class Export(GlancesExport):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Index did not exist, it will be created at the first write
|
# Index did not exist, it will be created at the first write
|
||||||
# Create it...
|
# Create it...
|
||||||
es.indices.create(self.index)
|
es.indices.create(index=self.index,body=template_body)
|
||||||
else:
|
else:
|
||||||
logger.info("There is already %s entries in the ElasticSearch %s index" % (index_count, self.index))
|
logger.info("There is already %s entries in the ElasticSearch %s index" % (index_count, self.index))
|
||||||
|
|
||||||
@ -84,15 +116,19 @@ class Export(GlancesExport):
|
|||||||
# https://elasticsearch-py.readthedocs.io/en/master/helpers.html
|
# https://elasticsearch-py.readthedocs.io/en/master/helpers.html
|
||||||
actions = []
|
actions = []
|
||||||
for c, p in zip(columns, points):
|
for c, p in zip(columns, points):
|
||||||
|
dtnow = datetime.utcnow()
|
||||||
action = {
|
action = {
|
||||||
"_index": self.index,
|
"_index": self.index,
|
||||||
"_type": name,
|
"_id": '{}.{}'.format(name,c),
|
||||||
"_id": c,
|
"_type": "glances",
|
||||||
"_source": {
|
"_source": {
|
||||||
|
"plugin": name,
|
||||||
|
"metric": c,
|
||||||
"value": str(p),
|
"value": str(p),
|
||||||
"timestamp": datetime.now()
|
"utc_datetime": dtnow.isoformat('T')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.debug("Exporting the following object to elasticsearch: {}".format(action))
|
||||||
actions.append(action)
|
actions.append(action)
|
||||||
|
|
||||||
# Write input to the ES index
|
# Write input to the ES index
|
||||||
|
Loading…
Reference in New Issue
Block a user