Commit fc5639ea authored by wutu's avatar wutu

添加集群监控模块

parent 4848a97f
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.9</version>
</dependency>
<!--日志模块--> <!--日志模块-->
<dependency> <dependency>
......
package top.ninwoo.edgecenter.controller; package top.ninwoo.edgecenter.controller;
import org.influxdb.InfluxDB;
import org.influxdb.dto.Point;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import top.ninwoo.common.entity.ClusterConfig; import top.ninwoo.common.entity.ClusterConfig;
...@@ -22,13 +24,16 @@ public class IndexController { ...@@ -22,13 +24,16 @@ public class IndexController {
ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(8); ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(8);
@Autowired @Autowired
ClusterService clusterService; private ClusterService clusterService;
@Autowired
private TopologyService topologyService;
@Autowired @Autowired
TopologyService topologyService; private IpService ipService;
@Autowired @Autowired
IpService ipService; private InfluxDB influxDB;
@RequestMapping(value = "/index") @RequestMapping(value = "/index")
public List<DockerContainer> index(int flag) { public List<DockerContainer> index(int flag) {
...@@ -88,7 +93,7 @@ public class IndexController { ...@@ -88,7 +93,7 @@ public class IndexController {
// 为每一个cid容器创建一个定时任务 // 为每一个cid容器创建一个定时任务
if (!scheduledFutureMap.containsKey(cid)) { if (!scheduledFutureMap.containsKey(cid)) {
containerInfoMap.put(cid, new ContainerInfo()); containerInfoMap.put(cid, new ContainerInfo());
NetworkMonitorThread networkMonitorThread = new NetworkMonitorThread(cid, containerInfoMap, clusterService); NetworkMonitorThread networkMonitorThread = new NetworkMonitorThread(cid, containerInfoMap, clusterService, influxDB, containerName);
// 放入线程池执行任务 // 放入线程池执行任务
ScheduledFuture<?> future = scheduledExecutorService.scheduleAtFixedRate(networkMonitorThread, 0, 1, TimeUnit.SECONDS); ScheduledFuture<?> future = scheduledExecutorService.scheduleAtFixedRate(networkMonitorThread, 0, 1, TimeUnit.SECONDS);
// 保存任务,以方便进行定时任务的关闭 // 保存任务,以方便进行定时任务的关闭
...@@ -119,7 +124,6 @@ public class IndexController { ...@@ -119,7 +124,6 @@ public class IndexController {
containerInfoMap.remove(cid); containerInfoMap.remove(cid);
} }
}); });
return true; return true;
} }
...@@ -143,11 +147,15 @@ public class IndexController { ...@@ -143,11 +147,15 @@ public class IndexController {
private String containerId; private String containerId;
private ConcurrentHashMap<String, ContainerInfo> map; private ConcurrentHashMap<String, ContainerInfo> map;
private ClusterService clusterService; private ClusterService clusterService;
private InfluxDB influxDB;
private String cName;
public NetworkMonitorThread(String containerId, ConcurrentHashMap<String, ContainerInfo> map, ClusterService clusterService) { public NetworkMonitorThread(String containerId, ConcurrentHashMap<String, ContainerInfo> map, ClusterService clusterService, InfluxDB influxDB, String cName) {
this.containerId = containerId; this.containerId = containerId;
this.map = map; this.map = map;
this.clusterService = clusterService; this.clusterService = clusterService;
this.influxDB = influxDB;
this.cName = cName;
} }
@Override @Override
...@@ -163,9 +171,20 @@ public class IndexController { ...@@ -163,9 +171,20 @@ public class IndexController {
if(map.containsKey(containerId)) { if(map.containsKey(containerId)) {
map.put(containerId, containerInfo); // TODO: 这里有又重新把容器id注册回去了 map.put(containerId, containerInfo); // TODO: 这里有又重新把容器id注册回去了
} }
System.out.println("监控运行中" + containerId); savePoint(networkInfo);
} }
private void savePoint(NetworkInfo networkInfo) {
Point.Builder builder = Point.measurement("monitor");
Point point = builder
.addField("rate", networkInfo.getCurRate())
.addField("error", networkInfo.getErrorRate())
.addField("drop", networkInfo.getDropRate())
.tag("cid", containerId)
.tag("cName", cName).build();
influxDB.setDatabase("test").write(point);
}
public void setContainerId(String containerId) { public void setContainerId(String containerId) {
this.containerId = containerId; this.containerId = containerId;
} }
...@@ -227,7 +246,8 @@ public class IndexController { ...@@ -227,7 +246,8 @@ public class IndexController {
return "没有设置clusterid"; return "没有设置clusterid";
} }
String res = clusterService.adjustCluster(clusterConfig); String res = clusterService.adjustCluster(clusterConfig);
return res; String res1 = topologyService.modifyTopology(clusterConfig.getId(), clusterConfig.getTopology());
return res + "|" + res1;
} }
@RequestMapping(value = "/adjustClusterTopo") @RequestMapping(value = "/adjustClusterTopo")
......
...@@ -5,7 +5,10 @@ spring: ...@@ -5,7 +5,10 @@ spring:
url: jdbc:mysql://opengn.org:32306/bishe?useSSL=false url: jdbc:mysql://opengn.org:32306/bishe?useSSL=false
username: root username: root
password: Vudo3423ljo password: Vudo3423ljo
influx:
url: http://192.168.61.131:8086
user: admin
password: admin
mybatis: mybatis:
configuration: configuration:
map-underscore-to-camel-case: true map-underscore-to-camel-case: true
......
...@@ -30,5 +30,10 @@ ...@@ -30,5 +30,10 @@
<version>2.1.2.RELEASE</version> <version>2.1.2.RELEASE</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.9</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
bishe.app.app-name=joliu bishe.app.app-name=joliu
bishe.app.cloud-url=127.0.0.1:9091 bishe.app.cloud-url=127.0.0.1:9091
spring.influx.url=http://192.168.61.131:8086
spring.influx.user=admin
spring.influx.password=admin
\ No newline at end of file
package top.ninwoo; package top.ninwoo;
import org.influxdb.InfluxDB;
import org.influxdb.dto.Point;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -14,6 +16,7 @@ import top.ninwoo.test.BisheTestMain; ...@@ -14,6 +16,7 @@ import top.ninwoo.test.BisheTestMain;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = BisheTestMain.class) @SpringBootTest(classes = BisheTestMain.class)
...@@ -25,6 +28,21 @@ public class BisheMultiNodeTests { ...@@ -25,6 +28,21 @@ public class BisheMultiNodeTests {
@Resource @Resource
private NetworkService networkService; private NetworkService networkService;
@Autowired
private InfluxDB influxDB;
@Test
public void testInFluxDB() {
Point.Builder builder = Point.measurement("monitor");
System.out.println(System.currentTimeMillis());
builder
.addField("rate", 1221f)
.addField("error", 0.01f)
.tag("cid", "APP1");
Point point = builder.build();
influxDB.setDatabase("test").write(point);
}
@Test @Test
public void testNetworkChange() { public void testNetworkChange() {
ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>(); ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>();
...@@ -108,7 +126,7 @@ public class BisheMultiNodeTests { ...@@ -108,7 +126,7 @@ public class BisheMultiNodeTests {
clusterConfigs.add(separatedClusterConfig1); clusterConfigs.add(separatedClusterConfig1);
clusterService.sendClusterConfigToEdgeNode(clusterConfigs); clusterService.sendClusterConfigToEdgeNode(clusterConfigs);
topo1.getTopology()[5][3] = 1; //topo1.getTopology()[6][3] = 1;
adjustCluster(clusterConfigs); adjustCluster(clusterConfigs);
} }
...@@ -118,6 +136,54 @@ public class BisheMultiNodeTests { ...@@ -118,6 +136,54 @@ public class BisheMultiNodeTests {
return b; return b;
} }
@Test
public void testNewService() {
ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>();
SeparatedClusterConfig separatedClusterConfig = new SeparatedClusterConfig();
separatedClusterConfig.setEdgeNodeId("192.168.61.130:8081");
ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setId(11112l);
clusterConfig.setOwner("joliu");
ContainerDescription containerDescription = new ContainerDescription();
containerDescription.setMode("normal");
containerDescription.setReplicas(1);
DockerContainer container = new DockerContainer();
container.setName("APP4");
container.setCommand("sh");
container.setImage("joliu/networktest");
containerDescription.setDockerContainer(container);
ClusterConfig clusterConfig1 = new ClusterConfig();
clusterConfig1.setId(11112l);
clusterConfig1.setOwner("joliu");
ContainerDescription containerDescription1 = new ContainerDescription();
containerDescription1.setMode("normal");
containerDescription1.setReplicas(1);
DockerContainer container1 = new DockerContainer();
container1.setName("APP5");
container1.setCommand("sh");
container1.setImage("joliu/networktest");
containerDescription1.setDockerContainer(container1);
List<ContainerDescription> cds = new ArrayList<>();
cds.add(containerDescription);
cds.add(containerDescription1);
clusterConfig.setDockers(cds);
NetworkTopology topo = new NetworkTopology();
topo.setAppNames(new String[]{"APP4", "APP5", "br:ovs9", "br:ovs10"});
// 这个参数好像没啥用
topo.setTopologyId(11);
topo.setTopology(new int[][]{
{0,0,0,0},
{0,0,0,0},
{1,0,0,0},
{0,1,1,0}});
clusterConfig.setTopology(topo);
separatedClusterConfig.setClusterConfig(clusterConfig);
clusterConfigs.add(separatedClusterConfig);
clusterService.sendClusterConfigToEdgeNode(clusterConfigs);
}
@Test @Test
public void testSendSeparateConfig() { public void testSendSeparateConfig() {
......
...@@ -116,7 +116,7 @@ public class TcServiceImpl implements TcService { ...@@ -116,7 +116,7 @@ public class TcServiceImpl implements TcService {
if(qosMap.containsKey(containerId)) { if(qosMap.containsKey(containerId)) {
maxRate = qosMap.get(containerId); maxRate = qosMap.get(containerId);
} }
netUsage = curRate/maxRate; netUsage = curRate/(1024*8f);
if(netUsage > 1.0) { if(netUsage > 1.0) {
netUsage = 1.0f; netUsage = 1.0f;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment