use of com.creditease.agent.monitor.api.MonitorDataFrame in project uavstack by uavorg.
the class NodeInfoDataAdapter method prepareInsertObj.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Object prepareInsertObj(DataStoreMsg msg, DataStoreConnection connection) {
boolean isDataStoreOK = (this.dataSource.getAvalibleAddressEntry() == null) ? false : true;
// OpenTSDB points list
List<Map<String, ?>> points = new ArrayList<Map<String, ?>>();
/**
* 消息message传输过来的MDF是一个列表包含多个MDF的json字符串
*/
// parse MDF list
String monitorDataFramesStr = (String) msg.get(MonitorDataFrame.MessageType.NodeInfo.toString());
List<String> monitorDataFrames = JSONHelper.toObjectArray(monitorDataFramesStr, String.class);
for (String mdfStr : monitorDataFrames) {
// 反序列化为MonitorDataFrame
MonitorDataFrame mdf = new MonitorDataFrame(mdfStr);
// get all frames
Map<String, List<Map>> frames = mdf.getDatas();
for (String monitorId : frames.keySet()) {
List<Map> monitorDatas = frames.get(monitorId);
for (Map monitorData : monitorDatas) {
String meId = (String) monitorData.get("MEId");
List<Map> instances = (List<Map>) monitorData.get("Instances");
for (Map instance : instances) {
// get instance id
String instanceId = (String) instance.get("id");
// get instance fields
Map<String, Object> fields = (Map<String, Object>) instance.get("values");
/**
* FAST Failure: if there is no available address, we may not go to DataStore part
*/
if (isDataStoreOK == false) {
if (log.isDebugEnable() == true) {
log.debug(this, "Skip MonitorData INSERT as no available address");
}
continue;
}
/**
* prepare the inst's metic data for opentsdb
*/
for (String key : fields.keySet()) {
Map<String, Object> point = new LinkedHashMap<String, Object>();
String mkey = key;
if (mkey.indexOf("cpu") < 0 && mkey.indexOf("conn") < 0 && mkey.indexOf("os.io.disk.") < 0 && mkey.indexOf("cpu") < 0 && mkey.indexOf("disk") != 0 && mkey.indexOf("in") != 0 && mkey.indexOf("out") != 0 && mkey.indexOf("mem") != 0) {
continue;
}
/**
* NOTE: os.io.disk.*,conn_*,in_*,out_* . they are dynamic tags, so make the metric key as
* "XX" add a new tag "ptag" as the last tag
*/
String plusTag = null;
if (key.indexOf("os.io.disk") == 0) {
mkey = "os.io.disk";
plusTag = key;
} else if (key.indexOf("conn_") == 0) {
mkey = "conn_port";
plusTag = key;
} else if (key.indexOf("in_") == 0) {
mkey = "in_port";
plusTag = key;
} else if (key.indexOf("out_") == 0) {
mkey = "out_port";
plusTag = key;
}
/**
* WRITE DATA Schema Sample:
*
* {
*
* metric: procStat.cpu,
*
* timestamp: 1463816026510,
*
* value: 4,
*
* tags:[
*
* ip: 127.0.0.1,
*
* pgid: mongo.exe,
*
* instid: 127.0.0.1_mongo.exe_3342,
*
* ptag(optional): os.io.disk.home.useRate
*
* ]
*
* }
*/
point.put("metric", meId + "." + mkey);
point.put("timestamp", mdf.getTimeFlag());
double value;
try {
value = Double.parseDouble((String) fields.get(key));
} catch (NumberFormatException e) {
continue;
}
point.put("value", value);
point.put("tags", createTags(mdf, instanceId, meId, plusTag, fields));
points.add(point);
}
}
}
}
}
return points;
}
use of com.creditease.agent.monitor.api.MonitorDataFrame in project uavstack by uavorg.
the class ProfileDataAdpater method prepareInsertObj.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object prepareInsertObj(DataStoreMsg msg, DataStoreConnection connection) {
List<Map<String, Object>> documents = new ArrayList<Map<String, Object>>();
/**
* 消息message传输过来的MDF是一个列表包含多个MDF的json字符串
*/
// parse MDF list
String monitorDataFramesStr = (String) msg.get(MonitorDataFrame.MessageType.Profile.toString());
List<String> monitorDataFrames = JSONHelper.toObjectArray(monitorDataFramesStr, String.class);
for (String mdfStr : monitorDataFrames) {
mdfStr = DataStoreHelper.encodeForMongoDB(mdfStr);
// 反序列化为MonitorDataFrame
MonitorDataFrame mdf = new MonitorDataFrame(mdfStr);
// get all frames
Map<String, List<Map>> frames = mdf.getDatas();
for (String appid : frames.keySet()) {
List<Map> appDatas = frames.get(appid);
for (Map appData : appDatas) {
// get PEId
String peId = (String) appData.get("PEId");
List<Map> instances = (List<Map>) appData.get("Instances");
for (Map instance : instances) {
// get instance id
String instanceId = (String) instance.get("id");
// get instance fields
Map<String, Object> fields = (Map<String, Object>) instance.get("values");
// convert Map to List for Mongo Query
List<Object> listValues = new ArrayList<Object>();
for (Object key : fields.keySet()) {
// get fieldValue
Object fieldValue = fields.get(key);
Map<String, Object> values = new LinkedHashMap<String, Object>();
values.put("id", key.toString());
values.put("value", fieldValue);
listValues.add(values);
}
// build instance info MAP
Map<String, Object> instanceInfo = new LinkedHashMap<String, Object>();
instanceInfo.put("id", instanceId);
instanceInfo.put("values", listValues);
// build document
Map<String, Object> document = new LinkedHashMap<String, Object>();
document.put("time", mdf.getTimeFlag());
document.put("host", mdf.getHost());
document.put("ip", mdf.getIP());
document.put("svrid", mdf.getServerId());
document.put("appid", appid);
document.put("peid", peId);
document.put("inst", instanceInfo);
documents.add(document);
}
}
}
}
return documents;
}
use of com.creditease.agent.monitor.api.MonitorDataFrame in project uavstack by uavorg.
the class ProfileDataMessageHandler method pushLatestProfileDataToCacheCenter.
/**
* 推送最新的ProfileData到缓存中心
*
* @param profileString
*/
private List<String> pushLatestProfileDataToCacheCenter(String profileString) {
/**
* setup ProfileDataMessageHandler as IStandardProfileModelListener for StandardProfileModeler
*/
ISystemActionEngineMgr engineMgr = (ISystemActionEngineMgr) ConfigurationManager.getInstance().getComponent("Global", "ISystemActionEngineMgr");
IActionEngine engine = engineMgr.getActionEngine("StandardProfileModelingEngine");
StandardProfileModeler modeler = (StandardProfileModeler) ConfigurationManager.getInstance().getComponent("healthmanager", "StandardProfileModeler");
modeler.setListener(this);
cm.beginBatch();
List<String> monitorDataFrames = JSONHelper.toObjectArray(profileString, String.class);
List<String> newMDFs = new ArrayList<String>();
for (String mdfStr : monitorDataFrames) {
MonitorDataFrame mdf = new MonitorDataFrame(mdfStr);
ActionContext ac = new ActionContext();
ac.putParam(MonitorDataFrame.class, mdf);
ac.putParam("NewMDFList", newMDFs);
ac.putParam("MDFString", mdfStr);
engine.execute("StandardProfileModeler", ac);
}
cm.submitBatch();
return newMDFs;
}
use of com.creditease.agent.monitor.api.MonitorDataFrame in project uavstack by uavorg.
the class JMXAppServerMonitorDataCatchWorker method run.
@Override
public void run() {
try {
boolean needProcessCheck = true;
long timeFlag = (System.currentTimeMillis() / 10) * 10;
// get all monitor's MBean
MonitorDataFrame mdf = new MonitorDataFrame(this.getWorkerId(), "M", timeFlag);
needProcessCheck = doCaptureMonitorData(mbsc, timeFlag, mdf);
// if needProcessCheck is still true, need see if the appserver is still alive
if (needProcessCheck == true) {
doHealthReaction();
return;
} else {
/**
* if there is data, we handle MDF using monitor data handler to process the monitor data
*/
if (!mdf.isEmpty()) {
List<MonitorDataFrame> ml = new ArrayList<MonitorDataFrame>();
ml.add(mdf);
this.detector.runHandlers(ml);
}
}
// get all profile's MBean
MonitorDataFrame pmdf = new MonitorDataFrame(this.getWorkerId(), "P", timeFlag);
needProcessCheck = doCaptureProfileData(mbsc, timeFlag, pmdf);
// if needProcessCheck is still true, need see if the appserver is still alive
if (needProcessCheck == true) {
doHealthReaction();
return;
} else {
/**
* if there is data, we handle MDF
*/
if (!pmdf.isEmpty()) {
/**
* as profile data is low frequency data, then we just need 1 thread for all appservers on the same
* host machine to publish the data
*/
AppServerProfileDataCatchWorker apdc = (AppServerProfileDataCatchWorker) this.getConfigManager().getComponent(this.feature, "AppServerProfileDataCatchWorker");
apdc.putData(pmdf);
}
}
} catch (IOException e) {
// if connect fails, try process detecting
doHealthReaction();
}
}
use of com.creditease.agent.monitor.api.MonitorDataFrame in project uavstack by uavorg.
the class JMXJavaMonitorDataCatchWorker method doCaptureMonitorData.
/**
* --------------------------------------------Monitor Data----------------------------------------------------
*/
/**
* TODO: doCaptureMonitorData
*
* @param timeFlag
* @param mbsc
* @return needProcessCheck
*/
private boolean doCaptureMonitorData(long timeFlag, MBeanServerConnection mbsc) {
StandardMonitorRepository smr = new StandardMonitorRepository();
// MEId: jvm
if (doCaptureMO_JVM(mbsc, smr) == true) {
return true;
}
// 自定义指标 goes to jvm
doCaptureMO_CustomizedMetrics(smr);
// UAV MSCP Application
doCaptureMO_MSCPApp(smr);
// build MDF
MonitorDataFrame mdf = new MonitorDataFrame(this.getWorkerId(), "M", timeFlag);
mdf.addData("server", smr.toJSONString());
// add appgroup to MDF
mdf.addExt("appgroup", this.getAppGroup());
/**
* if there is data, we handle MDF using monitor data handler to process the monitor data
*/
if (!mdf.isEmpty()) {
List<MonitorDataFrame> ml = new ArrayList<MonitorDataFrame>();
ml.add(mdf);
this.detector.runHandlers(ml);
}
return false;
}
Aggregations