Skip to content

Commit

Permalink
[Feature] Supports Bulletin to view all metrics. (#2584)
Browse files Browse the repository at this point in the history
Signed-off-by: tomsun28 <tomsun28@outlook.com>
Co-authored-by: YuLuo <yuluo08290126@gmail.com>
Co-authored-by: tomsun28 <tomsun28@outlook.com>
Co-authored-by: kerwin612 <kerwin612@qq.com>
  • Loading branch information
4 people authored Aug 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 5eef247 commit 5d416e8
Showing 31 changed files with 2,081 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -139,14 +139,14 @@ public class Monitor {
/**
* Record create time
*/
@Schema(title = "Record create time", example = "1612198922000", accessMode = READ_ONLY)
@Schema(title = "Record create time", example = "2024-07-02T20:09:34.903217", accessMode = READ_ONLY)
@CreatedDate
private LocalDateTime gmtCreate;

/**
* Record the latest modification time (timestamp in milliseconds)
*/
@Schema(title = "Record modify time", example = "1612198444000", accessMode = READ_ONLY)
@Schema(title = "Record modify time", example = "2024-07-02T20:09:34.903217", accessMode = READ_ONLY)
@LastModifiedDate
private LocalDateTime gmtUpdate;

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.hertzbeat.common.entity.manager.bulletin;

import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_WRITE;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.hertzbeat.common.entity.manager.JsonLongListAttributeConverter;
import org.apache.hertzbeat.common.entity.manager.JsonTagListAttributeConverter;
import org.apache.hertzbeat.common.entity.manager.TagItem;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

/**
* Bulletin
*/
@Entity
@Data
@Schema(description = "Bulletin")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EntityListeners(AuditingEntityListener.class)
@Table(name = "hzb_bulletin")
public class Bulletin {

@Id
@Schema(description = "Bulletin ID", example = "1")
private Long id;

@Schema(description = "Bulletin Name", example = "Bulletin1", accessMode = READ_WRITE)
private String name;

@Schema(description = "Monitor IDs", example = "1")
@Column(name = "monitor_ids", length = 5000)
@Convert(converter = JsonLongListAttributeConverter.class)
private List<Long> monitorIds;

@Schema(description = "Monitor Type eg: jvm, tomcat", example = "jvm", accessMode = READ_WRITE)
private String app;


@Schema(description = "Monitor Fields")
@Column(length = 4096, columnDefinition = "json")
private String fields;

@Schema(description = "Tags(status:success,env:prod)", example = "{name: key1, value: value1}",
accessMode = READ_WRITE)
@Convert(converter = JsonTagListAttributeConverter.class)
@Column(length = 2048)
private List<TagItem> tags;

@Schema(title = "The creator of this record", example = "tom", accessMode = READ_WRITE)
@CreatedBy
private String creator;

@Schema(title = "The modifier of this record", example = "tom", accessMode = READ_WRITE)
@LastModifiedBy
private String modifier;

@Schema(title = "Record create time", example = "2024-07-02T20:09:34.903217", accessMode = READ_WRITE)
@CreatedDate
private LocalDateTime gmtCreate;

@Schema(title = "Record modify time", example = "2024-07-02T20:09:34.903217", accessMode = READ_WRITE)
@LastModifiedDate
private LocalDateTime gmtUpdate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.hertzbeat.common.entity.manager.bulletin;

import java.util.List;
import java.util.Map;
import lombok.Data;

/**
* Bulletin DTO
*/
@Data
public class BulletinDto {

/**
* Bulletin name
*/
private String name;

/**
* Monitor type eg: jvm, tomcat
*/
private String app;


/**
* Monitor fields
*/
private Map<String, List<String>> fields;

/**
* Monitor ids
*/
private List<Long> monitorIds;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.hertzbeat.common.entity.manager.bulletin;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* Bulletin Metrics Data
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "Bulletin Metrics Data")
public class BulletinMetricsData {

/**
* Bulletin Name
*/
@Schema(title = "Bulletin Name")
private String name;

/**
* Content Data
*/
@Schema(description = "Content Data")
private List<Data> content;

/**
* Bulletin Metrics Data
*/
@lombok.Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class Data {

/**
* Monitor Name
*/
@Schema(title = "Monitor name")
private String monitorName;

/**
* Monitor ID
*/
@Schema(title = "Monitor ID")
private Long monitorId;

/**
* Monitor IP
*/
@Schema(title = "Monitor IP")
private String host;

/**
* Monitor Metrics
*/
@Schema(title = "Monitor Metrics")
private List<Metric> metrics;
}

/**
* Metrics Data
*/
@lombok.Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "Metrics Data")
public static class Metric{

/**
* Metric type
*/
@Schema(title = "Metric type")
private String name;

/**
* Metric fields
*/
@Schema(title = "Metric fields")
private List<List<Field>> fields;
}


/**
* Metrics field
*/
@lombok.Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "Metrics field")
public static class Field{

/**
* Field name
*/
@Schema(title = "Field name")
private String key;

/**
* Field unit
*/
@Schema(title = "Field unit")
private String unit;

/**
* Field value
*/
@Schema(title = "Field value")
private String value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.hertzbeat.common.entity.manager.bulletin;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.hertzbeat.common.entity.manager.TagItem;

/**
* Bulletin Vo
*/

@Data
@AllArgsConstructor
@NoArgsConstructor
public class BulletinVo {

/**
* Bulletin ID
*/
private Long id;

/**
* Bulletin name
*/
private String name;

/**
* Bulletin metrics
*/
private List<String> metrics;

/**
* Bulletin tags
*/
private List<TagItem> tags;

/**
* Bulletin monitor ID
*/
private List<Long> monitorId;

/**
* Bulletin monitor name
*/
private String app;

}
Original file line number Diff line number Diff line change
@@ -100,11 +100,15 @@ public static JsonNode fromJson(String jsonStr) {
* @param jsonStr json string
* @return true if the string is a json string
*/


public static boolean isJsonStr(String jsonStr) {
if (!StringUtils.hasText(jsonStr)) {
if (jsonStr == null || jsonStr.trim().isEmpty()) {
return false;
}
if (!jsonStr.startsWith("{") || !jsonStr.endsWith("}")) {
jsonStr = jsonStr.trim();
if (!(jsonStr.startsWith("{") && jsonStr.endsWith("}"))
&& !(jsonStr.startsWith("[") && jsonStr.endsWith("]"))) {
return false;
}
try {
Loading

0 comments on commit 5d416e8

Please sign in to comment.