首页 > 其他 > 详细

grafana elasticsearch date类型问题

时间:2017-01-22 15:25:26      阅读:465      评论:0      收藏:0      [点我收藏+]
  • 大致的数据格式
{
    "createTime": 1484967199,
    "ip": "localhost",
    "appId": "10000",
    "threadName": "Thread-acceptor-1",
    "level": "info",
    "type": "error",
    "tag": "tag1",
    "module": "module1",
    "detail": "some description"
}
  • 从kafka读取数据后由storm计算后直接将es客户端写入es。

  • 使用grafana配置数据源,其中使用自定义的字段createTime。

  • 技术分享

  • 配置grafana的dashboard的panel,结果报错,Invalid number format [epoch_millis#]

  • 是时间类型的错误,查下es字段的mapping,
http://132.122.252.22:9200/flume-index/_mapping
{
    "flume-index": {
        "mappings": {
            "distributed-log": {
                "properties": {
                    "appId": {
                        "type": "string"
                    },
                    "createTime": {
                        "type": "long"
                    },
                    "detail": {
                        "type": "string"
                    },
                    "ip": {
                        "type": "string"
                    },
                    "level": {
                        "type": "string"
                    },
                    "module": {
                        "type": "string"
                    },
                    "tag": {
                        "type": "string"
                    },
                    "threadName": {
                        "type": "string"
                    },
                    "type": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

没有指定es的mapping,所以根据java类型,当storm推数据到es时则会当做long型,具体格式如下,这导致grafana根据createTime查询错误,需要更改createTime的mapping。

  • 先删除原来的索引,
curl -XDELETE ‘localhost:9200/flume-index/?pretty‘
  • 再重新建立新索引,且指定createTime字段为date类型,且格式为默认即可。
curl -XPUT ‘localhost:9200/flume-index/?pretty‘ -d 
‘
{
    "mappings": {
        "distributed-log": {
            "properties": {
                "appId": {
                    "type": "string"
                },
                "createTime": {
                    "type": "date"
                },
                "detail": {
                    "type": "string"
                },
                "ip": {
                    "type": "string"
                },
                "level": {
                    "type": "string"
                },
                "module": {
                    "type": "string"
                },
                "tag": {
                    "type": "string"
                },
                "threadName": {
                    "type": "string"
                },
                "type": {
                    "type": "string"
                }
            }
        }
    }
}
‘
  • 再用json的字符串格式传入后,es即可以通过这个mapping进行转换。grafana也可以根据时间查出数据来。

  • 如果允许也可以直接使用es的_timestamp字段,但它并非准确的数据生成时间。es默认没有开启timestamp的记录,可以用下面开启,即有了_timestamp字段。

curl -XPOST localhost:9200/flume-index -d ‘
{
    "mappings": {
        "_default_": {
            "_timestamp": {
                "enabled": true
            }
        }
    }
}
‘

grafana elasticsearch date类型问题

原文:http://blog.csdn.net/wangyangzhizhou/article/details/54666394

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!