We are excited to announce that a new feature has been released !
It is now possible to send a signal to an application hosted by Scalingo.
On the Scalingo platform, sending signals is a useful way to trigger events while being the owner or collaborator of an application. This can be particularly useful for debugging purposes.
In this article we will talk about how to send a user-defined signal (SIGUSR1
and SIGUSR2
) to a Scalingo hosted application.For more information, you can check the Scalingo documentation about Send-Signal.
At Scalingo we often use signals handler to:
A signal can be send with our CLI:
$ scalingo -a my-app ps
+-------+---------+-------------+------+---------------------+
| NAME | STATUS | COMMAND | SIZE | CREATED AT |
+-------+---------+-------------+------+---------------------+
| web-1 | running | sample-test | M | 2023/01/05 09:24:33 |
| web-2 | running | sample-test | M | 2023/01/05 09:24:33 |
+-------+---------+-------------+------+---------------------+
$ scalingo -a my-app send-signal --signal SIGUSR1 web-1
-----> Sent signal 'SIGUSR1' to 'web-1' container.
The following example is a sample that can be found on our Scalingo's GitHub account and quickly deployed on the platform.
In this example, we will catch a SIGUSR1
and print the memory usage of our process.
The catch part can be resumed by this code:
process.on("SIGUSR1", () => {
const used = process.memoryUsage();
console.log("Printing memory usage")
for (let key in used) {
console.log(`- ${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`);
}
});
var express = require('express')
var app = express()
// ...
Here we will need to write our entry point in the Procfile
. If we did not, the default entry point of a node application will be npm start
which does not forward signals to app.js
. More information on which process catches the signal can be found in our Scalingo documentation.
web: node app.js
Once deployed on Scalingo we can easily send a signal to our containerized application:
$ scalingo -a my-app send-signal --signal SIGUSR1 web-1
-----> Sent signal 'SIGUSR1' to 'web-1' container.
This will produce the following log in our application:
2023-01-10 15:13:22.147625033 +0100 CET [web-1] Printing memory Usage
2023-01-10 15:13:22.147633815 +0100 CET [web-1] - heapTotal 6.7 MB
2023-01-10 15:13:22.147633065 +0100 CET [web-1] - rss 38.89 MB
2023-01-10 15:13:22.147634619 +0100 CET [web-1] - heapUsed 4.59 MB
2023-01-10 15:13:22.147635164 +0100 CET [web-1] - external 1.39 MB
2023-01-10 15:13:22.147635509 +0100 CET [web-1] - arrayBuffers 0.03 MB
In this article we discovered the new functionality about sending signal to an application hosted by Scalingo. As we seen this is a very useful feature for debugging purposes. Now, a new field of possibility is opened toward us. Go explore it.
At Scalingo (with our partners) we use trackers on our website.
Some of those are mandatory for the use of our website and can't be refused.
Some others are used to measure our audience as well as to improve our relationship with you or to send you quality content and advertising.