github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/README.md (about)

     1  <img src="https://user-images.githubusercontent.com/11155743/114745460-57760500-9d57-11eb-9a2c-43fa88171807.png" alt="Asynqmon logo" width="360px" />
     2  
     3  # Web UI for monitoring & administering [Asynq](https://github.com/hibiken/asynq) task queue
     4  
     5  ## Overview
     6  
     7  Asynqmon is a web UI tool for monitoring and administering [Asynq](https://github.com/hibiken/asynq) queues and tasks.
     8  It supports integration with [Prometheus](https://prometheus.io) to display time-series data.
     9  
    10  Asynqmon is both a library that you can include in your web application, as well as a binary that you can simply install and run.
    11  
    12  ## Version Compatibility
    13  
    14  Please make sure the version compatibility with the Asynq package you are using.
    15  
    16  | Asynq version  | WebUI (asynqmon) version |
    17  | -------------- | ------------------------ |
    18  | 0.23.x         | 0.7.x                    |
    19  | 0.22.x         | 0.6.x                    |
    20  | 0.20.x, 0.21.x | 0.5.x                    |
    21  | 0.19.x         | 0.4.x                    |
    22  | 0.18.x         | 0.2.x, 0.3.x             |
    23  | 0.16.x, 0.17.x | 0.1.x                    |
    24  
    25  ## Install the binary
    26  
    27  There're a few options to install the binary:
    28  
    29  - [Download a release binary](#release-binaries)
    30  - [Download a docker image](#docker-image)
    31  - [Build a binary from source](building-from-source)
    32  - [Build a docker image from source](#building-docker-image-locally)
    33  
    34  ### Release binaries
    35  
    36  You can download the release binary for your system from the [releases page](https://github.com/hibiken/asynqmon/releases).
    37  
    38  ### Docker image
    39  
    40  To pull the Docker image:
    41  
    42  ```bash
    43  # Pull the latest image
    44  docker pull hibiken/asynqmon
    45  
    46  # Or specify the image by tag
    47  docker pull hibiken/asynqmon[:tag]
    48  ```
    49  
    50  ### Building from source
    51  
    52  To build Asynqmon from source code, make sure you have Go installed ([download](https://golang.org/dl/)). Version `1.16` or higher is required. You also need [Node.js](https://nodejs.org/) and [Yarn](https://yarnpkg.com/) installed in order to build the frontend assets.
    53  
    54  Download the source code of this repository and then run:
    55  
    56  ```bash
    57  make build
    58  ```
    59  
    60  The `asynqmon` binary should be created in the current directory.
    61  
    62  ### Building Docker image locally
    63  
    64  To build Docker image locally, run:
    65  
    66  ```bash
    67  make docker
    68  ```
    69  
    70  ## Run the binary
    71  
    72  To use the defaults, simply run and open http://localhost:8080.
    73  
    74  ```bash
    75  # with a binary
    76  ./asynqmon
    77  
    78  # with a docker image
    79  docker run --rm \
    80      --name asynqmon \
    81      -p 8080:8080 \
    82      hibiken/asynqmon
    83  ```
    84  
    85  By default, Asynqmon web server listens on port `8080` and connects to a Redis server running on `127.0.0.1:6379`.
    86  
    87  To see all available flags, run:
    88  
    89  ```bash
    90  # with a binary
    91  ./asynqmon --help
    92  
    93  # with a docker image
    94  docker run hibiken/asynqmon --help
    95  ```
    96  
    97  Here's the available flags:
    98  
    99  _Note_: Use `--redis-url` to specify address, db-number, and password with one flag value; Alternatively, use `--redis-addr`, `--redis-db`, and `--redis-password` to specify each value.
   100  
   101  | Flag                              | Env                       | Description                                                                                                                  | Default          |
   102  | --------------------------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ---------------- |
   103  | `--port`(int)                     | `PORT`                    | port number to use for web ui server                                                                                         | 8080             |
   104  | `---redis-url`(string)            | `REDIS_URL`               | URL to redis or sentinel server. See [godoc](https://pkg.go.dev/github.com/hibiken/asynq#ParseRedisURI) for supported format | ""               |
   105  | `--redis-addr`(string)            | `REDIS_ADDR`              | address of redis server to connect to                                                                                        | "127.0.0.1:6379" |
   106  | `--redis-db`(int)                 | `REDIS_DB`                | redis database number                                                                                                        | 0                |
   107  | `--redis-password`(string)        | `REDIS_PASSWORD`          | password to use when connecting to redis server                                                                              | ""               |
   108  | `--redis-cluster-nodes`(string)   | `REDIS_CLUSTER_NODES`     | comma separated list of host:port addresses of cluster nodes                                                                 | ""               |
   109  | `--redis-tls`(string)             | `REDIS_TLS`               | server name for TLS validation used when connecting to redis server                                                          | ""               |
   110  | `--redis-insecure-tls`(bool)      | `REDIS_INSECURE_TLS`      | disable TLS certificate host checks                                                                                          | false            |
   111  | `--enable-metrics-exporter`(bool) | `ENABLE_METRICS_EXPORTER` | enable prometheus metrics exporter to expose queue metrics                                                                   | false            |
   112  | `--prometheus-addr`(string)       | `PROMETHEUS_ADDR`         | address of prometheus server to query time series                                                                            | ""               |
   113  | `--read-only`(bool)               | `READ_ONLY`               | use web UI in read-only mode                                                                                                 | false            |
   114  
   115  ### Connecting to Redis
   116  
   117  To connect to a **single redis server**, use either `--redis-url` or (`--redis-addr`, `--redis-db`, and `--redis-password`).
   118  
   119  Example:
   120  
   121  ```sh
   122  $ ./asynqmon --redis-url=redis://:mypassword@localhost:6380/2
   123  
   124  $ ./asynqmon --redis-addr=localhost:6380 --redis-db=2 --redis-password=mypassword
   125  ```
   126  
   127  To connect to **redis-sentinels**, use `--redis-url`.
   128  
   129  Example:
   130  
   131  ```sh
   132  $ ./asynqmon --redis-url=redis-sentinel://:mypassword@localhost:5000,localhost:5001,localhost:5002?master=mymaster
   133  ```
   134  
   135  To connect to a **redis-cluster**, use `--redis-cluster-nodes`.
   136  
   137  Example:
   138  
   139  ```sh
   140  $ ./asynqmon --redis-cluster-nodes=localhost:7000,localhost:7001,localhost:7002,localhost:7003,localhost:7004,localhost:7006
   141  ```
   142  
   143  ### Integration with Prometheus
   144  
   145  The binary supports two flags to enable integration with [Prometheus](https://prometheus.io/).
   146  
   147  First, enable metrics exporter to expose queue metrics to Prometheus server by passing `--enable-metrics-exporter` flag.
   148  The metrics data is now available under `/metrics` for Prometheus server to scrape.
   149  
   150  Once the metrics data is collected by a Prometheus server, you can pass the address of the Prometheus server to asynqmon to query the time-series data.
   151  The address can be specified via `--prometheus-addr`. This enables the metrics view on the Web UI.
   152  
   153  <img width="1532" alt="Screen Shot 2021-12-19 at 4 37 19 PM" src="https://user-images.githubusercontent.com/10953044/146696852-25916465-07f0-4ed5-af31-18be02390bcb.png">
   154  
   155  ### Examples
   156  
   157  ```bash
   158  # with a local binary; custom port and connect to redis server at localhost:6380
   159  ./asynqmon --port=3000 --redis-addr=localhost:6380
   160  
   161  # with prometheus integration enabled
   162  ./asynqmon --enable-metrics-exporter --prometheus-addr=http://localhost:9090
   163  
   164  # with Docker (connect to a Redis server running on the host machine)
   165  docker run --rm \
   166      --name asynqmon \
   167      -p 3000:3000 \
   168      hibiken/asynqmon --port=3000 --redis-addr=host.docker.internal:6380
   169  
   170  # with Docker (connect to a Redis server running in the Docker container)
   171  docker run --rm \
   172      --name asynqmon \
   173      --network dev-network \
   174      -p 8080:8080 \
   175      hibiken/asynqmon --redis-addr=dev-redis:6379
   176  ```
   177  
   178  Next, go to [localhost:8080](http://localhost:8080) and see Asynqmon dashboard:
   179  
   180  ![Web UI Queues View](https://user-images.githubusercontent.com/11155743/114697016-07327f00-9d26-11eb-808c-0ac841dc888e.png)
   181  
   182  **Tasks view**
   183  
   184  ![Web UI TasksView](https://user-images.githubusercontent.com/11155743/114697070-1f0a0300-9d26-11eb-855c-d3ec263865b7.png)
   185  
   186  **Settings and adaptive dark mode**
   187  
   188  ![Web UI Settings and adaptive dark mode](https://user-images.githubusercontent.com/11155743/114697149-3517c380-9d26-11eb-9f7a-ae2dd00aad5b.png)
   189  
   190  ## Import as a Library
   191  
   192  [![GoDoc](https://godoc.org/github.com/hibiken/asynqmon?status.svg)](https://godoc.org/github.com/hibiken/asynqmon)
   193  
   194  Asynqmon is also a library which can be imported into an existing web application.
   195  
   196  Example with [net/http](https://pkg.go.dev/net/http):
   197  
   198  ```go
   199  package main
   200  
   201  import (
   202  	"log"
   203  	"net/http"
   204  
   205  	"github.com/hibiken/asynq"
   206  	"github.com/hibiken/asynqmon"
   207  )
   208  
   209  func main() {
   210  	h := asynqmon.New(asynqmon.Options{
   211  		RootPath: "/monitoring", // RootPath specifies the root for asynqmon app
   212  		RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"},
   213  	})
   214  
   215      // Note: We need the tailing slash when using net/http.ServeMux.
   216  	http.Handle(h.RootPath()+"/", h)
   217  
   218  	// Go to http://localhost:8080/monitoring to see asynqmon homepage.
   219  	log.Fatal(http.ListenAndServe(":8080", nil))
   220  }
   221  ```
   222  
   223  Example with [gorilla/mux](https://pkg.go.dev/github.com/gorilla/mux):
   224  
   225  ```go
   226  package main
   227  
   228  import (
   229  	"log"
   230  	"net/http"
   231  
   232  	"github.com/gorilla/mux"
   233  	"github.com/hibiken/asynq"
   234  	"github.com/hibiken/asynqmon"
   235  )
   236  
   237  func main() {
   238  	h := asynqmon.New(asynqmon.Options{
   239  		RootPath: "/monitoring", // RootPath specifies the root for asynqmon app
   240  		RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"},
   241  	})
   242  
   243  	r := mux.NewRouter()
   244  	r.PathPrefix(h.RootPath()).Handler(h)
   245  
   246  	srv := &http.Server{
   247  		Handler: r,
   248  		Addr:    ":8080",
   249  	}
   250  
   251  	// Go to http://localhost:8080/monitoring to see asynqmon homepage.
   252  	log.Fatal(srv.ListenAndServe())
   253  }
   254  ```
   255  
   256  Example with [labstack/echo](https://github.com/labstack/echo)):
   257  
   258  
   259  ```go
   260  package main
   261  
   262  import (
   263  	"github.com/labstack/echo/v4"
   264  	"github.com/hibiken/asynq"
   265  	"github.com/hibiken/asynqmon"
   266  )
   267  
   268  func main() {
   269          e := echo.New()
   270  
   271  	mon := asynqmon.New(asynqmon.Options{
   272  		RootPath: "/monitoring/tasks",
   273  		RedisConnOpt: asynq.RedisClientOpt{
   274  			Addr: ":6379",
   275  			Password: "",
   276  			DB: 0,
   277  		},
   278  	})
   279  	e.Any("/monitoring/tasks/*", echo.WrapHandler(mon))
   280  	e.Start(":8080")
   281  }
   282  ```
   283  
   284  
   285  ## License
   286  
   287  Copyright (c) 2019-present [Ken Hibino](https://github.com/hibiken) and [Contributors](https://github.com/hibiken/asynqmon/graphs/contributors). `Asynqmon` is free and open-source software licensed under the [MIT License](https://github.com/hibiken/asynq/blob/master/LICENSE). Official logo was created by [Vic Shóstak](https://github.com/koddr) and distributed under [Creative Commons](https://creativecommons.org/publicdomain/zero/1.0/) license (CC0 1.0 Universal).