class OpentsdbConverter {

    public static Metric convertToModel(JSONObject json) {

        Metric m = new Metric();
        // opentsdb时间戳单位是秒
        m.setTimestamp(json.getLongValue("timestamp") * 1000L);
        m.setName(json.getString("metric"));
        m.setValue(json.getDoubleValue("value"));
        Map<String, String> mtags = m.getTags();

        JSONObject tags = json.getJSONObject("tags");
        if (tags != null) {
            for (Map.Entry<String, Object> e : tags.entrySet()) {
                String key = MetricUtils.formatMetricTagKey(e.getKey());
                String value = MetricUtils.formatTagValue(e.getValue().toString());
                mtags.put(key, value);
            }
        }

        return m;
    }

    private  OpentsdbConverter();

}