### Installation of mdtool Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/gitlab.com/golang-commonmark/markdown/README.md Installs the mdtool, an example command-line tool. ```go go get -u gitlab.com/golang-commonmark/mdtool ``` -------------------------------- ### Docker Compose Configuration Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/anomaly-detection/QuickStart.md Example docker-compose.yml configuration for running vmanomaly, including volume and environment variable setup for stateful/on-disk modes. ```yaml # docker-compose.yml file services: # ... vmanomaly: container_name: vmanomaly image: victoriametrics/vmanomaly:v1.29.4 # ... restart: always volumes: - ./config.yaml:/config.yaml - ./license:/license # Enable if settings.restore_state is True # - vmanomaly_data:/tmp/vmanomaly environment: # Enable if on-disk mode over in-memory is preferred # Required, if settings.restore_state is True - VMANOMALY_MODEL_DUMPS_DIR=/tmp/vmanomaly/models - VMANOMALY_DATA_DUMPS_DIR=/tmp/vmanomaly/data ports: - "8490:8490" command: - "/config.yaml" - "--licenseFile=/license" - "--loggerLevel=INFO" - "--watch" volumes: # ... # Enable if on-disk mode over in-memory is preferred # Required, if settings.restore_state is True vmanomaly_data: {} ``` -------------------------------- ### Install Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/pkoukk/tiktoken-go/README.md Install the tiktoken-go library using go get. ```bash go get github.com/pkoukk/tiktoken-go ``` -------------------------------- ### Install Package Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/gitlab.com/golang-commonmark/html/README.md Instructions on how to install the html package using go get. ```go go get -u gitlab.com/golang-commonmark/html ``` -------------------------------- ### Install bbolt Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/go.etcd.io/bbolt/README.md Instructions for installing the bbolt library using go get. ```sh $ go get go.etcd.io/bbolt@latest ``` -------------------------------- ### Install Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/gitlab.com/golang-commonmark/linkify/README.md Install the linkify package using go get. ```go go get -u gitlab.com/golang-commonmark/linkify ``` -------------------------------- ### Install Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/gitlab.com/golang-commonmark/puny/README.md Install the puny package using go get. ```go go get -u gitlab.com/golang-commonmark/puny ``` -------------------------------- ### vmanomaly Configuration Example Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/anomaly-detection/guides/guide-vmanomaly-vmalert/README.md An illustrative example of a vmanomaly_config.yml configuration file, demonstrating the structure and parameters for scheduler, models, reader, writer, and monitoring. ```yaml schedulers: periodic: infer_every: "1m" fit_every: "1h" fit_window: "2d" # 2d-14d based on the presence of weekly seasonality in your data models: prophet: class: "prophet" args: interval_width: 0.98 weekly_seasonality: False # comment it if your data has weekly seasonality yearly_seasonality: False reader: datasource_url: "http://victoriametrics:8428/" sampling_period: "60s" queries: node_cpu_rate: expr: "sum(rate(node_cpu_seconds_total[5m])) by (mode, instance, job)" writer: datasource_url: "http://victoriametrics:8428/" monitoring: pull: # Enable /metrics endpoint. addr: "0.0.0.0" port: 8490 ``` -------------------------------- ### Example Configuration File Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/anomaly-detection/QuickStart.md A sample configuration file demonstrating how to set up the Prophet model for anomaly detection, including scheduler, model, reader, and writer configurations. ```yaml settings: # https://docs.victoriametrics.com/anomaly-detection/components/settings/ n_workers: 2 # number of workers to run workload in parallel, set to 0 or negative number to use all available CPU cores anomaly_score_outside_data_range: 5.0 # default anomaly score for anomalies outside expected data range restore_state: true # restore state from previous run, available since v1.24.0 # https://docs.victoriametrics.com/anomaly-detection/components/settings/#logger-levels # to override service-global logger levels, use the `logger_levels` section logger_levels: # vmanomaly: INFO # scheduler: INFO # reader: INFO # writer: INFO model.prophet: WARNING schedulers: 1d_5m: # https://docs.victoriametrics.com/anomaly-detection/components/scheduler/#periodic-scheduler class: 'periodic' infer_every: '5m' fit_every: '1d' fit_window: '4w' models: # https://docs.victoriametrics.com/anomaly-detection/components/models/#prophet prophet_model: class: 'prophet' provide_series: ['anomaly_score', 'yhat', 'yhat_lower', 'yhat_upper'] # for debugging tz_aware: True # set to True if your data is timezone-aware, to deal with DST changes correctly tz_use_cyclical_encoding: True tz_seasonalities: # intra-day + intra-week seasonality - name: 'hod' # intra-day seasonality, hour of the day fourier_order: 4 # keep it 3-8 based on intraday pattern complexity prior_scale: 10 - name: 'dow' # intra-week seasonality, time of the week fourier_order: 2 # keep it 2-4, as dependencies are learned separately for each weekday compression: # available since v1.28.1 window: "30m" # downsample 5m data into 30m intervals before fitting agg_method: "mean" # use mean aggregation within each window adjust_boundaries: true # adjust confidence intervals after downsampling # inner model args (key-value pairs) accepted by # https://facebook.github.io/prophet/docs/quick_start#python-api args: interval_width: 0.98 # see https://facebook.github.io/prophet/docs/uncertainty_intervals reader: class: 'vm' # use VictoriaMetrics as a data source # https://docs.victoriametrics.com/anomaly-detection/components/reader/#vm-reader datasource_url: "https://play.victoriametrics.com/" # [YOUR_DATASOURCE_URL] tenant_id: '0:0' sampling_period: "5m" queries: # define your queries with MetricsQL - https://docs.victoriametrics.com/victoriametrics/metricsql/ cpu_user: expr: 'sum(rate(node_cpu_seconds_total{mode=~"user"}[10m])) by (container)' max_datapoints_per_query: 15000 # to deal with longer queries hitting search.MaxPointsPerTimeseries # other queries ... writer: class: 'vm' # use VictoriaMetrics as a data destination # https://docs.victoriametrics.com/anomaly-detection/components/writer/#vm-writer datasource_url: "http://victoriametrics:8428/" # [YOUR_DATASOURCE_URL] # optional tenant ID # tenant_id: "0:0" ``` -------------------------------- ### Installation Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/yosida95/uritemplate/v3/README.rst Install the uritemplate package using go get. ```sh $ go get -u github.com/yosida95/uritemplate/v3 ``` -------------------------------- ### Install Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/google/uuid/README.md Install the uuid package using go get. ```sh go get github.com/google/uuid ``` -------------------------------- ### Example of merging multiple YAML configuration files Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/anomaly-detection/QuickStart.md Demonstrates how to specify multiple YAML files or a directory for vmanomaly configuration, which will be shallow merged. ```shell vmanomaly config1.yaml config2.yaml ./config_dir/ ``` -------------------------------- ### Example Usage Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/blevesearch/gtreap/README.md Demonstrates basic operations like creating a treap, upserting, getting, and deleting items. ```Go import ( "math/rand" "github.com/steveyen/gtreap" ) func stringCompare(a, b interface{}) int { return bytes.Compare([]byte(a.(string)), []byte(b.(string))) } t := gtreap.NewTreap(stringCompare) t = t.Upsert("hi", rand.Int()) t = t.Upsert("hola", rand.Int()) t = t.Upsert("bye", rand.Int()) t = t.Upsert("adios", rand.Int()) hi = t.Get("hi") bye = t.Get("bye") // Some example Delete()'s... t = t.Delete("bye") nilValueHere = t.Get("bye") t2 = t.Delete("hi") nilValueHere2 = t2.Get("hi") // Since we still hold onto treap t, we can still access "hi". hiStillExistsInTreapT = t.Get("hi") t.VisitAscend("cya", func(i Item) bool { // This visitor callback will be invoked with every item // from "cya" onwards. So: "hi", "hola". // If we want to stop visiting, return false; // otherwise a true return result means keep visiting items. return true }) ``` -------------------------------- ### Example Configuration with Specific Models, Queries, and Schedulers Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/anomaly-detection/components/settings.md This example shows a configuration with state restoration enabled, defining specific models (zscore_online, prophet), queries (q1, q2), and a periodic scheduler. ```yaml settings: n_workers: 4 restore_state: True # enables state restoration schedulers: periodic_1d: class: periodic fit_every: 1h infer_every: 30s fit_window: 24h models: zscore_online: class: zscore_online z_threshold: 3.5 schedulers: ['periodic_1d'] prophet: class: prophet schedulers: ['periodic_1d'] queries: ['q1', 'q2'] args: interval_width: 0.98 reader: class: vm datasource_url: 'https://play.victoriametrics.com' tenant_id: "0" queries: q1: expr: 'some_metricsql_query_1' q2: expr: 'some_metricsql_query_2' sampling_period: 30s ``` -------------------------------- ### Example Use Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/bits-and-blooms/bitset/README.md Demonstrates basic usage of the bitset library, including setting, testing, clearing bits, chaining operations, and iterating over set bits. It also shows an intersection example. ```go package main import ( "fmt" "math/rand" "github.com/bits-and-blooms/bitset" ) func main() { fmt.Printf("Hello from BitSet!\n") var b bitset.BitSet // play some Go Fish for i := 0; i < 100; i++ { card1 := uint(rand.Intn(52)) card2 := uint(rand.Intn(52)) b.Set(card1) if b.Test(card2) { fmt.Println("Go Fish!") } b.Clear(card1) } // Chaining b.Set(10).Set(11) for i, e := b.NextSet(0); e; i, e = b.NextSet(i + 1) { fmt.Println("The following bit is set:", i) } if b.Intersection(bitset.New(100).Set(10)).Count() == 1 { fmt.Println("Intersection works.") } else { fmt.Println("Intersection doesn't work???") } } ``` -------------------------------- ### Querying Example Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/blevesearch/bleve/v2/README.md Shows how to open an existing Bleve index and perform a search. ```go index, _ := bleve.Open("example.bleve") query := bleve.NewQueryStringQuery("bleve") searchRequest := bleve.NewSearchRequest(query) searchResult, _ := index.Search(searchRequest) ``` -------------------------------- ### Installation Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/wk8/go-ordered-map/v2/README.md Command to install the go-ordered-map library using go get. ```bash go get -u github.com/wk8/go-ordered-map/v2 ``` -------------------------------- ### vmalert configuration example Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/anomaly-detection/guides/guide-vmanomaly-vmalert/README.md Example configuration for vmalert to alert on high anomaly scores. ```yaml groups: - name: AnomalyExample rules: - alert: HighAnomalyScore expr: 'anomaly_score > 1.0' labels: severity: warning annotations: summary: Anomaly Score exceeded 1.0. `sum(rate(node_cpu_seconds_total))` is showing abnormal behavior. ``` -------------------------------- ### Create User Example Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/go.etcd.io/bbolt/README.md Example function to create a new user within a specific account's 'USERS' bucket. ```go //createUser creates a new user in the given account. func createUser(accountID int, u *User) error { // Start the transaction. tx, err := db.Begin(true) if err != nil { return err } defer tx.Rollback() // Retrieve the root bucket for the account. // Assume this has already been created when the account was set up. root := tx.Bucket([]byte(strconv.FormatUint(accountID, 10))) // Setup the users bucket. bkt, err := root.CreateBucketIfNotExists([]byte("USERS")) if err != nil { return err } // Generate an ID for the new user. userID, err := bkt.NextSequence() if err != nil { return err } u.ID = userID // Marshal and save the encoded user. if buf, err := json.Marshal(u); err != nil { return err } else if err := bkt.Put([]byte(strconv.FormatUint(u.ID, 10)), buf); err != nil { return err } // Commit the transaction. if err := tx.Commit(); err != nil { return err } return nil } ``` -------------------------------- ### Rename pipe example 3 Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/logsql.md Renames all fields starting with 'foo' prefix to fields starting with 'bar' prefix. ```logsql _time:5m | rename foo* as bar* ``` -------------------------------- ### values example Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/logsql.md Example query to get all values (including empty) for the 'ip' field over the last 5 minutes. ```logsql _time:5m | stats values(ip) ips ``` -------------------------------- ### Installation Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/gitlab.com/golang-commonmark/markdown/README.md Installs the golang-commonmark/markdown parser. ```go go get -u gitlab.com/golang-commonmark/markdown ``` -------------------------------- ### uniq_values example Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/logsql.md Example query to get unique non-empty values for the 'ip' field over the last 5 minutes. ```logsql _time:5m | stats uniq_values(ip) unique_ips ``` -------------------------------- ### Start Docker Compose Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/anomaly-detection/guides/guide-vmanomaly-vmalert/README.md Command to start all services defined in the docker-compose.yml file in detached mode. ```sh docker-compose up -d ``` -------------------------------- ### Configuration examples Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/README.md Examples of how to configure the MCP Server for vmanomaly using environment variables for different scenarios. ```bash # Basic configuration export VMANOMALY_ENDPOINT="http://localhost:8490" ``` ```bash # With authentication export VMANOMALY_ENDPOINT="http://localhost:8490" export VMANOMALY_BEARER_TOKEN="your-token" ``` ```bash # With custom headers (e.g., behind a reverse proxy) export VMANOMALY_HEADERS="X-Custom-Header=value1,X-Another=value2" ``` ```bash # Server mode export MCP_SERVER_MODE="http" export MCP_LISTEN_ADDR="0.0.0.0:8080" ``` ```bash # Logging export MCP_LOG_LEVEL="debug" export MCP_LOG_FILE="/tmp/mcp-vmanomaly.log" ``` -------------------------------- ### vmalert Example Alerts Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/anomaly-detection/QuickStart.md Example Prometheus alerting rules for vmalert to monitor VictoriaMetrics license expiration. ```yaml groups: - name: vm-license # note the `job` label and update accordingly to your setup rules: - alert: LicenseExpiresInLessThan30Days expr: vm_license_expires_in_seconds < 30 * 24 * 3600 labels: severity: warning annotations: summary: "{{ $labels.job }} instance {{ $labels.instance }} license expires in less than 30 days" description: "{{ $labels.instance }} of job {{ $labels.job }} license expires in {{ $value | humanizeDuration }}. Please make sure to update the license before it expires." - alert: LicenseExpiresInLessThan7Days expr: vm_license_expires_in_seconds < 7 * 24 * 3600 labels: severity: critical annotations: summary: "{{ $labels.job }} instance {{ $labels.instance }} license expires in less than 7 days" description: "{{ $labels.instance }} of job {{ $labels.job }} license expires in {{ $value | humanizeDuration }}. Please make sure to update the license before it expires." ``` -------------------------------- ### Install Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/gitlab.com/golang-commonmark/mdurl/README.md Install the mdurl package. ```go go get -u gitlab.com/golang-commonmark/mdurl ``` -------------------------------- ### Exact Prefix Filter Example Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/logsql.md Example of using the exact prefix filter to match log messages starting with a specific prefix. ```logsql ="Processing request"* ``` -------------------------------- ### CLI Installation Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/blevesearch/bleve/v2/README.md Command to install the Bleve command-line interface. ```bash go install github.com/blevesearch/bleve/v2/cmd/bleve@latest ``` -------------------------------- ### rate() function example Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/logsql.md Example query to get the average per-second rate of logs containing the word 'error' over the last 5 minutes. ```logsql _time:5m error | stats rate() ``` -------------------------------- ### CLI Help Output Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/blevesearch/bleve/v2/README.md Help information for the Bleve command-line tool. ```text Bleve is a command-line tool to interact with a bleve index. Usage: bleve [command] Available Commands: bulk bulk loads from newline delimited JSON files check checks the contents of the index count counts the number documents in the index create creates a new index dictionary prints the term dictionary for the specified field in the index dump dumps the contents of the index fields lists the fields in this index help Help about any command index adds the files to the index mapping prints the mapping used for this index query queries the index registry registry lists the bleve components compiled into this executable scorch command-line tool to interact with a scorch index Flags: -h, --help help for bleve Use "bleve [command] --help" for more information about a command. ``` -------------------------------- ### uniq_values with limit example Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/logsql.md Example query to get up to 100 unique values for the 'ip' field over the last 5 minutes, limiting memory usage. ```logsql _time:5m | stats uniq_values(ip) limit 100 as unique_ips_100 ``` -------------------------------- ### Serialization Example Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/bits-and-blooms/bitset/README.md Demonstrates how to serialize a bitset to a byte buffer using WriteTo and deserialize it back using ReadFrom. ```go const length = 9585 const oneEvery = 97 bs := bitset.New(length) // Add some bits for i := uint(0); i < length; i += oneEvery { bs = bs.Set(i) } var buf bytes.Buffer n, err := bs.WriteTo(&buf) if err != nil { // failure } // Here n == buf.Len() ``` ```go // Read back from buf bs = bitset.New() n, err = bs.ReadFrom(&buf) if err != nil { // error } // n is the number of bytes read ``` -------------------------------- ### Getting the last N logs with last pipe (multiple partitions) Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/logsql.md Example of using the `last` pipe with `partition by` to get up to 3 logs with the biggest `request_duration` for each host. ```logsql _time:1h | last 3 by (request_duration) partition by (host) ``` -------------------------------- ### Installing go-fuzz Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/blevesearch/segment/README.md Instructions for installing the go-fuzz tool. ```bash go get github.com/dvyukov/go-fuzz/go-fuzz go get github.com/dvyukov/go-fuzz/go-fuzz-build ``` -------------------------------- ### Opening a database Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/go.etcd.io/bbolt/README.md Demonstrates how to open a bbolt database file, creating it if it doesn't exist. ```go package main import ( "log" bolt "go.etcd.io/bbolt" ) func main() { // Open the my.db data file in your current directory. // It will be created if it doesn't exist. db, err := bolt.Open("my.db", 0600, nil) if err != nil { log.Fatal(err) } defer db.Close() ... } ``` -------------------------------- ### Rename pipe example 4 Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/logsql.md Removes the 'foo' prefix from all fields that start with 'foo'. ```logsql _time:5m | rename foo* as * ``` -------------------------------- ### Getting a key/value from an FST Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/blevesearch/vellum/README.md Example of retrieving a value associated with a specific key from an FST. ```Go val, exists, err = fst.Get([]byte("dog")) if err != nil { log.Fatal(err) } if exists { fmt.Printf("contains dog with val: %d\n", val) } else { fmt.Printf("does not contain dog") } ``` -------------------------------- ### Import and Open bbolt Database Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/go.etcd.io/bbolt/README.md Example of how to import and open a bbolt database in Go. ```go import bolt "go.etcd.io/bbolt" db, err := bolt.Open(path, 0600, nil) if err != nil { return err } deferr db.Close() ``` -------------------------------- ### fields pipe with wildcard example Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/logsql.md Keeps all fields starting with the 'foo' prefix and drops the rest. ```logsql _time:5m | fields foo* ``` -------------------------------- ### Indexing Example Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/blevesearch/bleve/v2/README.md Demonstrates how to index a Go data structure using Bleve. ```go message := struct { Id string From string Body string }{ Id: "example", From: "xyz@couchbase.com", Body: "bleve indexing is easy", } mapping := bleve.NewIndexMapping() index, err := bleve.New("example.bleve", mapping) if err != nil { panic(err) } index.Index(message.Id, message) ``` -------------------------------- ### Search with Kubernetes Field Prefix Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/logsql.md Example of searching for the 'nginx' word in fields starting with 'kubernetes.' ```logsql kunberetes.*:nginx ``` -------------------------------- ### Example Usage with Preset Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/internal/resources/docs/anomaly-detection/UI.md Example of a minimal configuration file for running vmanomaly in 'ui' preset mode. ```yaml preset: ui # other optional server/settings parameters, e.g. port, max_concurrent_tasks, n_workers, logger_levels, etc. ``` -------------------------------- ### Install Faiss (Linux/macOS) Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/blevesearch/go-faiss/README.md Instructions to clone, build, and install Faiss library with C API enabled. ```bash git clone https://github.com/blevesearch/faiss.git cd faiss cmake -B build -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_C_API=ON -DBUILD_SHARED_LIBS=ON . make -C build sudo make -C build install ``` -------------------------------- ### Get Token By Model Source: https://github.com/victoriametrics/mcp-vmanomaly/blob/main/vendor/github.com/pkoukk/tiktoken-go/README.md Example of encoding text using a model name like gpt-3.5-turbo. ```go package main import ( "fmt" "github.com/pkoukk/tiktoken-go" ) func main() { text := "Hello, world!" encoding := "gpt-3.5-turbo" tkm, err := tiktoken.EncodingForModel(encoding) if err != nil { err = fmt.Errorf("getEncoding: %v", err) return } // encode token := tkm.Encode(text, nil, nil) // tokens fmt.Println(token) // num_tokens fmt.Println(len(token)) } ```