use of com.creditease.agent.monitor.api.MonitorDataFrame in project uavstack by uavorg.
the class JMXJavaMonitorDataCatchWorker method doCaptureProfileData.
/**
* --------------------------------------------Profile Data----------------------------------------------------
*/
/**
* TODO: doCaptureProfileData
*
* every 1 minute to send the profile data as heartbeat
*
* @param timeFlag
*/
private void doCaptureProfileData(long timeFlag) {
MonitorDataFrame pmdf = new MonitorDataFrame(this.getWorkerId(), "P", timeFlag);
if (state.getProfileTimestamp() == 0) {
state.setProfileTimestamp(System.currentTimeMillis());
} else {
long curTime = System.currentTimeMillis();
if (curTime - state.getProfileTimestamp() < profileHBTimeout) {
return;
}
pmdf.setTag("P:HB");
state.setProfileTimestamp(curTime);
}
// get Profile MDF
this.buildProfileMDF(pmdf);
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);
}
}
use of com.creditease.agent.monitor.api.MonitorDataFrame in project uavstack by uavorg.
the class MDFListenServerHandler method handle.
@SuppressWarnings("rawtypes")
@Override
public void handle(UAVHttpMessage data) {
try {
String body = data.getRequest(UAVHttpMessage.BODY);
List<MonitorDataFrame> mdfs = new ArrayList<MonitorDataFrame>();
// MDF array
if (body.indexOf("[") == 0) {
List<Map> mdfList = JSONHelper.toObjectArray(body, Map.class);
for (Map mdfMap : mdfList) {
MonitorDataFrame mdf = new MonitorDataFrame(mdfMap);
mdfs.add(mdf);
}
} else // MDF
{
MonitorDataFrame mdf = new MonitorDataFrame(body);
mdfs.add(mdf);
}
// send MDFs
MonitorDataPublishHandler mdph = (MonitorDataPublishHandler) this.getConfigManager().getComponent(this.feature, "MonitorDataPublishHandler");
mdph.handle(mdfs);
data.putResponse(UAVHttpMessage.RESULT, "OK");
} catch (Exception e) {
data.putResponse(UAVHttpMessage.ERR, e.getMessage());
}
}
use of com.creditease.agent.monitor.api.MonitorDataFrame in project uavstack by uavorg.
the class StandardProfileModeler method doAction.
@SuppressWarnings("rawtypes")
@Override
public void doAction(ActionContext context) throws Exception {
MonitorDataFrame mdf = context.getParam(MonitorDataFrame.class);
/**
* onBeforeMDFModeling
*/
this.listener.onBeforeMDFModeling(context, mdf);
/**
* Step 1: build all profile node info
*/
Map<String, List<Map>> frames = mdf.getDatas();
for (String appid : frames.keySet()) {
/**
* onBeforeFrameModeling
*/
this.listener.onBeforeFrameModeling(context, mdf, appid, frames.get(appid));
Map<String, Object> appProfile = new LinkedHashMap<String, Object>();
/**
* 1.1 basic info of the application
*/
Map<String, Object> values = mdf.getElemInstValues(appid, "cpt", "webapp");
String appurl = (String) values.get("appurl");
/**
* appgroup
*/
String appgroup = "";
if (values.containsKey("appgroup")) {
appgroup = (String) values.get("appgroup");
}
/**
* appdes from web.xml's description {org:"owner info"}
*/
String appdes = "";
if (values.containsKey("appdes")) {
appdes = (String) values.get("appdes");
}
/**
* appmetrics
*/
String appmetrics = "";
if (values.containsKey("appmetrics")) {
appmetrics = JSONHelper.toString(values.get("appmetrics"));
}
/**
* appName
*/
String appName = (String) values.get("appname");
/**
* app root
*/
String appRoot = (String) values.get("webapproot");
/**
* MOF metadata
*/
String mofMeta = "";
if (values.containsKey("mofmeta")) {
mofMeta = JSONHelper.toString(values.get("mofmeta"));
}
appProfile.put("appid", appid);
appProfile.put("ip", mdf.getIP());
appProfile.put("svrid", mdf.getServerId());
appProfile.put("host", mdf.getHost());
appProfile.put("time", mdf.getTimeFlag());
appProfile.put("appname", appName);
appProfile.put("appdes", appdes);
appProfile.put("appmetrics", appmetrics);
appProfile.put("appgroup", appgroup);
appProfile.put("webapproot", appRoot);
appProfile.put("appurl", appurl);
appProfile.put("mofmeta", mofMeta);
this.listener.onAppProfileMetaCreate(context, mdf, appid, appurl, appgroup, appProfile);
/**
* step 1.2: cache the application clients profile data
*/
String clientsJSONstr = createAppClientProfileData(context, mdf, appid, appurl, appgroup, appProfile);
/**
* Step 1.3 cache the application profile data
*/
createAppProfileData(context, mdf, appProfile, clientsJSONstr, appid, appurl, appgroup);
/**
* step 1.4: cache application ip_link & access data
*/
createAppIPLinkProfileData(context, mdf, appid, appurl, appgroup, appProfile);
/**
* onAfterFrameModeling
*/
this.listener.onAfterFrameModeling(context, mdf, appid, frames.get(appid), appProfile);
}
/**
* onAfterMDFModeling
*/
this.listener.onAfterMDFModeling(context, mdf);
context.setSucessful(true);
}
use of com.creditease.agent.monitor.api.MonitorDataFrame in project uavstack by uavorg.
the class NodeInfoWatcher method syncProcInfoToCache.
/**
* nodeInfo数据转为list返回并将判断进程死亡所用的K、V存入redis
*/
@SuppressWarnings("rawtypes")
private List<Map<String, Object>> syncProcInfoToCache(Map<String, String> data) {
List<Map<String, Object>> mdflist = new ArrayList<>();
Map<String, String> fieldValues = new HashMap<String, String>();
Map<String, String> fieldValuesDetail = new HashMap<String, String>();
for (String node : data.values()) {
Map<String, Object> mdfMap = buildMDF(node);
MonitorDataFrame mdf = new MonitorDataFrame(mdfMap);
String time = mdf.getTimeFlag() + "";
List<Map> els = mdf.getElemInstances("server", "procState");
for (Map el : els) {
try {
String group = mdf.getExt("appgroup");
String ip = mdf.getIP();
@SuppressWarnings("unchecked") Map<String, Object> m = (Map<String, Object>) el.get("values");
String hashKey = genProcHashKey(ip, m);
// 分别存时间戳和group
fieldValues.put(hashKey, time);
fieldValuesDetail.put(hashKey, group);
} catch (Exception e) {
log.err(this, "Sync ProcInfo To Cache Fail." + " ProcInfo:" + JSONHelper.toString(el), e);
}
}
mdflist.add(mdfMap);
}
cm.putHash(UAV_CACHE_REGION, CRASH_PROCS, fieldValues);
cm.putHash(UAV_CACHE_REGION, CRASH_PROCS_DETAIL, fieldValuesDetail);
if (log.isDebugEnable()) {
log.debug(this, "NodeInfoWatcher SYNC Node Data to Cache: data size=" + mdflist.size());
}
return mdflist;
}
use of com.creditease.agent.monitor.api.MonitorDataFrame in project uavstack by uavorg.
the class LogDataAdapter method prepareInsertObj.
/**
* [ { time:1464248773620, host:"09-201211070016", ip:"127.0.0.1",
* svrid:"F:/testenv/apache-tomcat-7.0.65---F:/testenv/apache-tomcat-7.0.65", tag:"L", frames:{ "ccsp":[ {
* "MEId":"log", "Instances":[ { "id":"F:/testenv/apache-tomcat-7.0.65/logs/ccsp.log", "values":{ "content":[ {
* "content":"2016-localhost-startStop-1INFORootWebApplicationContext:initializationstarted",
* "_timestamp":"1212345678129", "_lnum" : "123" } ] } }, { "id":"/ccsp/log_error.log", "values":{ "content":[
* {"content":"xxxxxxxxxx", "_timestamp":"1212345678129", "_lnum" : "123"} ] } } ] } ] } } ]
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object prepareInsertObj(DataStoreMsg msg, DataStoreConnection connection) {
String data = (String) msg.get(MonitorDataFrame.MessageType.Log.toString());
List<String> array = JSONHelper.toObjectArray(data, String.class);
Map<byte[], Map> ops = new HashMap<byte[], Map>();
Map<byte[], Long> ops_timestamp = new HashMap<byte[], Long>();
for (String mdfStr : array) {
long ip = 0;
byte[] svrid = null;
@SuppressWarnings("unused") byte[] timestamp = null;
// 反序列化为MonitorDataFrame
MonitorDataFrame mdf = new MonitorDataFrame(mdfStr);
ip = createipRowkey(mdf.getIP());
svrid = createRowkey(mdf.getServerId());
timestamp = toBytes(mdf.getTimeFlag());
Map<String, List<Map>> frames = mdf.getDatas();
for (String appid : frames.keySet()) {
// appid = ((String) entry).split(",", 2);
List<Map> applogs = frames.get(appid);
for (Map applog : applogs) {
List<Map> instances = (List<Map>) applog.get("Instances");
for (Map instance : instances) {
// get instance id
String logid = (String) instance.get("id");
// get instance fields
Map<String, Object> fields = (Map<String, Object>) instance.get("values");
List<Map> logs = (List<Map>) fields.get("content");
Map cklogs = null;
// --------------------------------------------------
for (int j = 0; j < logs.size(); j++) {
Map log = logs.get(j);
cklogs = new HashMap();
// byte[] rowkey = merge(createRowkey(appid), timestamp, toBytes(ip),
// svrid,createRowkey(logid));
long stamp = 0;
long num = 0;
for (Object lentry : log.keySet()) {
// 当出现_timestamp时,需要记录为定制时间戳
if ("_timestamp".equals(lentry) && StringHelper.isNumeric((String) log.get(lentry))) {
stamp = Long.parseLong((String) log.get(lentry));
continue;
}
// 当出现_lnum时,记录行号并加入rowkey
if ("_lnum".equals(lentry) && StringHelper.isNumeric((String) log.get(lentry))) {
num = Long.parseLong((String) log.get(lentry));
// rowkey = merge(rowkey, toBytes(Long.parseLong(num)));
}
// cf:k字段写入实际值
cklogs.put("cf:" + lentry, log.get(lentry));
}
byte[] rowkey = merge(createRowkey(appid), toBytes(stamp), toBytes(ip), svrid, createRowkey(logid), toBytes(num));
ops.put(rowkey, cklogs);
if (stamp != 0) {
ops_timestamp.put(rowkey, stamp);
}
}
// ------------------------------------------------------------
}
}
}
}
return new Map[] { ops, ops_timestamp };
}
Aggregations