健康サービス



概要

The Health service is designed to allow you to both validate and monitor that your Appwrite server instance and all of its internal components are up and responsive.


ここでは、我々がどのように我々自身の方法で実装することができるかについてより良い考えを与えるために、反応しているネイティブで動くこれらのサービスを使う方法について話します.
このダミーエクスプレスAPIrepository この例に従って依存関係をインストールします.

始める
この例では2つのブランチで作業します.
クイックノート
  • develop ここでは、このチュートリアルに従うすべてのダミーの例があります
  • appwrite-health-system , このブランチには、完全な例を見たい場合のすべての完全な例が含まれています.

  • インストール依存
    AppWriteコアチームからパッケージをインストールする必要があります.npm install node-appwrite --save2 . SDKファイルの作成
    新しいファイルを作るsrc/config/index.js , このファイルは、私たちのExpressアプリとAppwriteサービスの間の接続を作成するのに役立ちます.
    const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    let health = new sdk.Health(client);
    
    client
      .setEndpoint('http://localhost/v1')
      .setProject('PROJECT_ID')
      .setKey('YOUR_API_KEY');
    
    export {
      health,
      client,
    }
    
    3 .サーバファイル
    このためには、いくつかのパッケージをインストールする必要があります.npm install compression router body-parser --saveサーバーを改善するために私に従ってください.
    const compression   = require('compression')
    const express       = require('express')
    const app           = express()
    const router        = express.Router()
    const bodyParser    = require("body-parser")
    
    app.use(compression())
    app.use(bodyParser.json())
    app.use(bodyParser.urlencoded({
        extended: true
    }))
    
    app.disable('x-powered-by')
    app.use(function(req, res, next){
        res.setHeader("Access-Control-Allow-Origin", "*");
        res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
        next()
    })
    
    router.use(function(req, res, next){
        console.log("[ API ] -> /" + req.method + ' -> ' + req.path)
        next()
    })
    
    const system_health = require('./routes/systemHealth')(router);
    
    const port = process.env.PORT || 3000
    app.use("/api", router)
    
    app.use("*", function(req, res){
        res.status(404).json({status: 'ERROR', result: '404'})
    })
    
    app.listen(port, function(){
      console.log('[ API ] -> Server Ready: ' + port)
    })
    
    
    我々が見ることができるように、今、我々はちょうどルートを加えるための完全なサーバーを持っています.に来るsrc/routes/systemHealth.js , このファイルでは、ルートごとにロジックを作成する必要があります.
    コードのコメントに関して、私はあなたが異なったケースを特定するために、私が公式ドキュメンテーションから得た少しの説明をさせます.
    const {
      client,
      health,  
    } = require('../config')
    
    module.exports = function (router){
    
      //* Check the Appwrite HTTP server is up and responsive.
      // This route is used to overview check the health of the system
      router.get('/health', (req, res, next) => {
        // This line contains the system modules that are being checked
        // It will be changed on every route
        let promise = health.get();
    
        promise.then(function (response) {
          res.json(response);
        }, function (error) {
          res.json(error)
        });
      });
    
      //* Check the Appwrite database server is up and connection is successful.
      router.get('/health/db', (req, res, next) => {
        let promise = health.getDB();
    
        promise.then(function (response) {
          res.json(response);
        }, function (error) {
          res.json(error)
        });
      });
    
      //* Check the Appwrite in-memory cache server is up and connection is successful.
      router.get('/health/cache', (req, res, next) => {
        let promise = health.getCache();
    
        promise.then(function (response) {
          res.json(response);
        }, function (error) {
          res.json(error)
        });
      });
    
      /*
        Check the Appwrite server time is synced with Google remote NTP server.
        We use this technology to smoothly handle leap seconds with no disruptive events.
        The Network Time Protocol (NTP) is used by hundreds of millions of computers and devices to synchronize their clocks over the Internet.
        If your computer sets its own clock, it likely uses NTP.
      */
      router.get('/health/time', (req, res, next) => {
        let promise = health.getTime();
    
        promise.then(function (response) {
          res.json(response);
        }, function (error) {
          res.json(error)
        });
      });
    
      //* Get the number of webhooks that are waiting to be processed in the Appwrite internal queue server
      router.get('/health/webhooks', (req, res, next) => {
        let promise = health.getQueueWebhooks();
    
        promise.then(function (response) {
          res.json(response);
        }, function (error) {
          res.json(error)
        });
      });
    
      //* Get the number of tasks that are waiting to be processed in the Appwrite internal queue server.
      router.get('/health/queue/tasks', (req, res, next) => {
        let promise = health.getQueueWebhooks();
    
        promise.then(function (response) {
          res.json(response);
        }, function (error) {
          res.json(error)
        });
      });
    
      //* Get the number of logs that are waiting to be processed in the Appwrite internal queue server.
      router.get('/health/queue/logs', (req, res, next) => {
        let promise = health.getQueueLogs();
    
        promise.then(function (response) {
          res.json(response);
        }, function (error) {
          res.json(error)
        });
      });
    
      //* Get the number of usage stats that are waiting to be processed in the Appwrite internal queue server.
      router.get('/health/queue/usage', (req, res, next) => {
        let promise = health.getQueueUsage();
    
        promise.then(function (response) {
          res.json(response);
        }, function (error) {
          res.json(error)
        });
      });
    
      //* Get the number of certificates that are waiting to be issued against Letsencrypt in the Appwrite internal queue server.
      router.get('/health/queue/certificates', (req, res, next) => {
        let promise = health.getQueueCertificates();
    
        promise.then(function (response) {
          res.json(response);
        }, function (error) {
          res.json(error)
        });
      });
    
      //* To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "health.read" permission scope.
      router.get('/health/queue/functions', (req, res, next) => {
        let promise = health.getQueueFunctions();
    
        promise.then(function (response) {
          res.json(response);
        }, function (error) {
          res.json(error)
        });
      });
    
      //* Check the Appwrite local storage device is up and connection is successful.
      router.get('/health/storage/local', (req, res, next) => {
        let promise = health.getStorageLocal();
    
        promise.then(function (response) {
          res.json(response);
        }, function (error) {
          res.json(error)
        });
      });
    
      //* Check the Appwrite Anti Virus server is up and connection is successful.
      router.get('/health/anti-virus', (req, res, next) => {
        let promise = health.getStorageLocal();
    
        promise.then(function (response) {
          res.json(response);
        }, function (error) {
          res.json(error)
        });
      });
    }
    

    概要
    今、あなたはすべてのサービスを監視するためにサーバーを持っています、そして、彼らがうまく働いているならば、これは非常に役に立ちます.この種のモニターは、我々のアプリでより速い解決を見つけるのを助けます.このHacktoberfest私はappwriteに触れてきたし、私はそれはあなたが開発者としての外観を取る必要がありますツールと言うことができます.この小さなブログを読んでくれてありがとう.
    Full complete example

    次の手順
  • CHAIでテストファイルを作成します.
  • すべてのルートで返されるすべての応答を辞書に書き込みます.
  • クラウドサービスに展開する方法を説明します.