mirror of
https://github.com/nicolargo/glances.git
synced 2024-11-24 13:23:12 +03:00
use dynamic templating for values, clean up fields some more
This commit is contained in:
parent
5bf7069053
commit
b7041b3acb
@ -57,7 +57,38 @@ class Export(GlancesExport):
|
||||
if not self.export_enable:
|
||||
return None
|
||||
|
||||
self.index='{}-{}'.format(self.index, datetime.today().strftime("%Y.%m.%d"))
|
||||
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:
|
||||
es = Elasticsearch(hosts=['{}:{}'.format(self.host, self.port)])
|
||||
except Exception as e:
|
||||
@ -71,7 +102,7 @@ class Export(GlancesExport):
|
||||
except Exception as e:
|
||||
# Index did not exist, it will be created at the first write
|
||||
# Create it...
|
||||
es.indices.create(self.index)
|
||||
es.indices.create(index=self.index,body=template_body)
|
||||
else:
|
||||
logger.info("There is already %s entries in the ElasticSearch %s index" % (index_count, self.index))
|
||||
|
||||
@ -85,15 +116,17 @@ class Export(GlancesExport):
|
||||
# https://elasticsearch-py.readthedocs.io/en/master/helpers.html
|
||||
actions = []
|
||||
for c, p in zip(columns, points):
|
||||
dtnow = datetime.utcnow()
|
||||
action = {
|
||||
"_index": self.index,
|
||||
"_id": c,
|
||||
"_type": "glances",
|
||||
"_source": {
|
||||
"name": name,
|
||||
"plugin": name,
|
||||
"metric": c,
|
||||
"value": str(p),
|
||||
"type": "keyword",
|
||||
"timestamp": datetime.now()
|
||||
"_timestamp": dtnow.timestamp(),
|
||||
"timestamp": dtnow.isoformat()
|
||||
}
|
||||
}
|
||||
logger.debug("Exporting the following object to elasticsearch: {}".format(action))
|
||||
|
Loading…
Reference in New Issue
Block a user