Commit 712d0b5a authored by wutu's avatar wutu

Merge branch 'pretty-log' of gitee.com:prowo_admin/bishe into pretty-log

parents 44daf7ef fc5639ea
......@@ -23,6 +23,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.9</version>
</dependency>
<!--日志模块-->
<dependency>
......
package top.ninwoo.edgecenter.controller;
import org.influxdb.InfluxDB;
import org.influxdb.dto.Point;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.ninwoo.common.entity.ClusterConfig;
......@@ -22,13 +24,16 @@ public class IndexController {
ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(8);
@Autowired
ClusterService clusterService;
private ClusterService clusterService;
@Autowired
TopologyService topologyService;
private TopologyService topologyService;
@Autowired
IpService ipService;
private IpService ipService;
@Autowired
private InfluxDB influxDB;
@RequestMapping(value = "/index")
public List<DockerContainer> index(int flag) {
......@@ -88,7 +93,7 @@ public class IndexController {
// 为每一个cid容器创建一个定时任务
if (!scheduledFutureMap.containsKey(cid)) {
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);
// 保存任务,以方便进行定时任务的关闭
......@@ -119,7 +124,6 @@ public class IndexController {
containerInfoMap.remove(cid);
}
});
return true;
}
......@@ -143,11 +147,15 @@ public class IndexController {
private String containerId;
private ConcurrentHashMap<String, ContainerInfo> map;
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.map = map;
this.clusterService = clusterService;
this.influxDB = influxDB;
this.cName = cName;
}
@Override
......@@ -163,9 +171,20 @@ public class IndexController {
if(map.containsKey(containerId)) {
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) {
this.containerId = containerId;
}
......@@ -227,7 +246,8 @@ public class IndexController {
return "没有设置clusterid";
}
String res = clusterService.adjustCluster(clusterConfig);
return res;
String res1 = topologyService.modifyTopology(clusterConfig.getId(), clusterConfig.getTopology());
return res + "|" + res1;
}
@RequestMapping(value = "/adjustClusterTopo")
......
......@@ -5,7 +5,10 @@ spring:
url: jdbc:mysql://opengn.org:32306/bishe?useSSL=false
username: root
password: Vudo3423ljo
influx:
url: http://192.168.61.131:8086
user: admin
password: admin
mybatis:
configuration:
map-underscore-to-camel-case: true
......
......@@ -30,5 +30,10 @@
<version>2.1.2.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.9</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
bishe.app.app-name=joliu
bishe.app.cloud-url=127.0.0.1:9091
\ No newline at end of file
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;
import org.influxdb.InfluxDB;
import org.influxdb.dto.Point;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -14,6 +16,7 @@ import top.ninwoo.test.BisheTestMain;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = BisheTestMain.class)
......@@ -25,6 +28,21 @@ public class BisheMultiNodeTests {
@Resource
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
public void testNetworkChange() {
ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>();
......@@ -108,7 +126,7 @@ public class BisheMultiNodeTests {
clusterConfigs.add(separatedClusterConfig1);
clusterService.sendClusterConfigToEdgeNode(clusterConfigs);
topo1.getTopology()[5][3] = 1;
//topo1.getTopology()[6][3] = 1;
adjustCluster(clusterConfigs);
}
......@@ -118,6 +136,54 @@ public class BisheMultiNodeTests {
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
public void testSendSeparateConfig() {
......
......@@ -116,7 +116,7 @@ public class TcServiceImpl implements TcService {
if(qosMap.containsKey(containerId)) {
maxRate = qosMap.get(containerId);
}
netUsage = curRate/maxRate;
netUsage = curRate/(1024*8f);
if(netUsage > 1.0) {
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