### MQL Quick Start Examples Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Illustrates basic MQL syntax for deep field access, optional tables, filtering, duration comparisons, and native JSON array support. Useful for quickly understanding MQL's capabilities compared to KQL. ```mql // AQL supports deep nested field access with dots parent.child.grandchild == "value" ``` ```mql // Tables are optional (uses UI-selected default table) status_code >= 400 ``` ```mql // 'where' is optional for initial filters when using default table method == "GET" and duration > 100ms ``` ```mql // But required after other operations summarize count() by endpoint | where count_value > 100 ``` ```mql // Direct duration comparisons duration > 100ms // No need for special duration functions ``` ```mql // Native JSON array support errors[*].code == 500 // Any error has code 500 ``` ```mql tags[0] == "production" // First tag is "production" ``` -------------------------------- ### Minimal Development Setup Configuration Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/configuration.md An example .env file configuration for a minimal development environment, including database, basic authentication, and API key encryption. ```env DATABASE_URL=postgresql://postgres:postgres@localhost:5432/monoscope BASIC_AUTH_ENABLED=True BASIC_AUTH_USERNAME=admin BASIC_AUTH_PASSWORD=changeme API_KEY_ENCRYPTION_SECRET_KEY=monoscope123456monoscope1234567 ``` -------------------------------- ### Production Setup with Auth0 Configuration Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/configuration.md An example .env file configuration for a production environment using Auth0, including database connection, environment settings, and disabling basic authentication. ```env DATABASE_URL=postgresql://prod_user:secure_pass@db.example.com:5432/monoscope?sslmode=require ENVIRONMENT=PROD HOST_URL=https://monoscope.example.com # Disable basic auth BASIC_AUTH_ENABLED=False ``` -------------------------------- ### Install Haskell via GHCup Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Installs the Haskell toolchain using GHCup. This is the recommended method for managing Haskell installations. ```bash curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh ``` -------------------------------- ### Example PostgreSQL DATABASE_URL Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/configuration.md Provides an example of a PostgreSQL connection string format for the DATABASE_URL environment variable. ```sql postgresql://user:password@localhost:5432/monoscope?sslmode=disable ``` -------------------------------- ### Install LLVM on Linux (Ubuntu/Debian) Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Installs the LLVM compiler infrastructure on Ubuntu/Debian-based Linux systems using apt-get. ```bash # Install LLVM sudo apt-get install llvm ``` -------------------------------- ### Start Test Database Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DOCKER_COMPOSE_README.md Starts the TimescaleDB test database using the 'test' profile defined in docker-compose.yml. ```bash docker-compose --profile test up -d timescaledb-test ``` -------------------------------- ### Start Optional Services with Dev Profile Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DOCKER_COMPOSE_README.md Use this command to start optional services like pgAdmin with the development profile. Access the pgAdmin UI at http://localhost:5050. ```bash docker-compose --profile dev up -d ``` -------------------------------- ### String Operator Examples Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/kql-reference.md Provides examples of various string operators like 'has', 'contains', 'startswith', 'endswith', and regex matching. ```kusto message has "timeout" ``` ```kusto url contains "/api/v2" ``` ```kusto service_name startswith "payment-" ``` ```kusto request_body.msg =~ /^[A-Z]{3}-[0-9]+/ ``` -------------------------------- ### Initialize Monoscope Configuration Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Launches an interactive setup wizard to configure the Monoscope CLI. ```bash monoscope config init ``` -------------------------------- ### Example .env File for Test Credentials Source: https://github.com/monoscope-tech/monoscope/blob/master/test/integration/README.md This is an example of the .env file required when running tests with UPDATE_GOLDEN=true. It includes placeholders for various service credentials. ```env TWILIO_ACCOUNT_SID=AC... TWILIO_AUTH_TOKEN=... DISCORD_BOT_TOKEN=... DISCORD_PUBLIC_KEY=... SLACK_BOT_TOKEN=xoxb-... OPENAI_API_KEY=sk-... ``` -------------------------------- ### Install Monoscope CLI Source: https://github.com/monoscope-tech/monoscope/blob/master/README.md Installs the Monoscope CLI using a curl script and logs in the user. ```bash curl https://monoscope.tech/install.sh | sh monoscope auth login ``` -------------------------------- ### Start Optional Services with Test Profile Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DOCKER_COMPOSE_README.md Use this command to start optional services with the test profile, which includes a separate TimescaleDB instance for integration testing. ```bash docker-compose --profile test up -d ``` -------------------------------- ### Install libpq on Linux (Ubuntu/Debian) Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Installs the libpq-dev package on Ubuntu/Debian-based Linux systems, providing necessary libraries for PostgreSQL client connections. ```bash # Install libpq sudo apt-get install libpq-dev ``` -------------------------------- ### Start Monoscope with Docker Compose Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/getting-started.md Clone the Monoscope repository and start the services using Docker Compose. Verify that the services are running. ```bash git clone https://github.com/monoscope-tech/monoscope.git cd monoscope docker-compose up -d docker-compose ps ``` -------------------------------- ### List Available Tools Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/mcp.md This example demonstrates how to list all available tools exposed by the MCP server using a `curl` command. ```APIDOC ## List Tools ### Description Retrieves a list of all tools available on the Monoscope MCP server. ### Method POST ### Endpoint https://api.monoscope.tech/api/v1/mcp ### Request Body ```json { "jsonrpc": "2.0", "id": 1, "method": "tools/list" } ``` ### Request Example ```bash curl -s https://api.monoscope.tech/api/v1/mcp \ -H "Authorization: Bearer $MONOSCOPE_API_KEY" \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | jq '.result.tools[].name' ``` ### Response The response contains a list of tool names. The example command filters to show only the names. ``` -------------------------------- ### Install libpq on macOS Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Installs the libpq library on macOS using Homebrew. This library is necessary for PostgreSQL client connections. ```bash # Install libpq brew install libpq ``` -------------------------------- ### MQL vs Standard KQL Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Highlights key differences and provides examples of MQL syntax compared to standard KQL. ```APIDOC ## MQL vs Standard KQL ### Description This section illustrates the differences between Monoscope Query Language (MQL) and standard Kusto Query Language (KQL) with practical examples. ### Examples ```mql // Deep nested field access parent.child.grandchild == "value" // Optional 'where' clause for default table status_code >= 400 method == "GET" and duration > 100ms // 'where' required after other operations summarize count() by endpoint | where count_value > 100 // Direct duration comparisons duration > 100ms // Native JSON array support errors[*].code == 500 tags[0] == "production" ``` ``` -------------------------------- ### Install and Run ghcid for Automatic Recompilation Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Installs ghcid using Stack and demonstrates how to run it for automatic recompilation during development. It monitors file changes and reloads the Haskell environment. ```bash # Install ghcid stack install ghcid # Run with automatic recompilation make dev # Or ghcid --command="stack repl" --test=":main" ``` -------------------------------- ### Install Monoscope Claude Code Skills (Marketplace) Source: https://github.com/monoscope-tech/monoscope/blob/master/README.md Installs the Monoscope skills plugin for Claude Code from the marketplace. Requires restarting Claude Code after installation. ```bash # Claude Code claude plugin marketplace add monoscope-tech/skills claude plugin install monoscope-skills@monoscope-skills ``` -------------------------------- ### Array Access Syntax Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Examples of accessing specific or all elements in an array. ```mql errors[0] // First element tags[*] // All elements (wildcard) request_body.roles[1] // Nested array access events[*].name // Field in all array elements ``` -------------------------------- ### Install Monoscope CLI Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/getting-started.md Installs the Monoscope CLI using a curl command. This is the first step to managing your project from the terminal. ```bash curl https://monoscope.tech/install.sh | sh ``` -------------------------------- ### Install Specific Monoscope CLI Version Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Installs a specific version of the Monoscope CLI by passing the version tag to the install script. ```bash curl https://monoscope.tech/install.sh | sh -s v1.2.3 ``` -------------------------------- ### Syntax Error Examples Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Examples of common syntax errors and their suggested corrections. Ensure correct operators, quoted strings, and data types for comparisons. ```mql Query: status_code = 400 Error: Invalid operator '=' at line 1, column 12. Did you mean '=='? ``` ```mql Query: where method == GET Error: Unquoted string 'GET' at line 1, column 17. Strings must be quoted: "GET" ``` ```mql Query: duration > "100ms" Error: Cannot compare duration (number) with string "100ms". Did you mean: duration > 100ms ``` -------------------------------- ### Install Monoscope CLI to Custom Directory Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Installs the Monoscope CLI to a custom directory by setting the `MONOSCOPE_INSTALL_DIR` environment variable. ```bash MONOSCOPE_INSTALL_DIR=/usr/local/bin curl https://monoscope.tech/install.sh | sh ``` -------------------------------- ### Start Monoscope and TimescaleDB Services Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DOCKER_COMPOSE_README.md Starts TimescaleDB and Monoscope services using Docker Compose. This command pulls the latest Monoscope image and starts the services in detached mode. ```bash # Pull the latest Monoscope image from GitHub Packages (if needed) docker pull ghcr.io/monoscope-tech/monoscope:latest # Start services docker-compose up -d ``` -------------------------------- ### List Available MCP Tools Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/mcp.md Example using curl to list all available tools exposed by the Monoscope MCP server. Requires jq for pretty-printing the output. ```bash curl -s https://api.monoscope.tech/api/v1/mcp \ -H "Authorization: Bearer $MONOSCOPE_API_KEY" \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | jq '.result.tools[].name' ``` -------------------------------- ### Basic KQL Query Example Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/kql-reference.md Demonstrates a typical KQL query structure involving filtering, aggregation, sorting, and limiting results. ```kusto spans | where method == "GET" and status_code >= 400 | summarize count() by status_code | sort by status_code desc | take 10 ``` -------------------------------- ### Create .env File for Production Secrets Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/getting-started.md Copy the example .env file and edit it with your production-specific secrets and configurations. This is recommended for managing sensitive information in production environments. ```bash # Create .env file cp .env.example .env # Edit .env with your production values ``` -------------------------------- ### Clone Monoscope and Start Docker Compose Source: https://github.com/monoscope-tech/monoscope/blob/master/README.md Use these commands to clone the Monoscope repository and start the application using Docker Compose. Access the dashboard at http://localhost:8080. ```bash git clone https://github.com/monoscope-tech/monoscope.git cd monoscope docker-compose up ``` -------------------------------- ### Monoscope Query Syntax Examples Source: https://github.com/monoscope-tech/monoscope/blob/master/static/public/assets/js/monoscope/README.md A collection of valid query strings demonstrating filtering, source selection, aggregation, and summarization syntax. ```text request_body.v1.v2 = "abc" AND (request_body.v3.v4 = 123 OR request_body.v5[].v6=ANY[1,2,3] OR request_body[1].v7 OR NOT request_body[-1].v8 ) method=="GET" | traces // Source is set to traces. Can be requests, logs, traces, spans, metrics method == "GET" | stats count(*) method == "GET" | stats count(*) as total by field1 method == "GET" | stats count(*) as total by field1, field2 method == "GET" | summarize count(*) by bin_auto(timestamp) method == "GET" | summarize count(*) by bin(timestamp, 86400) method == "GET" | summarize count(*) by bin_auto(timestamp) method == "GET" | summarize count(*) by field1, field2, bin_auto(timestamp) method == "GET" | summarize avg(field1) by field1, field2, bin_auto(timestamp) ``` -------------------------------- ### Install Code Formatting and Linting Tools Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Installs code formatting (fourmolu) and linting (hlint) tools using Homebrew or Cabal. These tools help maintain code quality and consistency. ```bash # Code formatter brew install fourmolu # or: cabal install fourmolu # Linter brew install hlint ``` -------------------------------- ### Install Monoscope Claude Code Skills (npx) Source: https://github.com/monoscope-tech/monoscope/blob/master/README.md Installs the Monoscope skills plugin for Claude Code using npx, compatible with agents like Cursor, Cline, and Copilot. Requires restarting Claude Code after installation. ```bash # or via npx (Cursor, Cline, Copilot, and other agents) npx skills add monoscope-tech/skills ``` -------------------------------- ### Install PostgreSQL and TimescaleDB on macOS Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Installs PostgreSQL and the TimescaleDB extension on macOS using Homebrew. TimescaleDB is used for time-series data storage. ```bash # Install PostgreSQL with TimescaleDB brew install postgresql brew install timescaledb ``` -------------------------------- ### String Literals Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Examples of defining string values in MQL. ```mql "GET" // Simple string "user said \"hello\"" // Escaped quotes "/api/v1/users" // Path strings ``` -------------------------------- ### Call a Tool Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/mcp.md This example shows how to invoke a specific tool, such as `search_events`, with arguments using `curl`. ```APIDOC ## Call Tool ### Description Invokes a specified tool with the provided arguments. ### Method POST ### Endpoint https://api.monoscope.tech/api/v1/mcp ### Request Body ```json { "jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": { "name": "search_events", "arguments": { "body": { "query": "severity.text==\"error\"", "since": "1h" } } } } ``` ### Request Example ```bash curl -s https://api.monoscope.tech/api/v1/mcp \ -H "Authorization: Bearer $MONOSCOPE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": { "name": "search_events", "arguments": { "body": { "query": "severity.text==\"error\"", "since": "1h" } } } }' | jq ``` ### Response Tool execution results are returned. For REST-derived tools, `content` contains a truncated text view and `structuredContent` contains the full JSON. ``` -------------------------------- ### MQL Set Operation Example Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Demonstrates the use of the 'in' and '!in' set operators for checking membership within a list of values. ```mql method in ("GET", "POST") ``` ```mql status !in (200, 404) ``` -------------------------------- ### MQL Pattern Matching Example Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Shows how to use the 'matches regex' operator for pattern matching against string fields using regular expressions. ```mql email matches regex ".*@company\.com" ``` -------------------------------- ### Auto-instrument Node.js Application Source: https://github.com/monoscope-tech/monoscope/blob/master/README.md Installs the Node.js auto-instrumentation package and registers it for tracing. Set the service name and OTLP endpoint environment variables. ```bash npm install --save @opentelemetry/auto-instrumentations-node OTEL_SERVICE_NAME="my-app" \ OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317" \ node --require @opentelemetry/auto-instrumentations-node/register app.js ``` -------------------------------- ### Copy Override File for Local Development Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DOCKER_COMPOSE_README.md Copy the example override file to enable local development builds. Docker Compose will automatically use both the main and override files. ```bash # Copy the override example cp docker-compose.override.yml.example docker-compose.override.yml # Docker Compose will automatically use both files docker-compose up -d ``` -------------------------------- ### MQL Duration Literal Examples Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Provides examples of MQL duration literals, showcasing various units from nanoseconds to weeks. These are internally stored as nanosecond counts. ```mql 100ns, 250µs, 5ms, 30s, 10m, 2h, 1d, 1w ``` -------------------------------- ### Copy Environment File Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DOCKER_COMPOSE_README.md Copies the example environment file to a new file named .env. This is the first step in configuring Monoscope using environment variables. ```bash cp .env.example .env ``` -------------------------------- ### MQL Array Literal Examples Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Shows different ways to define array literals in MQL, including numeric, string, and tuple-like arrays. ```mql [1, 2, 3], ["a", "b"], ("GET", "POST") ``` -------------------------------- ### MQL String Literal Example Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Demonstrates how to define string literals in MQL, including handling escaped quotes within the string. ```mql "abc", "he said \"hi\"" ``` -------------------------------- ### CI/Automation Scripting with Monoscope CLI and jq Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Examples of using Monoscope CLI commands in a CI environment, leveraging JSON output and jq for scripting and assertions. ```bash # Error-rate gate in CI (count of error-level events in the last 30 min) monoscope metrics query 'summarize count() | where severity.text=="error"' --since 30m --assert '< 100' ``` ```bash # Get open issue count monoscope issues list --status open -o json | jq '.data | length' ``` ```bash # Apply all monitors from a directory (idempotent) monoscope monitors apply .monoscope/monitors/ ``` -------------------------------- ### Run Monoscope Server Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Starts the Monoscope server locally. Use 'stack run' for projects managed with Stack, or 'cabal run monoscope-server' for Cabal-managed projects. ```bash # Using Stack stack run # Or using Cabal cabal run monoscope-server ``` -------------------------------- ### Send Test Telemetry with Telemetrygen Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DOCKER_COMPOSE_README.md Sends 10 traces as test telemetry to verify the Monoscope setup. This command is used after the services have been started. ```bash monoscope telemetrygen --kind=trace --count=10 ``` -------------------------------- ### Manage Teams Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Commands for listing, getting, creating, updating, patching, and deleting teams. Note that the 'everyone' handle is reserved and cannot be modified. ```bash monoscope teams list ``` ```bash monoscope teams get ``` ```bash monoscope teams create team.yaml # { name, handle, description, notify_emails, slack_channels } ``` ```bash monoscope teams update team.yaml # full replace (PUT) ``` ```bash monoscope teams patch patch.yaml # partial update (PATCH) ``` ```bash monoscope teams delete ``` ```bash monoscope teams bulk delete --ids id1,id2 ``` -------------------------------- ### Auto-instrument Python Application Source: https://github.com/monoscope-tech/monoscope/blob/master/README.md Installs necessary OpenTelemetry packages and instruments a Python application for tracing. Ensure the service name and endpoint are correctly set. ```bash pip install opentelemetry-distro opentelemetry-exporter-otlp opentelemetry-bootstrap -a install OTEL_SERVICE_NAME="my-app" \ OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317" \ opentelemetry-instrument python myapp.py ``` -------------------------------- ### Manage Monoscope API Keys Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Commands for listing, getting, creating, activating, deactivating, and deleting API keys. Note that the plaintext key is printed only once upon creation. ```bash monoscope api-keys list monoscope api-keys get monoscope api-keys create "my-key-name" # prints plaintext key once monoscope api-keys activate monoscope api-keys deactivate # soft disable monoscope api-keys delete # permanent removal ``` -------------------------------- ### Run Monoscope Locally with Docker Compose Source: https://github.com/monoscope-tech/monoscope/blob/master/CONTRIBUTING.md Start a local instance of Monoscope using Docker Compose. The default credentials are admin/changeme. Visit http://localhost:8080. ```bash docker-compose up ``` -------------------------------- ### Clone Monoscope Repository and Install Dependencies Source: https://github.com/monoscope-tech/monoscope/blob/master/CONTRIBUTING.md Clone the Monoscope repository and install Haskell dependencies using Cabal. Ensure you have GHCup, Docker, Node.js, LLVM, and libpq installed. ```bash git clone https://github.com/monoscope-tech/monoscope.git cd monoscope cabal update git config core.hooksPath .githooks ``` -------------------------------- ### Run Monoscope with Docker Compose Profiles Source: https://github.com/monoscope-tech/monoscope/blob/master/CONTRIBUTING.md Start additional services for Monoscope development using Docker Compose profiles. Use the 'dev' profile for pgAdmin or the 'test' profile for an ephemeral test database. ```bash # pgAdmin for database management (http://localhost:5050) docker-compose --profile dev up # Ephemeral test database (port 5433) docker-compose --profile test up ``` -------------------------------- ### Manage Members Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Commands for listing, getting, adding, updating, and removing members. Members can be added by email or user ID, with specified permissions. ```bash monoscope members list ``` ```bash monoscope members get ``` ```bash monoscope members add --email teammate@example.com --permission view ``` ```bash monoscope members add --user-id --permission edit ``` ```bash monoscope members patch admin ``` ```bash monoscope members remove ``` -------------------------------- ### Run TimescaleDB Docker Container Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Starts a Docker container for TimescaleDB using a Makefile target. This command assumes the Makefile is present in the project root. ```bash make timescaledb-docker ``` -------------------------------- ### MQL Text Search Operation Examples Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Illustrates MQL text search operators like 'has_any' and 'has_all' for searching within string fields using lists of words. ```mql tags has_any ["urgent", "critical"] ``` ```mql message has_all ["user", "login"] ``` -------------------------------- ### Manage Monoscope Dashboards Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Commands for listing, getting, creating, updating, patching, deleting, starring, unstarring, and duplicating dashboards. Also includes dumping dashboard configurations to YAML and applying configurations from files or directories. ```bash monoscope dashboards list monoscope dashboards get monoscope dashboards create dashboard.yaml monoscope dashboards update dashboard.yaml monoscope dashboards patch patch.yaml monoscope dashboards delete monoscope dashboards star monoscope dashboards unstar monoscope dashboards duplicate # Dump as YAML (for editing and re-applying) monoscope dashboards yaml > dashboard.yaml # Idempotent upsert from file or directory monoscope dashboards apply dashboards/ # Bulk: delete monoscope dashboards bulk delete --ids id1,id2 # Widget operations monoscope dashboards widget upsert widget.yaml monoscope dashboards widget delete monoscope dashboards widget reorder --tab overview positions.json ``` -------------------------------- ### Create or Update Monitor from File Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Create a new monitor or update an existing one using a YAML or JSON configuration file. Use 'update' for a full replacement (PUT) or 'patch' for partial updates (PATCH). ```bash monoscope monitors create monitor.yaml ``` ```bash monoscope monitors update monitor.yaml ``` ```bash monoscope monitors patch patch.yaml ``` -------------------------------- ### Install LLVM on macOS Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Installs the LLVM compiler infrastructure on macOS using Homebrew. LLVM is a required dependency for building Monoscope. ```bash # Install LLVM brew install llvm ``` -------------------------------- ### Configure Shell Completions Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Set up shell completions for bash, zsh, and fish to improve CLI usability. Output is redirected to the appropriate configuration file for each shell. ```bash monoscope completion bash >> ~/.bashrc monoscope completion zsh >> ~/.zshrc monoscope completion fish >> ~/.config/fish/completions/monoscope.fish ``` -------------------------------- ### Check Build Log Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Provides commands to view the build log file ('build.log'). 'tail -50 build.log' shows the last 50 lines, while 'tail -f build.log' streams the log in real-time. ```bash # Check last 50 lines of build log tail -50 build.log # Watch build log in real-time tail -f build.log ``` -------------------------------- ### KQL Quick Reference Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/kql-reference.md Syntax reference for filtering, pipe operations, time functions, aggregations, and scalar functions. ```kusto ==, !=, >, <, >=, <= has, !has, contains, !contains startswith, !startswith, endswith, !endswith matches, =~ in, !in, has_any, has_all and, or, () ``` ```kusto | where | summarize [by ] | sort by [asc|desc] | take ``` ```kusto now(), ago(1h), ago(7d) bin(timestamp, 1h), bin_auto(timestamp) ``` ```kusto count(), sum(), avg(), min(), max() median(), stdev(), range() p50(), p75(), p90(), p95(), p99() percentile(field, N), percentiles(field, N1, N2, ...) countif(condition), dcount(field) ``` ```kusto strcat(s1, s2, ...), coalesce(v1, v2, ...) iff(cond, then, else), case(p1, v1, ..., else) ``` -------------------------------- ### Start Only TimescaleDB Service Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DOCKER_COMPOSE_README.md Starts only the TimescaleDB service using Docker Compose in detached mode. This is useful when running Monoscope locally but using the Dockerized TimescaleDB. ```bash # Start only TimescaleDB docker-compose up -d timescaledb ``` -------------------------------- ### Aggregation Error Examples Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Examples of common aggregation errors, such as missing grouping fields or referencing non-existent fields. Ensure correct syntax and schema awareness. ```mql Query: summarize count(*) by Error: Missing grouping field after 'by' keyword ``` ```mql Query: summarize avg(non_existent_field) Error: Field 'non_existent_field' not found in schema ``` -------------------------------- ### Access Read-Only Database in Development Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md This snippet shows how to source a .env file to load the DATABASE_URL and then connect to the database using psql. This is strictly for read-only access during development. ```bash # Read DATABASE_URL from .env file source .env psql $DATABASE_URL ``` -------------------------------- ### List All Monitors Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Retrieve a list of all configured monitors. ```bash monoscope monitors list ``` -------------------------------- ### Type Error Examples Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Examples of common type errors in queries. Ensure correct data types are used for comparisons and function arguments, especially for dates and numbers. ```mql Query: timestamp > "yesterday" Error: Invalid datetime value "yesterday". Use ago() function: timestamp > ago(1d) ``` ```mql Query: count > "many" Error: Cannot compare numeric field 'count' with string "many" ``` -------------------------------- ### Run All Tests Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Execute all tests in the project. Use `make test` for a standard run or `stack test --ghc-options=-w` for Stack-based projects. ```bash make test ``` ```bash stack test --ghc-options=-w ``` -------------------------------- ### Run Live Tests with Makefile Source: https://github.com/monoscope-tech/monoscope/blob/master/CONTRIBUTING.md Continuously run unit tests with live file-watching enabled. The tests will reload automatically upon file changes. ```bash make live-test-reload-unit ``` -------------------------------- ### Run Unit Tests with Makefile Source: https://github.com/monoscope-tech/monoscope/blob/master/CONTRIBUTING.md Conveniently run unit tests using the provided Makefile target. ```bash make test-unit ``` -------------------------------- ### Field Access Error Examples Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Examples of common field access errors, including typos and incorrect array syntax. Use dot notation for nested fields and correct field names. ```mql Query: request.boddy.message == "error" Error: Field 'boddy' not found in 'request'. Did you mean 'body'? ``` ```mql Query: attributes[user][id] == 123 Error: Invalid array syntax. Use dot notation: attributes.user.id ``` -------------------------------- ### Build and Run Monoscope from Source Source: https://github.com/monoscope-tech/monoscope/blob/master/CONTRIBUTING.md Build all targets of the Monoscope project using Cabal and run the application. For live-reloading during development, use the 'make live-reload' command. ```bash # Build all targets cabal build all -j # Run the application cabal run # Or with live-reload using ghcid make live-reload ``` -------------------------------- ### Simple Field Access Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Examples of accessing top-level fields in MQL. ```mql method // Simple field access status_code // Underscore-separated field names level // Severity level field ``` -------------------------------- ### Get Specific Monitor Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Retrieve details for a specific monitor using its ID. ```bash monoscope monitors get ``` -------------------------------- ### Complex Field Paths Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Examples of combining nested field access with array indexing. ```mql request_body.tags[*].name // Field in all array elements errors[0].message // Field in specific array element attributes.db.query.text // Deep nested field ``` -------------------------------- ### Nested JSON Field Access Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Examples of accessing nested fields within JSON objects. ```mql request_body.message // Nested field access attributes.http.method // Deep nesting resource.service.name // OpenTelemetry resource fields ``` -------------------------------- ### Run Integration Tests with Makefile Source: https://github.com/monoscope-tech/monoscope/blob/master/CONTRIBUTING.md Run integration tests using the Makefile target. Assumes an external PostgreSQL database is available. ```bash make test-integration ``` -------------------------------- ### Get Event Message Text Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md A shorthand to display only the message text (body and summary) of an event by its ID. ```bash # Common case: just the message text monoscope events get --show-body ``` -------------------------------- ### Get Current Timestamp Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/kql-reference.md The `now()` function returns the current timestamp, useful for filtering data up to the present moment. ```kusto timestamp <= now() ``` -------------------------------- ### Auto-instrument Kubernetes Application Source: https://github.com/monoscope-tech/monoscope/blob/master/README.md Installs the OpenTelemetry Operator and configures instrumentation for Kubernetes deployments. Annotate deployments to enable auto-instrumentation. ```bash # Install OpenTelemetry Operator kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/latest/download/opentelemetry-operator.yaml # Configure auto-instrumentation kubectl apply -f - < --tree ``` -------------------------------- ### Run Doctests with Makefile Source: https://github.com/monoscope-tech/monoscope/blob/master/CONTRIBUTING.md Run doctests using the Makefile target. ```bash make test-doctests ``` -------------------------------- ### List Migration Files Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DOCKER_COMPOSE_README.md Lists the migration files present in the static migrations directory. ```bash ls ./static/migrations/ ``` -------------------------------- ### Get Monoscope Configuration Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Retrieves Monoscope CLI configuration values. Shows all values by default or a specific value when a key is provided. ```bash monoscope config get ``` ```bash monoscope config get project ``` -------------------------------- ### Run Unit and Doctests Source: https://github.com/monoscope-tech/monoscope/blob/master/CONTRIBUTING.md Execute unit tests and doctests to ensure code correctness. Use '-O0' to disable optimizations for debugging. ```bash cabal test unit-tests --ghc-options="-O0" cabal test doctests --ghc-options="-O0" ``` -------------------------------- ### Apply Monitors from Directory Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Idempotently apply monitors defined in a file or directory, keyed by name. This command ensures the desired state of monitors. ```bash monoscope monitors apply monitors/ ``` -------------------------------- ### Generate Service Worker with Workbox Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Use this command to generate the service worker for the project. Ensure you have Workbox installed and a configuration file at config/workbox-config.js. ```bash workbox generateSW config/workbox-config.js ``` -------------------------------- ### Run Monoscope Test Suites Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/anomaly-detection-testing-guide.md Commands to execute unit, integration, or the full suite of tests using the project's makefile. ```bash # Run unit tests make test-unit # Run integration tests make test-integration # Run all tests make test ``` -------------------------------- ### Run Code Formatting and Linting Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Executes code formatting using 'make fmt' and runs the linter with 'make lint'. These commands are typically defined in the project's Makefile. ```bash # Format code make fmt # Run linter make lint ``` -------------------------------- ### Force Local Build with Docker Compose Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DOCKER_COMPOSE_README.md Use this command to force Docker Compose to build the Monoscope image locally before starting the services. ```bash # Force local build docker-compose build monoscope # Or build and run docker-compose up -d --build monoscope ``` -------------------------------- ### Check Monoscope Logs Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/getting-started.md Follow Monoscope logs in real-time to identify any issues during startup or operation. ```bash docker-compose logs -f monoscope ``` -------------------------------- ### Configure Port Mapping for PostgreSQL Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DOCKER_COMPOSE_README.md Example of how to change the host port mapping in docker-compose.yml to avoid conflicts with a locally running PostgreSQL instance. ```yaml ports: - '5433:5432' # Change host port to 5433 ``` -------------------------------- ### Run All Tests with Makefile Source: https://github.com/monoscope-tech/monoscope/blob/master/CONTRIBUTING.md Execute all defined tests in the project using the 'test' target in the Makefile. ```bash make test ``` -------------------------------- ### Run Unit Tests with File Watching Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Execute unit tests with file watching enabled for continuous testing during development. Use `make live-test-unit` or `stack test monoscope-server:unit-tests --ghc-options=-w --file-watch`. ```bash make live-test-unit ``` ```bash stack test monoscope-server:unit-tests --ghc-options=-w --file-watch ``` -------------------------------- ### Force Reinstall Monoscope CLI Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Forces a reinstallation of the Monoscope CLI, even if the installed version is already current. Use `--force` flag. ```bash curl https://monoscope.tech/install.sh | sh -s -- --force ``` -------------------------------- ### Querying Specific Data Sources Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/kql-reference.md Shows how to query different data sources like 'spans' (logs/spans) or 'metrics'. If no source is specified, the query defaults to the current context. ```kusto spans | where method == "POST" ``` ```kusto metrics | where metric_name == "http_requests_total" ``` -------------------------------- ### Send Telemetry with Python Script Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/getting-started.md A Python script using OpenTelemetry to send a test span with attributes. Ensure you have the necessary OpenTelemetry packages installed. ```python # save as send_telemetry.py from opentelemetry import trace from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor import time # Configure OpenTelemetry trace.set_tracer_provider(TracerProvider()) tracer = trace.get_tracer(__name__) # Set up OTLP exporter otlp_exporter = OTLPSpanExporter( endpoint="localhost:4317", insecure=True, headers=("x-api-key", "YOUR_API_KEY"), ) # Add exporter to tracer trace.get_tracer_provider().add_span_processor( BatchSpanProcessor(otlp_exporter) ) # Send a test span with tracer.start_as_current_span("test-operation") as span: span.set_attribute("user.id", "123") span.set_attribute("operation.type", "test") time.sleep(0.1) print("Telemetry sent!") ``` ```bash pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp python send_telemetry.py ``` -------------------------------- ### Authenticate Google Cloud Application Default Credentials Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/DEVELOPMENT.md Run this command to log in and set up application default credentials for Google Cloud integration. This is required if your project utilizes Google Cloud services. ```bash gcloud auth application-default login ``` -------------------------------- ### Using the 'where' Keyword Source: https://github.com/monoscope-tech/monoscope/blob/master/web-components/README.md Understand the requirements for the 'where' keyword based on whether a table is specified or if it follows an aggregation. ```mql spans | where status_code >= 400 metrics | where cpu_usage > 80 ``` ```mql // These are equivalent when using the default table: status_code >= 400 where status_code >= 400 ``` ```mql // Filter after summarize requires 'where' status_code >= 400 | summarize count() by endpoint | where count_value > 100 spans | where method == "POST" | summarize count() | where count_value > 10 ``` -------------------------------- ### Arithmetic in Percentiles Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/kql-reference.md Perform unit conversions and scaling directly within percentile functions. For example, convert nanoseconds to milliseconds or scale response times. ```kusto // Convert nanoseconds to milliseconds | summarize percentiles(duration / 1e6, 50, 75, 90, 95, 99) by bin(timestamp, 1h) ``` ```kusto // Scale values | summarize p95(response_time * 1000) ``` -------------------------------- ### Run Monoscope CLI E2E Tests Against Prod Demo Project Source: https://github.com/monoscope-tech/monoscope/blob/master/docs/cli.md Execute the end-to-end integration tests against the public demo project on production. Requires a read-only API key for the demo project. ```bash MONOSCOPE_API_KEY= \ USE_EXTERNAL_DB=true cabal test integration-tests \ --test-options='--match "CLI binary E2E"' ```