Skip to content

Commit

Permalink
Merge pull request #13 from shiyindaxiaojie/feature
Browse files Browse the repository at this point in the history
Feature
  • Loading branch information
shiyindaxiaojie authored Aug 27, 2024
2 parents 6b2df46 + 346e52c commit ddeb08b
Show file tree
Hide file tree
Showing 34 changed files with 592 additions and 406 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_IMAGE: shiyindaxiaojie/cat-home
DOCKER_VERSION: v3.4.0
DOCKER_VERSION: v3.4.1
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 3.4.1 (2024-08-27)

### FEATURES

- 新增 JVM 内置参数,支持 G1CMSZGC 垃圾回收器

### BUGFIX

- 修复 `HeartBeat` 监控告警交互问题
- 修复 Jira Software 兼容性问题

## 3.4.0 (2024-05-01)

### FEATURES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public enum AlertType {

Exception("Exception", "异常告警",
"http://{0}:{1}/cat/r/p?domain={2}&date={3}&ip=All&type=RuntimeException,Exception&metric={4}",
"http://{0}:{1}/cat/s/config?op=exceptionThresholdUpdate&domain={2}&exception={3}"), // exception=type
"http://{0}:{1}/cat/s/config?op=exceptionThresholdUpdate&domain={2}&exception={3}"),

HeartBeat("Heartbeat", "心跳告警",
"http://{0}:{1}/cat/r/p?domain={2}&date={3}&ip={4}&type=Heartbeat",
"http://{0}:{1}/cat/s/config?op=heartbeatRuleUpdate&key={2};{3}"), // key=ruleId
"http://{0}:{1}/cat/r/h?domain={2}&date={3}&ip=All&reportType=day&op=view",
"http://{0}:{1}/cat/s/config?op=heartbeatRuleConfigList"),

ThirdParty("ThirdParty", "第三方告警", "", ""),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,9 @@ protected static Map<String, String> parseUrls(String query) {
for (String keyValue : keyValues) {
String[] pair = keyValue.split("=");
if (pair.length == 2) {
try {
String key = URLDecoder.decode(pair[0], "UTF-8");
String value = URLDecoder.decode(pair[1], "UTF-8");
params.put(key, value);
} catch (UnsupportedEncodingException e) {
// do nothing
}
String key = pair[0];
String value = pair[1];
params.put(key, value);
}
}
return params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public boolean send(SendMessageEntity message) {
issue.setComponents(components);
}

String parsedFixVersionNames = this.getParameterValue(receiver,"fixVersionNames");
String parsedFixVersionNames = this.getParameterValue(receiver,"fixVersionNames");
if (StringUtils.isNotEmpty(parsedFixVersionNames)) {
List<String> fixVersionNames = Lists.newArrayList();
Collections.addAll(fixVersionNames, parsedFixVersionNames.split(","));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.atlassian.jira.rest.client.api.AuthenticationHandler;
import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.JiraRestClientFactory;
import com.atlassian.jira.rest.client.api.OptionalIterable;
import com.atlassian.jira.rest.client.api.domain.BasicComponent;
import com.atlassian.jira.rest.client.api.domain.BasicIssue;
import com.atlassian.jira.rest.client.api.domain.IssueType;
Expand All @@ -13,7 +14,6 @@
import com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
import com.google.common.collect.Lists;
import com.sun.jndi.toolkit.url.Uri;

import java.io.IOException;
import java.net.URI;
Expand Down Expand Up @@ -88,6 +88,12 @@ public BasicIssue createIssue(JiraIssue issue) throws ExecutionException, Interr
}
}

public Project getProject(String projectKey) throws IOException {
try (JiraRestClient restClient = auth()) {
return restClient.getProjectClient().getProject(projectKey).claim();
}
}

private JiraRestClient auth() {
URI uri = URI.create(address);
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
Expand All @@ -109,17 +115,27 @@ private Project getProject(JiraRestClient restClient, String projectKey) {
}

private IssueType getIssueType(JiraRestClient restClient, String projectKey, String issueTypeName) {
for (IssueType issueType : getProject(restClient, projectKey).getIssueTypes()) {
if (issueType.getName().equals(issueTypeName)) {
return issueType;
if (issueTypeName == null || issueTypeName.isEmpty()) {
throw new RuntimeException("Issue type is required.");
}
OptionalIterable<IssueType> issueTypes = getProject(restClient, projectKey).getIssueTypes();
for (String name : issueTypeName.split(",")) {
for (IssueType issueType : issueTypes) {
if (issueType.getName().equals(name)) {
return issueType;
}
}
}
throw new RuntimeException("Issue type '" + issueTypeName + "' is not found.");
}

private List<BasicComponent> getComponent(JiraRestClient restClient, String projectKey, List<String> componentNames) {
if (componentNames == null || componentNames.isEmpty()) {
throw new RuntimeException("Component name is required.");
}
List<BasicComponent> components = new ArrayList<>();
for (BasicComponent component : getProject(restClient, projectKey).getComponents()) {
Iterable<BasicComponent> basicComponents = getProject(restClient, projectKey).getComponents();
for (BasicComponent component : basicComponents) {
for (String componentName : componentNames) {
if (component.getName().equals(componentName)) {
components.add(component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
</component>
<component>
<role>com.dianping.cat.alarm.spi.spliter.Spliter</role>
<role-hint>feishu</role-hint>
<role-hint>dingtalk</role-hint>
<implementation>com.dianping.cat.alarm.spi.spliter.FeishuSpliter</implementation>
</component>
<component>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ public static void main(String[] args) {
List<String> components = Lists.newArrayList("架构");
List<String> fixVersionNames = Lists.newArrayList("待定");
String assigneeName = "guoyuanlu";
String reporterName = "monitor";

JiraIssue issue = new JiraIssue(projectKey, summary, description);
issue.setIssueType(issueType);
issue.setComponents(components);
issue.setFixVersionNames(fixVersionNames);
issue.setAssigneeName(assigneeName);
issue.setReporterName(reporterName);
issue.addCustomFields("customfield_11201", "ROI");
JiraHelper jiraHelper = new JiraHelper("", "");
try {
Expand Down
40 changes: 40 additions & 0 deletions cat-client/src/main/java/com/dianping/cat/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.dianping.cat;

import com.dianping.cat.status.model.entity.Extension;
import com.dianping.cat.status.model.entity.GcInfo;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.util.List;

/**
* TODO
*
* @author <a href="mailto:[email protected]">gyl</a>
* @since 2.4.13
*/
public class Test {

public static void main(String[] args) {
List<GarbageCollectorMXBean> beans = ManagementFactory.getGarbageCollectorMXBeans();

for (GarbageCollectorMXBean mxbean : beans) {
if (mxbean.isValid()) {
String name = mxbean.getName();
long collectionCount = mxbean.getCollectionCount();
long collectionTime = mxbean.getCollectionTime();
System.out.println("Garbage Collector: " + name);
System.out.println(" Collection Count: " + collectionCount);
System.out.println(" Collection Time: " + collectionTime + " ms");
}
}

for (MemoryPoolMXBean mpBean : ManagementFactory.getMemoryPoolMXBeans()) {
long count = mpBean.getUsage().getUsed();
String name = mpBean.getName();

System.out.println(name + ":" + count);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public Map<String, String> getProperties() {
Map<String, String> map = new HashMap<String, String>();

map.put("msg-queue", String.valueOf(m_queue.size()));
map.put("atomic-queue", String.valueOf(m_queue.size()));
// map.put("atomic-queue", String.valueOf(m_queue.size()));
return map;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ public void visitDiskVolume(DiskVolumeInfo diskVolume) {
Extension diskExtension = m_statusInfo.findOrCreateExtension("Disk");
File volume = new File(diskVolume.getId());

diskVolume.setTotal(volume.getTotalSpace());
diskVolume.setFree(volume.getFreeSpace());
diskVolume.setUsable(volume.getUsableSpace());
diskVolume.setTotal(volume.getTotalSpace() / (1024 * 1024 * 1024));
diskVolume.setFree(volume.getFreeSpace() / (1024 * 1024 * 1024));
diskVolume.setUsable(volume.getUsableSpace() / (1024 * 1024 * 1024));

diskExtension.findOrCreateExtensionDetail(diskVolume.getId() + " Free").setValue(volume.getFreeSpace());
diskExtension.findOrCreateExtensionDetail(diskVolume.getId() + " Free").setValue(diskVolume.getFree());
}

@Override
Expand Down Expand Up @@ -308,4 +308,4 @@ public void visitThread(ThreadsInfo thread) {
m_statusInfo.addExtension(frameworkThread);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void translateHeartbeat(StatusInfo info) {
MessageInfo message = info.getMessage();

if (message.getProduced() > 0 || message.getBytes() > 0) {
Extension catExtension = info.findOrCreateExtension("CatUsage");
Extension catExtension = info.findOrCreateExtension("Cat");

catExtension.findOrCreateExtensionDetail("Produced").setValue(message.getProduced());
catExtension.findOrCreateExtensionDetail("Overflowed").setValue(message.getOverflowed());
Expand All @@ -188,7 +188,7 @@ private void translateHeartbeat(StatusInfo info) {
gc.findOrCreateExtensionDetail("ConcurrentMarkSweepTime").setValue(oldGc.getTime());
}

Extension thread = info.findOrCreateExtension("FrameworkThread");
Extension thread = info.findOrCreateExtension("Thread");
ThreadsInfo threadInfo = info.getThread();

thread.findOrCreateExtensionDetail("HttpThread").setValue(threadInfo.getHttpThreadCount());
Expand Down
Loading

0 comments on commit ddeb08b

Please sign in to comment.