Measuring the execution time of the maintenance script using ntfy

In this article, I will introduce you “ntfy” which I happened to find when looking into something else, and explain how convenient the tool is, taking up a use case involving Hinemos’ maintenance script.

What is ntfy?

ntfy is a python-based tool for sending a notification to applications, such as slack and pushover, when a long-running script finishes.
ntfy, which enables notification to third-party applications, can be installed easily.
For information on which applications a notification can be sent to, refer to the following article.
https://ntfy.readthedocs.io/en/latest/

What we will do here

One of the advantages of ntfy is that a notification can be sent to applications such as slack and pushover when a shell/process finishes, and it can be sent to syslog, too.
This time, we will measure the time required to execute the maintenance script for rebuilding Hinemos’ internal DB by use of ntfy, and output it to systemlog.

Procedure

  1. Installation

Install ntfy from pip.

1

$ pip install ntfy

 

  1. Setting the ntfy configuration file

Various notification settings can be configured in the ”~/.ntfy.yml” file.
Execute the following command to open the file.

1

$ vi ~/.ntfy.yml

Nothing is displayed right after the file was opened.
Enter the following.

1

2

3

backends:

    – systemlog

 

  1. Execution test

Execute the following command.

1

 $ ntfy -t “sleep finish” done sleep 10

Command execution is successful if the following message is output.

1

 Sep 23 17:20:28 hinemos ntfy: [sleep finish] “sleep 10” succeeded in 0:10 minutes

“in 0:10 minutes” indicates the time required to execute the command. As you can see, ntfy not only sends a notification but also measures the time required for command execution.
Also, you can add a title to the output log by using the “-t” option.

 

  1. Measuring the time required to execute the maintenance script

Rebuilding Hinemos Manager’s internal DB

1

 $ ntfy -t “hinemos maintenance finish” done /opt/hinemos/sbin/mng/hinemos_cluster_db.sh -w hinemos

Result of log output

1

 Sep 23 17:28:03 hinemos ntfy: [hinemos maintenance finish] “/opt/hinemos/sbin/mng/hinemos_cluster_db.sh -w hinemos” succeeded in 0:36 minutes

You can see it took 36 seconds to execute the maintenance script.
Although the result was output to systemlog as specified by default this time, you can specify a format of your choice in “~/.ntfy.yml”.

Feedback

Although a notification was sent to systemlog only this time, it can be sent to two or more destinations with just one execution by stating other applications, such as slack, in ntfy configuration file “~/.ntfy.yml”.
ntfy may be useful if you wish to send a notification to two or more destinations, for example, in the case where you need to output the measurement result to systemlog as well as send a notification to slack and the desktop”.

Creating a shell for time measurement using the time command and performing Custom Monitor may be better if you need to measure the time required for execution and perform numeric monitoring with Hinemos.

Reference

Github:https://github.com/dschep/ntfy
Sending a push notification from a linux command line or script to a smartphone (introduction of a tool named “ntfy”)
Sending a notification to Slack when a linux command finishes


ご意見やお問い合わせについて

この記事へのご意見やお問い合わせについては、こちら(お問い合わせフォーム)もしくは
Hinemos営業担当【hsd-sales@atomitech.jp】までご連絡ください。

※お問い合わせフォームからご連絡の場合には、お問い合わせ内容で「Hinemosについて」を選択し、
 本文の冒頭に「Hinemos研究日記_【タイトル名】」とご記載ください。
※メールアドレスへご連絡の場合には、件名を「Hinemos研究日記_【タイトル名】」でご連絡ください。