# User Behavior Monitor Shell Version

`User Behavior Monitor Shell Version` is a project used to monitor the behavior of Cloud POC/Ondemand customers by reading from dbaas `metadb` periodically. It contains several shell script files, which serves different functionality.

# Shell Scripts

## bot.sh
It serves the functionality of reading from `metadb` and sending message to the Feishu chat `TiDB Cloud User Behavior Monitoring` whenever the monitored behavior (including new tenant creation, cluster creation, backuping and restoring, importing of data and cluster scaling in or out) occurs. It run several SQL every 15 minutes and wrap up the result to the chat mentioned above. The script only works for POC and Ondemand customer behavior.
## bot_devtier.sh
It serves the functionality of reading from `metadb` and sending message to the Feishu chat `Dev Tier User Behaviour Monitoring` whenever the monitored behavior (including new tenant creation, cluster creation, backuping and restoring, importing of data and cluster scaling in or out) occurs. It run several SQL every 15 minutes and wrap up the result to the chat mentioned above. The script only works for dev tier (free tier) cutomers .
## doc_updater.sh
By reading from `metadb`, it monitors the creation of new POC tenant accounts and updates it in the Feishu doc `TiDB Cloud Technical PoC`. 
## bot_dw.sh
It extracts needed data from `metadb` and sends it to a (previewed) data warehouse.

# How to use them
The scripts are designed to run on dbaas prod environment. We need to wrap them into yaml files.
## Build
* Run `make` to generate all the yaml files.
* Run `make poc` to generate yaml file used to monitor POC customer behaviors.
* Run `make ondemand` to generate yaml file used to monitor On-demand customer behaviors.
* Run `make devtier` to generate yaml file used to monitor Dev-tier customer behaviors.
* Run `make dw` to generate yaml file used to extract data from `metadb` to the data warehouse.
* Run `make doc-updater` to generate yaml file used to update creation of new poc tenants.

