简体   繁体   中英

How to keep stats for a node.js app deployed on google cloud app engine and keep my data persistent

I have a node.js application where I serve articles that are stored in memory like this:

let articles = [];

module.exports.addArticle = function(req, res) {
  articles.push('New Article');
  res.send('Ok');
}

module.exports.home = function(req, res) {
  res.json(articles);
}

This works fine when I add articles and list them through home route. But after a day passes, I see all my articles are gone.

I deployed this app on google cloud using:

git clone myrepo
cd myrepo
yarn build
gcloud app deploy

This is my app.yaml :

runtime: nodejs12

env_variables:
  BUCKET_NAME: "example-gcs-bucket"

handlers:
- url: /.*
  secure: always
  script: auto

I am thinking google restarts my node app or launches different instances of it, but I am not sure. How does google cloud app engine works in that way, and how do I monitor what's going on with my app, keeping stats like how many times it restarts or launches new instances incoming requests things like that.

Also what other simple storage solutions are available through google cloud app so my articles are persistent.

As stated on your app.yaml , you are using Automatic scalling . App engine is expected to shut down instances where using the automatic scaling setup due to a variety of reasons such as instances have been moved to another server or that the machine where the container was running got restarted and based on usage patterns.

You may consider using manual or basic scaling according to Google Document and avoid persisting data on memory as app engine is designed for stateless applications. If you want to store your articles or array, I would recommend to use Firestore .

To monitor your application and logs, go to Cloud Logging then point your resources in App Engine version or by following these steps::

  • App Engine > Versions
  • Hover your mouse to preferred version > look for Diagnose column
  • Click Tools > Click Logs .

It will direct you to Cloud Logging to view the logs of your App engine application version. You can also view the graph of your creation of instance, traffic, memory usage and etc. in App Engine > Dashboard . There are two dropdown button in the console, the first one is for your App Engine version and the second display the default is Summary that you can change to Instances, Memory usage and etc. it will instant change the data of the graph below.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM