|
1 | 1 | package scouter.plugin.server.influxdb; |
2 | 2 |
|
| 3 | +import org.influxdb.dto.Point; |
| 4 | +import scouter.lang.TimeTypeEnum; |
3 | 5 | import scouter.lang.pack.PerfCounterPack; |
4 | 6 | import scouter.lang.plugin.PluginConstants; |
5 | 7 | import scouter.lang.plugin.annotation.ServerPlugin; |
| 8 | +import scouter.lang.value.Value; |
6 | 9 | import scouter.server.Configure; |
7 | 10 |
|
| 11 | +import java.util.Map; |
| 12 | +import java.util.concurrent.TimeUnit; |
| 13 | + |
8 | 14 | /** |
9 | 15 | * @author Gun Lee (gunlee01@gmail.com) on 2016. 3. 29. |
10 | 16 | */ |
11 | 17 | public class InfluxdbPlugin { |
12 | 18 | Configure conf = Configure.getInstance(); |
13 | 19 |
|
| 20 | + final String confMeasurement = "ext_plugin_influxdb_measurement"; |
| 21 | + final String confTagObj = "ext_plugin_influxdb_tag_obj"; |
| 22 | + final String confTagTimeType = "ext_plugin_influxdb_tag_timetype"; |
| 23 | + |
| 24 | + final String confMeasurementDefault = "counter"; |
| 25 | + final String confTagObjDefault = "obj"; |
| 26 | + final String confTagTimeTypeDefault = "timetype"; |
| 27 | + |
14 | 28 | @ServerPlugin(PluginConstants.PLUGIN_SERVER_COUNTER) |
15 | 29 | public void counter(PerfCounterPack pack) { |
| 30 | + String measurementName = conf.getValue(confMeasurement, confMeasurementDefault); |
| 31 | + String objTagName = conf.getValue(confTagObj, confTagObjDefault); |
| 32 | + String timeTypeTagName = conf.getValue(confTagTimeType, confTagTimeTypeDefault); |
| 33 | + |
| 34 | + try { |
| 35 | + Point.Builder builder = Point.measurement(measurementName) |
| 36 | + .time(pack.time, TimeUnit.MILLISECONDS) |
| 37 | + .tag(objTagName, pack.objName) |
| 38 | + .tag(timeTypeTagName, TimeTypeEnum.getString(pack.timetype)); |
| 39 | + |
| 40 | + Map<String, Value> dataMap = pack.data.toMap(); |
| 41 | + for (Map.Entry<String, Value> field : dataMap.entrySet()) { |
| 42 | + Value valueOrigin = field.getValue(); |
| 43 | + if (valueOrigin == null) { |
| 44 | + continue; |
| 45 | + } |
| 46 | + Object value = valueOrigin.toJavaObject(); |
| 47 | + String key = field.getKey(); |
| 48 | + builder.field(key, value); |
| 49 | + } |
| 50 | + |
| 51 | + Point point = builder.build(); |
| 52 | + String line = point.lineProtocol(); |
| 53 | + |
| 54 | + System.out.println(line); |
16 | 55 |
|
| 56 | + } catch (Exception e) { |
| 57 | + e.getMessage(); |
| 58 | + } |
17 | 59 | } |
18 | 60 | } |
0 commit comments