scouter.server.http.handler.CounterHandler Maven / Gradle / Ivy
/*
* Copyright 2015 the original author or authors.
* @https://github.com/scouter-project/scouter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package scouter.server.http.handler;
import java.io.IOException;
import java.io.Reader;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import scouter.io.DataOutputX;
import scouter.lang.TimeTypeEnum;
import scouter.lang.pack.ObjectPack;
import scouter.lang.pack.Pack;
import scouter.lang.pack.PerfCounterPack;
import scouter.lang.value.FloatValue;
import scouter.net.NetCafe;
import scouter.server.CounterManager;
import scouter.server.netio.data.NetDataProcessor;
import scouter.util.HashUtil;
import scouter.util.IPUtil;
import scouter.util.StringUtil;
/*
[
{
"object" : {
"host" : "VM123",
"name" : "my_server1",
"type" : "redis",
"address" : "10.10.10.10"
},
"counters" : [
{"name" : "aof_rewrite_scheduled", "value" : 55},
{"name" : "client_longest_output_list", "value" : 245},
{"name" : "used_cpu_user", "value" : 4245}
]
},
{
"object" : {
"host" : "VM123",
"name" : "my_server2",
"type" : "redis",
"address" : "10.10.10.10"
},
"counters" : [
{"name" : "aof_rewrite_scheduled", "value" : 35},
{"name" : "client_longest_output_list", "value" : 65},
{"name" : "used_cpu_user", "value" : 8888}
]
}
]
*/
public class CounterHandler {
static CounterManager counterManager = CounterManager.getInstance();
public static void process(Reader in) {
JSONParser parser = new JSONParser();
try {
Object o = parser.parse(in);
if (o instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) o;
for (int i = 0; i