通过elasticsearch批量创建kibana的visualize图表及dashboard

kibana中展示的visualize图表及dashboard,是保存在Elasticsearch的kibana-int索引的dashboard类型中的(以kibana3来说明)。

下面获取一保存的一个dashboard

GET http://localhost:9200/kibana-int/dashboard/skytone.optlog

{
    "_index": "kibana-int",
    "_type": "dashboard",
    "_id": "skytone.optlog",
    "_version": 11,
    "found": true,
    "_source": {
        "user": "guest",
        "group": "guest",
        "title": "skytone.optlog",
        "dashboard": "xxx"
    }
}

其中,dashboard字段中保存着具体的kibana中展示的具体的内容,可以参照着kibana的界面设置,很容易明白其实信息的含义的:

{
    "title": "skytone.optlog",
    "services": { "query": { "list": { "0": { "query": "*", "alias": "", "color": "#7EB26D", "id": 0, "pin": false, "type": "lucene", "enable": true } }, "ids": [ 0 ] }, "filter": { "list": { "0": { "type": "time", "field": "@timestamp", "from": "now-24h", "to": "now", "mandate": "must", "active": true, "alias": "", "id": 0 }, "1": { "type": "querystring", "query": "_type=skytone_optlog", "mandate": "must", "active": true, "alias": "", "id": 1 } }, "ids": [ 0, 1 ] } },
    "rows": [ { "title": "Graph", "height": "350px", "editable": true, "collapse": true, "collapsable": true, "panels": [ { "span": 12, "editable": true, "group": [ "default" ], "type": "histogram", "mode": "count", "time_field": "@timestamp", "value_field": null, "auto_int": true, "resolution": 100, "interval": "10m", "fill": 3, "linewidth": 3, "timezone": "browser", "spyable": true, "zoomlinks": true, "bars": true, "stack": true, "points": false, "lines": false, "legend": true, "x-axis": true, "y-axis": true, "percentage": false, "interactive": true, "queries": { "mode": "all", "ids": [ 0 ] }, "title": "Events over time", "intervals": [ "auto", "1s", "1m", "5m", "10m", "30m", "1h", "3h", "12h", "1d", "1w", "1M", "1y" ], "options": true, "tooltip": { "value_type": "cumulative", "query_as_alias": true }, "scale": 1, "y_format": "none", "grid": { "max": null, "min": 0 }, "annotate": { "enable": false, "query": "*", "size": 20, "field": "_type", "sort": [ "_score", "desc" ] }, "pointradius": 5, "show_query": true, "legend_counts": true, "zerofill": true, "derivative": false } ], "notice": false }, { "title": "Events", "height": "350px", "editable": true, "collapse": false, "collapsable": true, "panels": [ { "title": "All events", "error": false, "span": 12, "editable": true, "group": [ "default" ], "type": "table", "size": 100, "pages": 5, "offset": 0, "sort": [ "optid", "desc" ], "style": { "font-size": "9pt" }, "overflow": "min-height", "fields": [ "optime", "optid", "opcode", "cardno", "callno", "result_code", "jsonreq", "jsonrep", "extras" ], "localTime": true, "timeField": "@timestamp", "highlight": [], "sortable": true, "header": true, "paging": true, "spyable": true, "queries": { "mode": "all", "ids": [ 0 ] }, "field_list": false, "status": "Stable", "trimFactor": 300, "normTimes": true, "all_fields": false } ], "notice": false } ],
    "editable": true,
    "failover": false,
    "index": { "interval": "day", "pattern": "[logstash-]YYYY.MM.DD", "default": "NO_TIME_FILTER_OR_INDEX_PATTERN_NOT_MATCHED", "warm_fields": true },
    "style": "light",
    "panel_hints": true,
    "pulldowns": [ { "type": "query", "collapse": false, "notice": false, "query": "*", "pinned": true, "history": [ "*", "optid=9157" ], "remember": 10, "enable": true }, { "type": "filtering", "collapse": true, "notice": false, "enable": true } ],
    "nav": [ { "type": "timepicker", "collapse": false, "notice": false, "status": "Stable", "time_options": [ "5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d" ], "refresh_intervals": [ "5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d" ], "timefield": "@timestamp", "now": true, "filter_id": 0, "enable": true } ],
    "loader": { "save_gist": false, "save_elasticsearch": true, "save_local": true, "save_default": true, "save_temp": true, "save_temp_ttl_enable": true, "save_temp_ttl": "30d", "load_gist": true, "load_elasticsearch": true, "load_elasticsearch_size": 20, "load_local": true, "hide": false },
    "refresh": "5m" }

因此,如果有大量的类型的dashboard需要添加的话,可以用工具或脚本调用http rest api来向kibana-int/dashboard中添加上面格式的文档就可以了。

下面增加一个新的dashboard,skytone.optlog2

POST  http://localhost:9200/kibana-int/dashboard/skytone.optlog2
{
    "user": "guest",
    "group": "guest",
    "title": "skytone.optlog2",
    "dashboard": "XXXX"  //就是上面GET出来的内容,见于篇副省略了
}

更详细的请参见:http://xiaorui.cc/?p=1570

你可能感兴趣的:(elasticsearch)