Skip to content

Commit 04902a8

Browse files
authored
Merge pull request #4869 from ant-media/serverAlerts
High resource usage and server unexpected shutdown webhook
2 parents 3b5dc21 + 293300b commit 04902a8

File tree

6 files changed

+301
-68
lines changed

6 files changed

+301
-68
lines changed

src/main/java/io/antmedia/AntMediaApplicationAdapter.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,14 @@
88
import java.lang.reflect.Modifier;
99
import java.nio.file.Files;
1010
import java.nio.file.Path;
11-
import java.util.ArrayList;
12-
import java.util.Collections;
13-
import java.util.HashMap;
14-
import java.util.Iterator;
15-
import java.util.List;
16-
import java.util.Map;
11+
import java.util.*;
1712
import java.util.Map.Entry;
13+
import java.util.concurrent.ConcurrentLinkedQueue;
1814
import java.util.regex.Pattern;
19-
import java.util.Queue;
20-
import java.util.Set;
2115

2216
import javax.validation.constraints.NotNull;
2317

18+
import io.antmedia.statistic.*;
2419
import org.apache.commons.io.FileUtils;
2520
import org.apache.commons.io.FilenameUtils;
2621
import org.apache.commons.lang3.RandomStringUtils;
@@ -72,9 +67,6 @@
7267
import io.antmedia.settings.ServerSettings;
7368
import io.antmedia.shutdown.AMSShutdownManager;
7469
import io.antmedia.shutdown.IShutdownListener;
75-
import io.antmedia.statistic.DashViewerStats;
76-
import io.antmedia.statistic.HlsViewerStats;
77-
import io.antmedia.statistic.ViewerStats;
7870
import io.antmedia.statistic.type.RTMPToWebRTCStats;
7971
import io.antmedia.statistic.type.WebRTCAudioReceiveStats;
8072
import io.antmedia.statistic.type.WebRTCAudioSendStats;
@@ -97,6 +89,7 @@ public class AntMediaApplicationAdapter extends MultiThreadedApplicationAdapter
9789
public static final String HOOK_ACTION_END_LIVE_STREAM = "liveStreamEnded";
9890
public static final String HOOK_ACTION_START_LIVE_STREAM = "liveStreamStarted";
9991
public static final String HOOK_ACTION_VOD_READY = "vodReady";
92+
10093
public static final String HOOK_ACTION_PUBLISH_TIMEOUT_ERROR = "publishTimeoutError";
10194
public static final String HOOK_ACTION_ENCODER_NOT_OPENED_ERROR = "encoderNotOpenedError";
10295
public static final String HOOK_ACTION_ENDPOINT_FAILED = "endpointFailed";
@@ -151,7 +144,7 @@ public class AntMediaApplicationAdapter extends MultiThreadedApplicationAdapter
151144

152145
protected StorageClient storageClient;
153146

154-
protected ArrayList<IStreamListener> streamListeners = new ArrayList<>();
147+
protected Queue<IStreamListener> streamListeners = new ConcurrentLinkedQueue<>();
155148

156149
IClusterStreamFetcher clusterStreamFetcher;
157150

@@ -176,6 +169,7 @@ public boolean appStart(IScope app) {
176169
if (!result.isSuccess()) {
177170
//Save App Setting
178171
this.shutdownProperly = false;
172+
179173
// Reset Broadcast Stats
180174
resetBroadcasts();
181175
}
@@ -241,7 +235,6 @@ else if (getServerSettings().getHostAddress().equals(storedSettings.getWarFileOr
241235

242236
setStorageclientSettings(appSettings);
243237

244-
245238
logger.info("{} started", app.getName());
246239

247240
return true;
@@ -357,7 +350,6 @@ public Result importVoDFolder(String vodFolderPath) {
357350
return result;
358351
}
359352

360-
361353
public Result unlinksVoD(String directory)
362354
{
363355
//check the directory exist

src/main/java/io/antmedia/console/rest/RestServiceV2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public Response isShutdownProperly(@ApiParam(value = "Application name", require
461461
return super.isShutdownProperly(appNamesArray);
462462
}
463463

464-
@ApiOperation(value = "Set application or applications shutdown properly to true", response = Result.class)
464+
@ApiOperation(value = "Set application or applications shutdown property to true", response = Result.class)
465465
@GET
466466
@Path("/shutdown-properly")
467467
@Produces(MediaType.APPLICATION_JSON)

src/main/java/io/antmedia/settings/ServerSettings.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public class ServerSettings implements ApplicationContextAware {
8787
public static final String SETTINGS_JWT_SERVER_CONTROL_ENABLED = "server.jwtServerControlEnabled";
8888

8989
public static final String SETTINGS_JWKS_URL = "server.jwksURL";
90+
91+
private static final String SETTINGS_SERVER_STATUS_WEBHOOK_URL = "server.statusWebHookURL";
9092

9193
/**
9294
* The IP filter that is allowed to access the web panel of Ant Media Server
@@ -235,6 +237,15 @@ public class ServerSettings implements ApplicationContextAware {
235237
@Value("${"+SETTINGS_RTMP_PORT + ":1935}")
236238
private int rtmpPort = 1935;
237239

240+
241+
/**
242+
* Server status webhook url. It's called for several errors such
243+
* - high resource usage
244+
* - Unexpected shutdown
245+
*/
246+
@Value("${"+SETTINGS_SERVER_STATUS_WEBHOOK_URL + ":#{null}}")
247+
private String serverStatusWebHookURL;
248+
238249

239250
public String getJwksURL() {
240251
return jwksURL;
@@ -565,5 +576,13 @@ public void setSslEnabled(boolean sslEnabled) {
565576
this.sslEnabled = sslEnabled;
566577
}
567578

579+
public String getServerStatusWebHookURL() {
580+
return serverStatusWebHookURL;
581+
}
582+
583+
584+
public void setServerStatusWebHookURL(String serverStatusWebHookURL) {
585+
this.serverStatusWebHookURL = serverStatusWebHookURL;
586+
}
568587

569588
}

0 commit comments

Comments
 (0)