### Install Asynqmon Library Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/00-START-HERE.md Use 'go get' to install the Asynqmon library into your Go project. This is the first step for integrating Asynqmon into an existing application. ```bash go get github.com/hibiken/asynqmon ``` -------------------------------- ### Minimal Asynqmon Setup Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/README.md Demonstrates the most basic setup for Asynqmon, initializing it with Redis connection options and mounting it to the default HTTP root path. ```go h := asynqmon.New(asynqmon.Options{ RedisConnOpt: asynq.RedisClientOpt{Addr: "localhost:6379"}, }) defer h.Close() http.Handle("/", h) http.ListenAndServe(":8080", nil) ``` -------------------------------- ### Minimal Asynqmon Setup Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md This is the most basic setup for Asynqmon. It requires importing the necessary packages and creating an Asynqmon handler with Redis connection options. The handler is then registered with an HTTP server. ```go package main import ( "log" "net/http" "github.com/hibiken/asynq" "github.com/hibiken/asynqmon" ) func main() { // Create handler h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: "localhost:6379"}, }) defer h.Close() // Register with HTTP server http.Handle(h.RootPath()+"/", h) // Start server log.Fatal(http.ListenAndServe(":8000", nil)) // Visit: http://localhost:8000/monitoring } ``` -------------------------------- ### Minimal Setup for Asynqmon HTTP Handler Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/00-START-HERE.md This snippet shows the minimal setup required to integrate Asynqmon as an HTTP handler in your Go application. It demonstrates how to create an Asynqmon handler and register it with an HTTP multiplexer. ```go package main import ( "context" "log" "net/http" "github.com/hibiken/asynqmon" ) func main() { // Create a new Asynqmon handler. h := asynqmon.NewHTTPHandler(asynqmon.DefaultMux) // Register the handler with your HTTP mux. http.Handle("/asynqmon/", h) // Start the HTTP server. log.Println("Starting server on :8080") log.Fatal(http.ListenAndServe(":8080", nil)) } ``` -------------------------------- ### Programmatic API Call Example Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/00-START-HERE.md This example demonstrates how to programmatically interact with the Asynqmon API using HTTP client requests. It shows examples for fetching queue information and triggering task runs. ```bash # Use HTTP client to call: # GET /api/queues # POST /api/queues/{qname}/pending_tasks/{id}:run ``` -------------------------------- ### HTTPHandler Usage Example Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/http-handler.md Integrate the Asynqmon HTTPHandler into a Go HTTP server. Mount the handler at the specified RootPath and start the server. ```go package main import ( "log" "net/http" "github.com/hibiken/asynq" "github.com/hibiken/asynqmon" ) func main() { h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"}, }) defer h.Close() http.Handle(h.RootPath()+"/", h) log.Fatal(http.ListenAndServe(":8000", nil)) } ``` -------------------------------- ### Download and Install Asynqmon Binary Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Download the pre-compiled binary from the releases page or build it from source using make. ```bash wget https://github.com/hibiken/asynqmon/releases/download/v0.7.0/asynqmon-0.7.0-linux-amd64.zip unzip asynqmon-0.7.0-linux-amd64.zip ``` ```bash git clone https://github.com/hibiken/asynqmon.git cd asynqmon make build ``` -------------------------------- ### Minimal Binary Usage Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/00-START-HERE.md Run the Asynqmon binary with minimal configuration. This command starts the UI and connects to Redis on localhost. ```bash # Minimal binary usage ./asynqmon --port 8080 --redis-addr localhost:6379 ``` -------------------------------- ### Integrate Asynqmon with gorilla/mux Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/http-handler.md This example shows how to integrate Asynqmon with the gorilla/mux router. It uses PathPrefix to route monitoring requests. ```go package main import ( "log" "net/http" "github.com/gorilla/mux" "github.com/hibiken/asynq" "github.com/hibiken/asynqmon" ) func main() { h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"}, }) defer h.Close() r := mux.NewRouter() r.PathPrefix(h.RootPath()).Handler(h) srv := &http.Server{ Handler: r, Addr: ":8080", } log.Fatal(srv.ListenAndServe()) // Visit http://localhost:8080/monitoring } ``` -------------------------------- ### Usage Example for ResultFormatterFunc Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/formatters.md Provides a basic example of creating a ResultFormatterFunc that simply returns the result as a string. ```go formatter := asynqmon.ResultFormatterFunc(func(taskType string, result []byte) string { return string(result) }) ``` -------------------------------- ### Integrate Asynqmon with Gorilla Mux Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md This example shows how to mount the Asynqmon handler within a Gorilla Mux router. Ensure the RootPath is correctly configured. ```go h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: "localhost:6379"}, }) deffer h.Close() r := mux.NewRouter() r.PathPrefix(h.RootPath()).Handler(h) http.ListenAndServe(":8080", r) ``` -------------------------------- ### Production Asynqmon Setup Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/README.md Illustrates a production-ready configuration for Asynqmon, including a custom root path, specific Redis connection, Prometheus endpoint, and read-only mode. ```go h := asynqmon.New(asynqmon.Options{ RootPath: "/tasks/monitor", RedisConnOpt: asynq.RedisClientOpt{Addr: "redis.prod:6379"}, PrometheusAddress: "http://prometheus.prod:9090", ReadOnly: true, }) defer h.Close() mux := http.NewServeMux() mux.Handle(h.RootPath()+"/", h) http.ListenAndServe(":8000", mux) ``` -------------------------------- ### Integrate Asynqmon with gorilla/mux Source: https://github.com/hibiken/asynqmon/blob/master/README.md Integrate Asynqmon into a web application using the gorilla/mux router. This example shows how to set up the router and server with Asynqmon's handler. ```go package main import ( "log" "net/http" "github.com/gorilla/mux" "github.com/hibiken/asynq" "github.com/hibiken/asynqmon" ) func main() { h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", // RootPath specifies the root for asynqmon app RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"}, }) r := mux.NewRouter() r.PathPrefix(h.RootPath()).Handler(h) srv := &http.Server{ Handler: r, Addr: ":8080", } // Go to http://localhost:8080/monitoring to see asynqmon homepage. log.Fatal(srv.ListenAndServe()) } ``` -------------------------------- ### Integrate Asynqmon with Gin Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md This example shows how to integrate Asynqmon with a Gin web framework application, using Gin's wrapper for HTTP handlers. ```go h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: "localhost:6379"}, }) deffer h.Close() r := gin.Default() r.Any("/monitoring/*path", gin.WrapF(h.ServeHTTP)) r.Run(":8080") ``` -------------------------------- ### Install npm Dependencies with Yarn Source: https://github.com/hibiken/asynqmon/blob/master/ui/README.md Installs all necessary npm packages for the React UI. Ensure you are in the 'ui/' directory before running. ```bash yarn ``` -------------------------------- ### Run asynqmon Basic Usage Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/binary-flags.md Starts the asynqmon web server with default settings. It will listen on port 8080 and connect to Redis at 127.0.0.1:6379. ```bash ./asynqmon ``` -------------------------------- ### Initialize and Cleanup Asynqmon Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/configuration.md Initialize Asynqmon with options and ensure cleanup by deferring the Close() method. This registers the handler with an HTTP server and starts the server. ```go h := asynqmon.New(opts) defer h.Close() // Register with HTTP server http.Handle(h.RootPath()+" பான", h) // Listen and serve log.Fatal(http.ListenAndServe(":8080", nil)) ``` -------------------------------- ### Connect to a Single Redis Server Source: https://github.com/hibiken/asynqmon/blob/master/README.md Examples demonstrating how to connect Asynqmon to a single Redis server using either the `--redis-url` flag or individual flags for address, database, and password. ```sh $ ./asynqmon --redis-url=redis://:mypassword@localhost:6380/2 $ ./asynqmon --redis-addr=localhost:6380 --redis-db=2 --redis-password=mypassword ``` -------------------------------- ### Integrate Asynqmon with Echo Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md This example demonstrates integrating Asynqmon with an Echo web framework application. The handler is wrapped to be compatible with Echo's routing. ```go h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: "localhost:6379"}, }) deffer h.Close() e := echo.New() e.Any("/monitoring/*", echo.WrapHandler(h)) e.Start(":8080") ``` -------------------------------- ### Usage Example for PayloadFormatterFunc Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/formatters.md Demonstrates how to create a custom PayloadFormatterFunc to format email task payloads. ```go formatter := asynqmon.PayloadFormatterFunc(func(taskType string, payload []byte) string { switch taskType { case "send_email": var email map[string]string json.Unmarshal(payload, &email) return "Email to: " + email["to"] default: return string(payload) } }) ``` -------------------------------- ### Initialize Asynqmon for Production (Read-Only) Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/configuration.md Configure Asynqmon for production in read-only mode. This setup connects to a production Redis instance and Prometheus, restricting modifications. ```go h := asynqmon.New(asynqmon.Options{ RootPath: "/tasks/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: "redis.prod:6379"}, PrometheusAddress: "http://prometheus.prod:9090", ReadOnly: true, // Restrict to viewing only }) ``` -------------------------------- ### Import Asynqmon Library in Go Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/INDEX.md Import the Asynqmon library into your Go application to start using its features. This is the first step for integrating Asynqmon into your project. ```go import "github.com/hibiken/asynqmon" ``` -------------------------------- ### Run Local Development Server Source: https://github.com/hibiken/asynqmon/blob/master/ui/README.md Starts a local development server for the React UI, accessible at http://localhost:3000/. The page auto-reloads on code changes. ```bash yarn start ``` -------------------------------- ### Run Asynqmon using Docker (Basic) Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/binary-flags.md Starts Asynqmon in a Docker container with default settings. The container is detached and named 'asynqmon', with port 8080 mapped. ```bash docker run -d \ --name asynqmon \ -p 8080:8080 \ hibiken/asynqmon ``` -------------------------------- ### Configure Asynqmon with Read-Only Mode Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/00-START-HERE.md This example shows how to configure Asynqmon to run in read-only mode. This is useful for monitoring production queues without allowing any modifications. ```go // Set ReadOnly: true in library OR --read-only flag asynqmon.NewHTTPHandler(asynqmon.DefaultMux, asynqmon.WithReadOnly(true)) ``` -------------------------------- ### Run Asynqmon in Production with Read-Only and Prometheus Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/binary-flags.md A comprehensive example for production deployment, setting a custom port, connecting to a secure Redis instance, enabling Prometheus metrics, and activating read-only mode. The Redis password is read from a file. ```bash ./asynqmon \ --port 8080 \ --redis-addr redis.prod:6379 \ --redis-password "$(cat /secrets/redis-password)" \ --prometheus-addr http://prometheus.prod:9090 \ --enable-metrics-exporter \ --read-only ``` -------------------------------- ### Configure Redis Sentinel Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/configuration.md Connect to a Redis Sentinel setup by providing the Sentinel connection URL, including password and master name. ```bash ./asynqmon --redis-url "redis-sentinel://:password@localhost:26379,localhost:26380,localhost:26381?master=mymaster" ``` -------------------------------- ### Integrate Asynqmon with labstack/echo Source: https://github.com/hibiken/asynqmon/blob/master/README.md Embed Asynqmon into an application using the labstack/echo framework. This example configures Echo to serve the Asynqmon handler at a specified path. ```go package main import ( "github.com/labstack/echo/v4" "github.com/hibiken/asynq" "github.com/hibiken/asynqmon" ) func main() { e := echo.New() mon := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring/tasks", RedisConnOpt: asynq.RedisClientOpt{ Addr: ":6379", Password: "", DB: 0, }, }) e.Any("/monitoring/tasks/*", echo.WrapHandler(mon)) e.Start(":8080") } ``` -------------------------------- ### Troubleshoot Metrics Not Showing Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/binary-flags.md Ensure Prometheus is running by checking its API endpoint. Then, start Asynqmon with the --prometheus-addr flag pointing to your Prometheus instance. ```bash # Ensure Prometheus is running curl http://localhost:9090/api/v1/query # Then start Asynqmon with Prometheus configured ./asynqmon --prometheus-addr http://localhost:9090 ``` -------------------------------- ### Initialize Asynqmon for Production with Redis Cluster and TLS Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/configuration.md Configure Asynqmon for a production environment using a Redis cluster with TLS enabled. This setup is for high-availability and secure connections. ```go redisOpt := asynq.RedisClusterClientOpt{ Addrs: []string{ "redis1.prod:6379", "redis2.prod:6379", "redis3.prod:6379", }, Password: os.Getenv("REDIS_PASSWORD"), TLSConfig: &tls.Config{ ServerName: "redis.prod", }, } h := asynqmon.New(asynqmon.Options{ RootPath: "/tasks", RedisConnOpt: redisOpt, PrometheusAddress: "http://prometheus.prod:9090", ReadOnly: true, }) ``` -------------------------------- ### Configure Asynqmon with Custom Formatters Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/http-handler.md Integrate Asynqmon with custom payload and result formatters for enhanced data presentation. This example uses JSON formatting. ```go package main import ( "encoding/json" "log" "net/http" "github.com/hibiken/asynq" "github.com/hibiken/asynqmon" ) func main() { h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"}, PayloadFormatter: asynqmon.PayloadFormatterFunc(func(taskType string, payload []byte) string { // Custom JSON formatting var data map[string]interface{} if err := json.Unmarshal(payload, &data); err != nil { return string(payload) } formatted, _ := json.MarshalIndent(data, "", " ") return string(formatted) }), ResultFormatter: asynqmon.ResultFormatterFunc(func(taskType string, result []byte) string { return string(result) }), }) defer h.Close() http.Handle(h.RootPath()+"/", h) log.Fatal(http.ListenAndServe(":8080", nil)) } ``` -------------------------------- ### Create New HTTPHandler Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/http-handler.md Use the New function to create an HTTPHandler instance. Ensure Redis connection options are provided. The RootPath must start with '/'. ```go func New(opts Options) *HTTPHandler ``` -------------------------------- ### Access Log Format Example Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/binary-flags.md The binary outputs access logs in Apache Common Log Format to stdout. The format includes host, user, date, request method, path, protocol, status, and size. ```log 127.0.0.1 - - [25/Jun/2026:15:04:05 +0000] "GET /api/queues HTTP/1.1" 200 1234 ``` -------------------------------- ### Configure Asynqmon for Redis Sentinel High Availability Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/binary-flags.md Connects Asynqmon to a Redis Sentinel setup for high availability. Specify the Sentinel addresses and the master name. ```bash ./asynqmon --redis-url "redis-sentinel://:password@sentinel1:26379,sentinel2:26379,sentinel3:26379?master=mymaster" ``` -------------------------------- ### Connect to Redis Sentinels Source: https://github.com/hibiken/asynqmon/blob/master/README.md Use the `--redis-url` flag to connect Asynqmon to a Redis setup managed by sentinels. Specify the sentinel addresses and the master name. ```sh $ ./asynqmon --redis-url=redis-sentinel://:mypassword@localhost:5000,localhost:5001,localhost:5002?master=mymaster ``` -------------------------------- ### Initialize and Integrate HTTPHandler Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/README.md Demonstrates how to create a new HTTPHandler instance with specified options and integrate it into a Go HTTP server. Ensure to close the handler when done. ```go h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"}, }) defer h.Close() http.Handle(h.RootPath()+"/", h) http.ListenAndServe(":8000", nil) ``` -------------------------------- ### View Scheduler Entries Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Get a list of all scheduled entries. ```APIDOC ## GET /api/scheduler_entries ### Description Retrieves a list of all configured scheduler entries. ### Method GET ### Endpoint /api/scheduler_entries ``` -------------------------------- ### Initialize Asynqmon for Development Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/configuration.md Configure Asynqmon for local development. Connects to a local Redis instance and sets the root path for the monitoring interface. ```go h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: "localhost:6379"}, ReadOnly: false, }) ``` -------------------------------- ### View Workers/Servers Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Get a list of all registered workers or servers. ```APIDOC ## GET /api/servers ### Description Retrieves a list of all active workers or servers registered with Asynqmon. ### Method GET ### Endpoint /api/servers ``` -------------------------------- ### Get queue details Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Retrieves detailed information about a specific queue. ```APIDOC ## GET /api/queues/{qname} ### Description Get queue details ### Method GET ### Endpoint /api/queues/{qname} ### Parameters #### Path Parameters - **qname** (string) - Required - The name of the queue ``` -------------------------------- ### Initialize Asynqmon for Staging with Prometheus Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/configuration.md Set up Asynqmon for a staging environment, including a connection to a staging Redis instance and Prometheus monitoring. ```go h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: "redis.staging:6379"}, PrometheusAddress: "http://prometheus.staging:9090", ReadOnly: false, }) ``` -------------------------------- ### View Redis Info Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Get information about the Redis instance used by Asynqmon. ```APIDOC ## GET /api/redis_info ### Description Retrieves information about the Redis instance that Asynqmon is connected to. ### Method GET ### Endpoint /api/redis_info ``` -------------------------------- ### Get Task Details Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Retrieve detailed information about a specific task by its ID. ```APIDOC ## GET /api/queues/{queue_name}/tasks/{task_id} ### Description Retrieves detailed information about a specific task. ### Method GET ### Endpoint /api/queues/{queue_name}/tasks/{task_id} ### Parameters #### Path Parameters - **queue_name** (string) - Required - The name of the queue. - **task_id** (string) - Required - The ID of the task. ``` -------------------------------- ### Get Single Task Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/endpoints.md Retrieves detailed information about a specific task using its ID. ```APIDOC ## GET /api/queues/{qname}/tasks/{task_id} ### Description Fetches detailed information for a single task identified by its ID. ### Method GET ### Endpoint /api/queues/{qname}/tasks/{task_id} ### Response #### Success Response (200) - **Task** (object) - Detailed task object including fields like `id`, `queue`, `type`, `payload`, `state`, `result`, `completed_at`, etc. #### Error Response (500) - **Internal Server Error** - Indicates an error occurred on the Redis server. ``` -------------------------------- ### Get Prometheus Metrics Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Fetch Prometheus metrics for Asynqmon, optionally specifying a duration. ```APIDOC ## GET /api/metrics ### Description Retrieves Prometheus metrics for Asynqmon. Requires `PrometheusAddress` to be configured. ### Method GET ### Endpoint /api/metrics ### Parameters #### Query Parameters - **duration_sec** (integer) - Optional - The duration in seconds for which to collect metrics. Defaults to 3600 (1 hour). ``` -------------------------------- ### View Active Tasks Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Get a paginated list of active tasks for a specific queue. ```APIDOC ## GET /api/queues/{queue_name}/active_tasks ### Description Retrieves a paginated list of active tasks for a given queue. ### Method GET ### Endpoint /api/queues/{queue_name}/active_tasks ### Parameters #### Path Parameters - **queue_name** (string) - Required - The name of the queue. #### Query Parameters - **page_size** (integer) - Optional - The number of tasks to return per page. Defaults to 20. - **page** (integer) - Optional - The page number to retrieve. Defaults to 1. ``` -------------------------------- ### Display Asynqmon Help Information Source: https://github.com/hibiken/asynqmon/blob/master/README.md View all available command-line flags for the Asynqmon binary or Docker image to customize its behavior. ```bash # with a binary ./asynqmon --help # with a docker image docker run hibiken/asynqmon --help ``` -------------------------------- ### Build asynqmon Binary from Source Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/binary-flags.md Builds the asynqmon binary from the project's source code. The resulting binary will be placed in the root directory. ```bash make build # Creates ./asynqmon binary ``` -------------------------------- ### Get Single Task Endpoint Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/endpoints.md Endpoint to fetch detailed information for a specific task within a queue. ```http GET /api/queues/{qname}/tasks/{task_id} ``` -------------------------------- ### Binary in Read-Only Mode Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/00-START-HERE.md Start the Asynqmon binary in read-only mode. This mode prevents any modifications to the task queues. ```bash # Read-only mode ./asynqmon --read-only ``` -------------------------------- ### Options Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/types.md Configuration structure for HTTPHandler initialization. ```APIDOC ## Options ### Description Configuration structure for HTTPHandler initialization. ### Fields - **RootPath** (string) - URL path where asynqmon is mounted (must start with "/" if provided) - **RedisConnOpt** (asynq.RedisConnOpt) - Redis connection configuration (required) - **PayloadFormatter** (PayloadFormatter) - Custom formatter for task payloads (optional, uses default if nil) - **ResultFormatter** (ResultFormatter) - Custom formatter for task results (optional, uses default if nil) - **PrometheusAddress** (string) - Address of Prometheus server for metrics (optional) - **ReadOnly** (bool) - If true, restricts API to read-only operations (GET only) ``` -------------------------------- ### Asynqmon Binary Flags for Configuration Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/00-START-HERE.md This snippet illustrates common command-line flags used to configure the Asynqmon binary. These flags allow for flexible deployment and customization. ```bash # Example flags for running Asynqmon binary # --read-only # --redis-addr=redis://localhost:6379 # --redis-sentinel-addrs=redis://localhost:26379,redis://localhost:26380 # --redis-sentinel-master=mymaster # --prometheus-listen-addr=:9090 ``` -------------------------------- ### Queue Management Endpoints Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/README.md Endpoints for managing queues, including listing, getting details, deleting, pausing, and resuming queues. ```APIDOC ## GET /api/queues ### Description List all queues. ### Method GET ### Endpoint /api/queues ``` ```APIDOC ## GET /api/queues/{qname} ### Description Get queue details. ### Method GET ### Endpoint /api/queues/{qname} ``` ```APIDOC ## DELETE /api/queues/{qname} ### Description Delete an empty queue. ### Method DELETE ### Endpoint /api/queues/{qname} ``` ```APIDOC ## POST /api/queues/{qname}:pause ### Description Pause a queue. ### Method POST ### Endpoint /api/queues/{qname}:pause ``` ```APIDOC ## POST /api/queues/{qname}:resume ### Description Resume a queue. ### Method POST ### Endpoint /api/queues/{qname}:resume ``` ```APIDOC ## GET /api/queue_stats ### Description Get queue statistics. ### Method GET ### Endpoint /api/queue_stats ``` -------------------------------- ### Go Struct for Worker Information Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/types.md Details about an active worker, including the task it's processing, its queue, and start time. ```go type workerInfo struct { TaskID string // Task ID being processed Queue string // Queue name TaskType string // Task type TaskPayload string // Formatted task payload Started string // RFC3339 start time } ``` -------------------------------- ### Asynqmon Integration with Gorilla Mux Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/README.md Demonstrates how to integrate Asynqmon with the Gorilla Mux router, allowing for more advanced routing configurations. ```go r := mux.NewRouter() r.PathPrefix(h.RootPath()).Handler(h) http.ListenAndServe(":8080", r) ``` -------------------------------- ### Run Asynqmon as Standalone Binary Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/00-START-HERE.md Download and run the Asynqmon binary directly. Configure the port and Redis address using command-line flags. ```bash # Download or build wget https://github.com/hibiken/asynqmon/releases/download/v0.7.0/asynqmon-0.7.0-linux-amd64.zip unzip asynqmon-0.7.0-linux-amd64.zip chmod +x asynqmon # Run ./asynqmon --port 8080 --redis-addr localhost:6379 # Visit: http://localhost:8080 ``` -------------------------------- ### Configure Asynqmon using Environment Variables Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/binary-flags.md Demonstrates setting Asynqmon configuration options via environment variables. This is an alternative to command-line flags and is often used in containerized environments. ```bash export PORT=3000 export REDIS_ADDR=redis.example.com export REDIS_DB=2 export REDIS_PASSWORD=secret export PROMETHEUS_ADDR=http://prometheus:9090 export ENABLE_METRICS_EXPORTER=true export READ_ONLY=true export MAX_PAYLOAD_LENGTH=150 ./asynqmon ``` -------------------------------- ### Get Redis Info Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/endpoints.md Retrieves information about the Redis server or cluster. This endpoint is useful for monitoring the health and status of your Redis instance. ```json { "address": "string", "info": "map[string]string", "raw_info": "string", "cluster": false } ``` ```json { "address": "string", "info": "map[string]string", "raw_info": "string", "cluster": true, "raw_cluster_nodes": "string", "queue_locations": [ { "queue": "string", "keyslot": "int64", "nodes": ["string"] } ] } ``` -------------------------------- ### Configure Asynqmon with Redis Server with Password Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/configuration.md Initialize Asynqmon with a Redis server that requires authentication. Specify the password and database number. ```go redisOpt := asynq.RedisClientOpt{ Addr: "localhost:6379", Password: "mypassword", DB: 2, } h := asynqmon.New(asynqmon.Options{ RedisConnOpt: redisOpt, }) ``` -------------------------------- ### activeTask JSON Representation Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/types.md The JSON format for an activeTask. Includes fields from baseTask and adds start time, deadline, and orphaned status. ```json { "id": "string", "type": "string", "payload": "string", "queue": "string", "max_retry": 0, "retried": 0, "error_message": "string", "start_time": "RFC3339 or '-“", "deadline": "RFC3339 or '-“", "is_orphaned": false } ``` -------------------------------- ### API Response Format - Single Resource Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Example JSON structure for API responses that return a single resource, such as a specific task or server. ```json // Single resource { "id": "...", "type": "...", "...": "..." } ``` -------------------------------- ### Get Queue Details Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/endpoints.md Retrieves detailed information about a specific queue, including its current status and historical statistics for the past 10 days. ```APIDOC ## GET /api/queues/{qname} ### Description Get detailed information about a specific queue, including 10 days of historical statistics. ### Method GET ### Endpoint /api/queues/{qname} ### Parameters #### Path Parameters - **qname** (string) - Required - The name of the queue. #### Query Parameters None ### Request Example None ### Response #### Success Response (200) - **current** (object) - Current status of the queue. - **queue** (string) - The name of the queue. - **memory_usage_bytes** (int64) - Memory usage in bytes. - **size** (int) - Current number of tasks in the queue. - **groups** (int) - Number of task groups. - **latency_msec** (int64) - Current latency in milliseconds. - **display_latency** (string) - Formatted latency string. - **active** (int) - Number of active tasks. - **pending** (int) - Number of pending tasks. - **aggregating** (int) - Number of aggregating tasks. - **scheduled** (int) - Number of scheduled tasks. - **retry** (int) - Number of tasks in retry state. - **archived** (int) - Number of archived tasks. - **completed** (int) - Number of completed tasks. - **processed** (int) - Number of processed tasks. - **succeeded** (int) - Number of succeeded tasks. - **failed** (int) - Number of failed tasks. - **paused** (bool) - Indicates if the queue is paused. - **timestamp** (string) - RFC3339 time string of the last update. - **history** (array) - Historical statistics for the past 10 days. - **queue** (string) - The name of the queue. - **processed** (int) - Number of processed tasks for the day. - **succeeded** (int) - Number of succeeded tasks for the day. - **failed** (int) - Number of failed tasks for the day. - **date** (string) - Date in YYYY-MM-DD format. #### Response Example ```json { "current": { "queue": "default", "memory_usage_bytes": 1024, "size": 5, "groups": 0, "latency_msec": 100, "display_latency": "100ms", "active": 1, "pending": 4, "aggregating": 0, "scheduled": 0, "retry": 0, "archived": 0, "completed": 0, "processed": 0, "succeeded": 0, "failed": 0, "paused": false, "timestamp": "2023-10-27T10:00:00Z" }, "history": [ { "queue": "default", "processed": 100, "succeeded": 95, "failed": 5, "date": "2023-10-26" } ] } ``` #### Status Codes - `200 OK` - Success - `500 Internal Server Error` - Redis connection error ``` -------------------------------- ### Build Asynqmon Binary with Compiled UI Source: https://github.com/hibiken/asynqmon/blob/master/ui/README.md Compiles the Asynqmon binary, including a production build of the React app. This command should be run from the root of the repository. ```bash make build ``` -------------------------------- ### Get Prometheus Metrics Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Retrieve Prometheus-compatible metrics for Asynqmon. Ensure `PrometheusAddress` is configured. Specify a `duration_sec` to filter metrics by time range. ```bash # Requires PrometheusAddress to be configured curl "http://localhost:8080/api/metrics?duration_sec=3600" ``` -------------------------------- ### Run Asynqmon with Defaults Source: https://github.com/hibiken/asynqmon/blob/master/README.md Run the Asynqmon binary using default settings. Access the web UI at http://localhost:8080. Assumes Redis is running on 127.0.0.1:6379. ```bash # with a binary ./asynqmon # with a docker image docker run --rm \ --name asynqmon \ -p 8080:8080 \ hibiken/asynqmon ``` -------------------------------- ### Minimal Library Usage Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/00-START-HERE.md Integrate Asynqmon as an HTTP handler in your Go application. Ensure Redis is accessible at the specified address. ```go // Minimal library usage h := asynqmon.New(asynqmon.Options{ RedisConnOpt: asynq.RedisClientOpt{Addr: "localhost:6379"}, }) http.Handle("/", h) http.ListenAndServe(":8080", nil) ``` -------------------------------- ### Integrate Asynqmon with Gin Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/README.md Use Gin's Any method with WrapF to integrate the Asynqmon handler. ```go r := gin.Default() r.Any("/monitoring/*path", gin.WrapF(h.ServeHTTP)) ``` -------------------------------- ### View Redis Information Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Get detailed information about the Redis instance being used by Asynqmon. This includes memory usage, client connections, and other operational metrics. ```bash curl http://localhost:8080/api/redis_info ``` -------------------------------- ### Run Asynqmon with Docker Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/00-START-HERE.md Deploy Asynqmon using Docker, mapping the container port and setting the Redis address via environment variables. ```bash docker run -d --name asynqmon -p 8080:8080 \ -e REDIS_ADDR=redis:6379 \ hibiken/asynqmon ``` -------------------------------- ### Run Asynqmon Binary Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/INDEX.md Execute the Asynqmon binary from the command line. You can pass various flags to configure its behavior, such as the port it listens on. The default address is http://localhost:8080. ```bash ./asynqmon --flags ``` -------------------------------- ### Run Asynqmon with Prometheus Metrics Enabled Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Enable the Prometheus metrics exporter and specify the Prometheus server address. ```bash ./asynqmon --enable-metrics-exporter --prometheus-addr http://localhost:9090 ``` -------------------------------- ### Troubleshoot Web UI Loading Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Check if the Asynqmon web UI port is accessible and review logs for any errors. ```bash # Check port is accessible curl http://localhost:8080 ``` ```bash # Check logs for errors ./asynqmon 2>&1 | tail -20 ``` -------------------------------- ### Create Asynqmon HTTP Handler Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/INDEX.md Instantiate the Asynqmon HTTP handler with desired options. This handler serves as the main entry point for integrating Asynqmon's monitoring capabilities into your HTTP server. ```go asynqmon.New(options) ``` -------------------------------- ### Run Asynqmon with Docker (Redis on Host) Source: https://github.com/hibiken/asynqmon/blob/master/README.md Run Asynqmon using Docker, connecting to a Redis server running on the host machine. Ensure port 3000 is exposed. ```bash # with Docker (connect to a Redis server running on the host machine) docker run --rm \ --name asynqmon \ -p 3000:3000 \ hibiken/asynqmon --port=3000 --redis-addr=host.docker.internal:6379 ``` -------------------------------- ### Configure Redis with password and database Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/configuration.md Connect to a Redis instance that requires authentication and is not using the default database. ```bash ./asynqmon --redis-addr redis.example.com --redis-db 2 --redis-password mypassword ``` -------------------------------- ### Set configuration via environment variables Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/configuration.md Configure asynqmon by exporting environment variables for port, Redis connection details, Prometheus address, read-only mode, and payload display length. ```bash export PORT=3000 export REDIS_ADDR=redis.example.com export REDIS_DB=2 export REDIS_PASSWORD=mypassword export PROMETHEUS_ADDR=http://localhost:9090 export READ_ONLY=true export MAX_PAYLOAD_LENGTH=150 ./asynqmon ``` -------------------------------- ### Handle Read-Only Mode Errors Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md If you encounter '405 Method Not Allowed' errors, either remove the --read-only flag or ensure you are only using GET requests. ```bash # If you see "405 Method Not Allowed" # Either remove --read-only flag or use GET requests only ``` -------------------------------- ### Configure Asynqmon with Redis Sentinel Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/configuration.md Initialize Asynqmon using Redis Sentinel for high availability. Specify Sentinel addresses and the master name. ```go redisOpt := asynq.RedisFailoverClientOpt{ SentinelAddrs: []string{ "localhost:26379", "localhost:26380", "localhost:26381", }, MasterName: "mymaster", } h := asynqmon.New(asynqmon.Options{ RedisConnOpt: redisOpt, }) ``` -------------------------------- ### Get Task Details Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Retrieve comprehensive details for a specific task using its ID. This endpoint provides information about a single task's status and metadata. ```bash curl http://localhost:8080/api/queues/default/tasks/{task_id} ``` -------------------------------- ### Enable Read-Only Mode in Asynqmon Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/http-handler.md Configure Asynqmon to operate in read-only mode, allowing only GET requests. This is useful for restricting write operations on the monitoring interface. ```go h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"}, ReadOnly: true, // Only GET requests allowed }) deffer h.Close() http.Handle(h.RootPath()+"/", h) http.ListenAndServe(":8080", nil) ``` -------------------------------- ### Build Asynqmon Docker Image Locally Source: https://github.com/hibiken/asynqmon/blob/master/README.md Build the Asynqmon Docker image locally using the provided Makefile. This is useful for development or custom builds. ```bash make docker ``` -------------------------------- ### Asynqmon Binary Command-Line Flags Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/README.md Lists the available command-line flags for running the Asynqmon binary. These flags control aspects like port, Redis connection details, and UI display limits. ```bash ./asynqmon [flags] Flags: --port Port number (default: 8080) --redis-url Complete Redis URL --redis-addr Redis address (default: 127.0.0.1:6379) --redis-db Redis database (default: 0) --redis-password Redis password --redis-tls TLS server name for Redis --redis-insecure-tls Disable TLS verification (default: false) --redis-cluster-nodes Comma-separated cluster node addresses --max-payload-length Max payload chars in UI (default: 200) --max-result-length Max result chars in UI (default: 200) --enable-metrics-exporter Enable /metrics endpoint (default: false) --prometheus-addr Prometheus server address --read-only Read-only mode (default: false) ``` -------------------------------- ### Access Asynqmon UI via Library Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Integrate Asynqmon into your Go application to access its UI. Visit the specified local URL to view the monitoring interface. ```go http.Handle(h.RootPath()+"/", h) ``` -------------------------------- ### API Response Format - List Endpoints Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/quick-start.md Example JSON structure for API responses that return lists of resources like queues, tasks, servers, or scheduler entries. ```json // List endpoints { "queues": [...], "tasks": [...], "servers": [...], "entries": [...] } ``` -------------------------------- ### Integrate Asynqmon with net/http.ServeMux Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/http-handler.md Use this snippet to integrate Asynqmon with the standard Go net/http.ServeMux. Ensure a trailing slash is used for the path when registering the handler. ```go package main import ( "log" "net/http" "github.com/hibiken/asynq" "github.com/hibiken/asynqmon" ) func main() { h := asynqmon.New(asynqmon.Options{ RootPath: "/monitoring", RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"}, }) defer h.Close() // Note: Need trailing slash when using net/http.ServeMux http.Handle(h.RootPath()+"/", h) log.Fatal(http.ListenAndServe(":8080", nil)) // Visit http://localhost:8080/monitoring } ``` -------------------------------- ### Asynqmon Library Options Structure Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/README.md Defines the configurable options for integrating Asynqmon into your Go application. Key fields include RootPath, Redis connection options, and custom formatters. ```go type Options struct { RootPath string // Default: "/" RedisConnOpt asynq.RedisConnOpt // Required PayloadFormatter PayloadFormatter // Default: DefaultPayloadFormatter ResultFormatter ResultFormatter // Default: DefaultResultFormatter PrometheusAddress string // Default: "" ReadOnly bool // Default: false } ``` -------------------------------- ### Get Redis Info Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/endpoints.md Retrieves detailed information about the Redis server or cluster status, including connection details and configuration. Supports both single server and cluster configurations. ```APIDOC ## GET /api/redis_info ### Description Get information about the Redis server or cluster. ### Method GET ### Endpoint /api/redis_info ### Response #### Success Response (200) - **address** (string) - The network address of the Redis instance. - **info** (map[string]string) - A map containing key-value pairs of Redis server information. - **raw_info** (string) - The raw string output from the Redis INFO command. - **cluster** (boolean) - Indicates if the Redis instance is part of a cluster. - **raw_cluster_nodes** (string) - The raw string output from the Redis CLUSTER NODES command (only present in cluster mode). - **queue_locations** (array) - An array of objects detailing queue distribution across cluster nodes (only present in cluster mode). - **queue** (string) - The name of the queue. - **keyslot** (int64) - The keyslot associated with the queue. - **nodes** (array) - A list of node addresses where the queue is located. #### Response Example (Single Server) { "address": "localhost:6379", "info": { "redis_version": "6.2.6", "role": "master" }, "raw_info": "# Server\nredis_version:6.2.6\n...", "cluster": false } #### Response Example (Cluster) { "address": "localhost:7000", "info": { "redis_version": "6.2.6", "role": "master" }, "raw_info": "# Server\nredis_version:6.2.6\n...", "cluster": true, "raw_cluster_nodes": "...", "queue_locations": [ { "queue": "default", "keyslot": 1234, "nodes": ["localhost:7000", "localhost:7001"] } ] } ### Status Codes - `200 OK` - Success - `500 Internal Server Error` - Redis error ``` -------------------------------- ### Import Path for Asynqmon Source: https://github.com/hibiken/asynqmon/blob/master/_autodocs/overview.md This is the import path for the Asynqmon library in Go projects. ```go github.com/hibiken/asynqmon ```