Java Code Examples for org.ho.yaml.Yaml#loadType()
The following examples show how to use
org.ho.yaml.Yaml#loadType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TomcatConfigReadin.java From bestconf with Apache License 2.0 | 5 votes |
private static HashMap loadYamlToHashMap(String filePath) { HashMap hashmap = null; File f = new File(filePath); try { hashmap = Yaml.loadType(new FileInputStream(f.getAbsolutePath()), HashMap.class); } catch (FileNotFoundException e) { e.printStackTrace(); } return hashmap; }
Example 2
Source File: ElasticSearchPlugin.java From OpenFalcon-SuitAgent with Apache License 2.0 | 4 votes |
/** * 插件监控的服务正常运行时的內建监控报告 * 若有些特殊的监控值无法用配置文件进行配置监控,可利用此方法进行硬编码形式进行获取 * 注:此方法只有在监控对象可用时,才会调用,并加入到监控值报告中,一并上传 * * @param metricsValueInfo 当前的JMXMetricsValueInfo信息 * @return */ @Override public Collection<FalconReportObject> inbuiltReportObjectsForValid(JMXMetricsValueInfo metricsValueInfo) { // 指定配置中配置的监控值 int pid = metricsValueInfo.getJmxConnectionInfo().getPid(); Set<FalconReportObject> result = new HashSet<>(); String configPath = pluginDir + File.separator + metricsConfFile; try { String selfNodeId = ElasticSearchConfig.getNodeId(pid); String selfNodeName = ElasticSearchConfig.getNodeName(pid); if(StringUtils.isEmpty(selfNodeId) || StringUtils.isEmpty(selfNodeName)){ log.error("获取es:{} 的服务信息失败",metricsValueInfo.getJmxConnectionInfo().getName()); }else{ HashMap<String,Object> confMap = Yaml.loadType(new FileInputStream(configPath),HashMap.class); if(confMap != null){ for (String key : confMap.keySet()) { String urlSuffix = key.substring(0,key.lastIndexOf('.')); String url = ElasticSearchConfig.getConnectionUrl(pid) + "/" + urlSuffix; Map<String,String> config = (Map<String, String>) confMap.get(key); String method = config.get("method"); String metrics = config.get("metrics"); String valuePath = config.get("valuePath").replace("{selfNodeId}",selfNodeId).replace("{selfNodeName}",selfNodeName); String counterType = config.get("counterType"); String valueExpress = config.get("valueExpress"); String tag = config.get("tag"); if("get".equalsIgnoreCase(method)){ String responseText = HttpUtil.get(url).getResult(); JSONObject jsonObject = JSONObject.parseObject(responseText); if(jsonObject != null){ String[] paths = valuePath.split("\\."); for(int i=0;i<paths.length;i++){ if(i == paths.length -1){ Object value = jsonObject.get(paths[i]); if(value instanceof JSONObject){ log.error("elasticSearch http获取值异常,检查{}路径(valuePath)是否为叶子节点:{}",key,config.get("valuePath")); }else{ //服务的标识后缀名 String name = metricsValueInfo.getJmxConnectionInfo().getName(); FalconReportObject falconReportObject = new FalconReportObject(); MetricsCommon.setReportCommonValue(falconReportObject,step); falconReportObject.setTimestamp(metricsValueInfo.getTimestamp()); falconReportObject.setMetric(MetricsCommon.getMetricsName(metrics)); falconReportObject.setValue(String.valueOf(executeJsExpress(valueExpress,value))); falconReportObject.setCounterType(CounterType.valueOf(counterType)); falconReportObject.appendTags(MetricsCommon.getTags(name,this,serverName(), MetricsType.HTTP_URL_CONF)). appendTags(tag); result.add(falconReportObject); } }else{ jsonObject = jsonObject.getJSONObject(paths[i]); } } } } } } } } catch (IOException e) { log.error("elasticSearch监控值获取发生异常",e); } return result; }
Example 3
Source File: JYAML.java From marshalsec with MIT License | 2 votes |
/** * {@inheritDoc} * * @see marshalsec.MarshallerBase#unmarshal(java.lang.Object) */ @Override public Object unmarshal ( String data ) throws Exception { return Yaml.loadType(data, Object.class); }