Skip to content

Commit 278d09d

Browse files
committed
[document] add example for adding a widget chart link on an customizable alert.
1 parent 184e81b commit 278d09d

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

scouter.document/main/Alert-Plugin-Guide.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,41 @@ Alert script file can be edited from scouter client ui or directly in scouter se
5151
* alert when ```GcTime``` is over than 2 sec
5252
```java
5353
// void process(RealCounter $counter, PluginHelper $$)
54+
//################ widget chart url setting ####################
55+
String counterName = "TPS";
5456
String objType = $counter.objType();
5557
String objName = $counter.objName();
5658
57-
String widgetUrl = "http://127.0.0.1:6180/widget/simple/counter.html?source="
59+
java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyyMMdd");
60+
long now = System.currentTimeMillis();
61+
String today = dateFormat.format(new java.util.Date(now));
62+
String yesterday = dateFormat.format(new java.util.Date(now-24*60*60*1000));
5863
59-
String counterApi5Min = "TPS/ofType/" + objType;
60-
counterApi5Min += "?startTimeMillis=" + (System.currentTimeMillis()-300*1000);
61-
counterApi5Min += "?endTimeMillis=" + System.currentTimeMillis();
64+
String widgetUrl = "http://127.0.0.1:6180/widget/simple/counter.html?source=";
6265
63-
String counterApiLatest5Min = "TPS/latest/300/ofType" + objType;
66+
String counterApi = counterName + "/ofType/" + objType;
67+
counterApi += "?startTimeMillis=" + (now-600*1000L);
68+
counterApi += "&endTimeMillis=" + now;
69+
70+
String counterApiLatest = counterName + "/latest/600/ofType/" + objType;
71+
72+
String statApi = "stat/" + counterName + "/ofType/" + objType;
73+
statApi += "?startYmd=" + yesterday;
74+
statApi += "&endYmd=" + today;
75+
//##############################################################
6476
6577
int gcTime = $counter.intValue();
6678
if(gcTime > 2000) {
67-
String message = "gc time:" + respTime + "ms";
68-
69-
message = "\n[Check TPS]\n";
70-
message += widgetUrl + java.net.UrlEncoder.encode(counterApi5Min) + "\n";
79+
String message = "gc time:" + respTime + "ms\n";
7180
72-
message += "[Current 5 min TPS]\n";
73-
message += widgetUrl + java.net.UrlEncoder.encode(counterApiLatest5Min) + "\n";
81+
message = "[On-time chart]\n";
82+
message += widgetUrl + java.net.URLEncoder.encode(counterApi) + "\n";
83+
message += "[Current chart]\n";
84+
message += widgetUrl + java.net.URLEncoder.encode(counterApiLatest) + "\n";
85+
message += "[Daily chart]\n";
86+
message += widgetUrl + java.net.URLEncoder.encode(statApi) + "\n";
7487
75-
$counter.fatal("gc time fatal", message);
88+
$counter.fatal("gc time fatal", message);
7689
}
7790
```
7891
* sample2 (**Elasped90%.alert**)

0 commit comments

Comments
 (0)