Skip to content

Commit 53994b0

Browse files
committed
Update Dameng Agent to fit for prometheus usage
1 parent 89d7a0b commit 53994b0

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

ojr-dameng-db/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "com.ojr"
7-
version = "0.5.2"
7+
version = "0.5.3"
88

99
java {
1010
sourceCompatibility = JavaVersion.VERSION_1_8

ojr-dameng-db/config/config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ instances:
1515
otel.callback.interval: 30
1616
#otel.backend.url: http://localhost:4317
1717
otel.backend.url: http://localhost:4318
18-
otel.transport: prometheus
19-
prometheus.port: 16543
18+
otel.transport: prometheus+http
19+
prometheus.port: 16540
2020
prometheus.restricted.metrics: db.sql.elapsed_time,db.lock.time
2121
otel.service.name: DamengA

ojr-dameng-db/src/main/java/com/ojr/dameng/DamengDc.java

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.ojr.rdb.AbstractDbDc;
77
import com.ojr.rdb.DbDcConfig;
88
import com.ojr.rdb.DbDcUtil;
9+
import com.ojr.rdb.SemanticAttributes;
910

1011
import java.sql.Connection;
1112
import java.sql.ResultSet;
@@ -39,6 +40,8 @@ public void processParameters(Map<String, Object> properties, DbDcConfig dbDcCon
3940
public void enrichResourceAttributes(ResourceEnricher enricher) {
4041
super.enrichResourceAttributes(enricher);
4142
enricher.enrich(DcUtil.OJR_PLUGIN, "dameng-db");
43+
enricher.enrich(DbDcUtil.DB_ADDRESS, this.getDbAddress());
44+
enricher.enrich(DbDcUtil.DB_PORT, this.getDbPort());
4245
}
4346

4447
// Register metrics with specific calculation modes

ojr-dameng-db/src/main/java/com/ojr/dameng/DamengUtil.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public class DamengUtil {
1313
public static final String SQL_COUNT_SQL = "select stat_val from v$sysstat where name in ('sql executed count')";
1414
public static final String IO_READ_COUNT_SQL = "select stat_val from v$sysstat where name in ('physical read count')";
1515
public static final String IO_WRITE_COUNT_SQL = "select stat_val from v$sysstat where name in ('physical write count')";
16-
public static final String TASK_WAIT_COUNT_SQL = "select waiting from v$task_queue";
16+
public static final String TASK_WAIT_COUNT_SQL = "SELECT COUNT(*) AS waiting FROM v$trxwait";
1717
public static final String TASK_AVG_WAIT_TIME_SQL = "select average_wait_time from v$task_queue";
1818

1919
public static final String CACHE_HIT_SQL = "SELECT SUM(rat_hit) / COUNT(*), name FROM v$bufferpool GROUP BY name";
2020
public static final String SQL_ELAPSED_TIME_SQL =
21-
"SELECT EXEC_TIME as ELAPSED_TIME_MILLIS, SQL_ID as sql_id, SQL_TEXT as sql_text FROM V$SYSTEM_LONG_EXEC_SQLS ORDER BY EXEC_TIME DESC LIMIT 20";
21+
"SELECT time_used/1000000.0 as time_used_seconds, sql_id, top_sql_text FROM v$sql_history ORDER BY time_used DESC limit 10";
2222
public static final String LOCK_COUNT_SQL = "select count(*), ltype from v$lock where blocked =1 group by ltype";
2323
public static final String LOCK_TIME_SQL = "SELECT timestampdiff(second, DS.create_time, sysdate) AS metric_value, L.ADDR AS lock_id, DS.SESS_ID AS blocking_sess_id, SS.SESS_ID AS blocker_sess_id, obj.OBJECT_NAME AS locked_obj_name FROM v$lock L LEFT JOIN v$sessions DS ON DS.TRX_ID = L.TRX_ID LEFT JOIN v$sessions SS ON SS.TRX_ID = L.TID LEFT JOIN dba_objects obj ON L.TABLE_ID = obj.OBJECT_ID WHERE L.BLOCKED = 1 LIMIT 20";
2424

ojr-dameng-db/src/test/java/com/ojr/dameng/DamengSimpIntegrationTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public void testSqlStatement(Connection conn) throws SQLException {
2020

2121
stmt = conn.createStatement();
2222

23+
String dropTableSQL = "DROP TABLE IF EXISTS ojr_users";
24+
stmt.executeUpdate(dropTableSQL);
25+
2326
String createTableSQL = "CREATE TABLE IF NOT EXISTS ojr_users (" +
2427
"id INT PRIMARY KEY AUTO_INCREMENT, " +
2528
"name VARCHAR(100), " +
@@ -54,8 +57,7 @@ public void testSqlStatement(Connection conn) throws SQLException {
5457
System.out.printf("ID: %d, Name: %s, Email: %s%n", id, name, email);
5558
}
5659

57-
String deleteTableSQL = "DROP TABLE ojr_users";
58-
stmt.executeUpdate(deleteTableSQL);
60+
stmt.executeUpdate(dropTableSQL);
5961

6062
rs.close();
6163
pstmt.close();

0 commit comments

Comments
 (0)