-
Notifications
You must be signed in to change notification settings - Fork 324
feat(tools): add tools for InfluxDB datasource #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Shaik-Sirajuddin
wants to merge
27
commits into
grafana:main
Choose a base branch
from
Shaik-Sirajuddin:influx_datasource
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
3edb205
wip:influxb tools
Shaik-Sirajuddin 9e3d11f
feat(influx): add metadata tools(buckets,measurements,tags,keys)
Shaik-Sirajuddin e4eb162
chore(docker): add influxdb2,3 for integration tests
Shaik-Sirajuddin 63abec0
wip(influx-tools): add measurement,tag,field list tools
Shaik-Sirajuddin 70da93c
chore(docker): docker container for influxdb integration tests
Shaik-Sirajuddin da08012
test(influxdb): add query , limit tests
Shaik-Sirajuddin 796c904
feat(influxdb): apply limits for queries
Shaik-Sirajuddin 27f25c9
chore(docker): entrypoints for influxdb init scripts
Shaik-Sirajuddin e6fd613
chore(influxdb): update hint context keys
Shaik-Sirajuddin 1d2642b
chore(influx): add len checks
Shaik-Sirajuddin bc6acf9
Merge branch 'main' of https://github.com/grafana/mcp-grafana into in…
Shaik-Sirajuddin f07bd52
Update tools/influx_db.go
Shaik-Sirajuddin 55f1894
Update tools/influx_db.go
Shaik-Sirajuddin 2846bdf
chore(tools): type response definitions influxdb tools , grafana clie…
Shaik-Sirajuddin 7337fb1
chore(tools): unit tests for influxdb toosl
Shaik-Sirajuddin 366609d
Merge branch 'influx_datasource' of https://github.com/Shaik-Sirajudd…
Shaik-Sirajuddin 04fc22a
chore(tools): apply newline for influxql queries
Shaik-Sirajuddin d3e4e3a
lint(tools): fix lint errors
Shaik-Sirajuddin 0c2a00b
lint(tools): fix lint errors
Shaik-Sirajuddin 24650b1
refractor(tools): use dsquery response types from grafana package
Shaik-Sirajuddin 18bd52b
refactor: rename fluxql to flux in influxdb tool descriptions and tests
Shaik-Sirajuddin 60ce708
chore(tools): replace manual slices cap increase operation with slice…
Shaik-Sirajuddin 93bd6d7
fix(tools): fix failing integration tests
Shaik-Sirajuddin 88a3eae
Merge branch 'main' of https://github.com/grafana/mcp-grafana into in…
Shaik-Sirajuddin c400395
chore(tools): enhance query limit application to support cte influx
Shaik-Sirajuddin ac563f6
refractor(tools): rename tool_name influxdb tools
Shaik-Sirajuddin 41d23d6
chore(tools): escape special characters influxql
Shaik-Sirajuddin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // package grafana | ||
| package grafana | ||
|
|
||
| import "errors" | ||
|
|
||
| var ErrNoRows = errors.New("no rows in result set") | ||
|
|
||
| type DSQueryPayload struct { | ||
| Queries []any `json:"queries"` | ||
| From string `json:"from"` | ||
| To string `json:"to"` | ||
| } | ||
|
|
||
| type DsQueryFrameField struct { | ||
| Name string `json:"name"` | ||
| Type string `json:"type"` | ||
| TypeInfo struct { | ||
| Frame string `json:"frame,omitempty"` | ||
| } `json:"typeInfo,omitempty"` | ||
| Labels struct { | ||
| Field string `json:"_field,omitempty"` | ||
| } `json:"labels"` | ||
| Config map[string]interface{} `json:"config,omitempty"` | ||
| } | ||
|
|
||
| type DsQueryFrame struct { | ||
| Schema struct { | ||
| Name string `json:"name,omitempty"` | ||
| RefID string `json:"refId,omitempty"` | ||
| Fields []DsQueryFrameField `json:"fields"` | ||
| } `json:"schema,omitempty"` | ||
| Data struct { | ||
| Values [][]interface{} `json:"values"` | ||
| } `json:"data"` | ||
| } | ||
|
|
||
| type DsQueryResult struct { | ||
| Status int `json:"status,omitempty"` | ||
| Frames []DsQueryFrame `json:"frames,omitempty"` | ||
| Error string `json:"error,omitempty"` | ||
| } | ||
|
|
||
| // DSQueryResponse represents the raw API response from Grafana's /api/ds/query | ||
| type DSQueryResponse struct { | ||
| Results map[string]DsQueryResult `json:"results"` | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| password |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| admintoken |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| admin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "token": "apiv3_OgXAgbMRgiGXcAQaFLJoaw==", | ||
| "name": "_admin" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #!/bin/bash | ||
| echo "Starting InfluxDB v2 data seeding..." | ||
|
|
||
| ADMIN_TOKEN="admintoken" | ||
| ORG_NAME="system-logs" | ||
| BUCKET_NAME="b-system-logs" | ||
|
|
||
| # --- Generate Timestamps --- | ||
| NOW=$(date +%s%N) | ||
| M1=$((NOW - 7200000000000)) # 2 hours ago | ||
| M2=$((NOW - 3600000000000)) # 1 hour ago | ||
| M3=$((NOW - 1800000000000)) # 30 min ago | ||
| M4=$((NOW - 900000000000)) # 15 min ago | ||
| M5=$((NOW - 300000000000)) # 5 min ago | ||
|
|
||
| # --- Seed b-system-logs bucket --- | ||
| echo "Seeding $BUCKET_NAME bucket..." | ||
| influx write \ | ||
| --token "$ADMIN_TOKEN" \ | ||
| --org "$ORG_NAME" \ | ||
| --bucket "$BUCKET_NAME" \ | ||
| --precision ns \ | ||
| <<EOF | ||
| auth_events,service=ssh,status=fail,ip=192.168.1.50 attempt_count=5i,severity=3i $M1 | ||
| auth_events,service=ssh,status=fail,ip=192.168.1.51 attempt_count=3i,severity=3i $M2 | ||
| auth_events,service=ssh,status=fail,ip=10.0.0.99 attempt_count=8i,severity=4i $M3 | ||
| auth_events,service=web,status=success,ip=10.0.0.15 attempt_count=1i,severity=1i $M4 | ||
| auth_events,service=web,status=success,ip=172.16.0.5 attempt_count=1i,severity=1i $M5 | ||
| auth_events,service=vpn,status=fail,ip=203.0.113.42 attempt_count=12i,severity=5i $M2 | ||
| auth_events,service=vpn,status=success,ip=10.10.0.3 attempt_count=1i,severity=1i $M3 | ||
| auth_events,service=ftp,status=fail,ip=198.51.100.7 attempt_count=2i,severity=2i $M1 | ||
| auth_events,service=smtp,status=success,ip=10.0.1.20 attempt_count=1i,severity=1i $M4 | ||
| auth_events,service=rdp,status=fail,ip=203.0.113.10 attempt_count=20i,severity=5i $M5 | ||
| resource_usage,host=server-alpha,region=us-east cpu_util=45.2,mem_free_gb=12.5,disk_used_pct=55.0,load_1m=1.05,net_in_mbps=10.2 $M1 | ||
| resource_usage,host=server-alpha,region=us-east cpu_util=67.8,mem_free_gb=8.3,disk_used_pct=55.3,load_1m=2.80,net_in_mbps=45.6 $M2 | ||
| resource_usage,host=server-alpha,region=us-east cpu_util=88.9,mem_free_gb=2.1,disk_used_pct=55.5,load_1m=4.20,net_in_mbps=92.1 $M3 | ||
| resource_usage,host=server-alpha,region=us-east cpu_util=91.2,mem_free_gb=1.5,disk_used_pct=55.7,load_1m=5.10,net_in_mbps=98.4 $M4 | ||
| resource_usage,host=server-alpha,region=us-east cpu_util=75.4,mem_free_gb=4.2,disk_used_pct=55.8,load_1m=3.30,net_in_mbps=60.3 $M5 | ||
| resource_usage,host=server-beta,region=us-west cpu_util=12.1,mem_free_gb=30.4,disk_used_pct=22.0,load_1m=0.05,net_in_mbps=5.1 $M1 | ||
| resource_usage,host=server-beta,region=us-west cpu_util=18.5,mem_free_gb=28.9,disk_used_pct=22.1,load_1m=0.45,net_in_mbps=8.3 $M2 | ||
| resource_usage,host=server-beta,region=us-west cpu_util=35.7,mem_free_gb=25.1,disk_used_pct=22.2,load_1m=1.20,net_in_mbps=20.7 $M3 | ||
| resource_usage,host=server-gamma,region=eu-west cpu_util=55.3,mem_free_gb=16.0,disk_used_pct=70.1,load_1m=2.10,net_in_mbps=30.5 $M1 | ||
| resource_usage,host=server-gamma,region=eu-west cpu_util=60.1,mem_free_gb=14.5,disk_used_pct=70.5,load_1m=2.50,net_in_mbps=35.9 $M2 | ||
| resource_usage,host=server-gamma,region=eu-west cpu_util=72.4,mem_free_gb=10.2,disk_used_pct=71.0,load_1m=3.10,net_in_mbps=50.4 $M3 | ||
| resource_usage,host=server-delta,region=ap-south cpu_util=5.2,mem_free_gb=60.1,disk_used_pct=10.0,load_1m=0.02,net_in_mbps=1.2 $M4 | ||
| resource_usage,host=server-delta,region=ap-south cpu_util=8.9,mem_free_gb=58.4,disk_used_pct=10.1,load_1m=0.10,net_in_mbps=3.4 $M5 | ||
| syslog,host=server-alpha,level=ERROR,facility=kern pid=4821i $M3 | ||
| syslog,host=server-alpha,level=WARN,facility=kern pid=1i $M2 | ||
| syslog,host=server-beta,level=INFO,facility=sshd pid=9201i $M1 | ||
| syslog,host=server-gamma,level=ERROR,facility=nginx pid=3310i $M4 | ||
| syslog,host=server-delta,level=INFO,facility=cron pid=7741i $M5 | ||
| syslog,host=server-alpha,level=CRIT,facility=disk pid=1i $M5 | ||
| EOF | ||
|
|
||
| influx write \ | ||
| --token "$ADMIN_TOKEN" \ | ||
| --org "$ORG_NAME" \ | ||
| --bucket "$BUCKET_NAME" \ | ||
| --precision ns \ | ||
| <<EOF | ||
| http_requests,app=api-gateway,method=GET,status=200 count=1500i,latency_ms=45.2,error_rate=0.0 $M1 | ||
| http_requests,app=api-gateway,method=POST,status=201 count=320i,latency_ms=120.5,error_rate=0.0 $M1 | ||
| http_requests,app=api-gateway,method=GET,status=500 count=12i,latency_ms=5001.0,error_rate=1.0 $M2 | ||
| http_requests,app=api-gateway,method=GET,status=200 count=1800i,latency_ms=42.1,error_rate=0.0 $M2 | ||
| http_requests,app=checkout-svc,method=POST,status=200 count=200i,latency_ms=350.0,error_rate=0.0 $M3 | ||
| http_requests,app=checkout-svc,method=POST,status=500 count=25i,latency_ms=6000.0,error_rate=1.0 $M3 | ||
| http_requests,app=checkout-svc,method=POST,status=200 count=190i,latency_ms=400.0,error_rate=0.0 $M4 | ||
| db_queries,app=user-svc,db=postgres,op=SELECT duration_ms=5.2,rows_returned=10i $M1 | ||
| db_queries,app=user-svc,db=postgres,op=INSERT duration_ms=12.1,rows_returned=1i $M2 | ||
| db_queries,app=user-svc,db=redis,op=GET duration_ms=0.8,rows_returned=1i $M3 | ||
| db_queries,app=checkout-svc,db=postgres,op=SELECT duration_ms=250.0,rows_returned=500i $M4 | ||
| db_queries,app=checkout-svc,db=postgres,op=UPDATE duration_ms=80.5,rows_returned=1i $M5 | ||
| queue_stats,app=worker,queue=email pending=45i,processed=1200i,failed=3i,dlq_size=3i $M1 | ||
| queue_stats,app=worker,queue=email pending=120i,processed=1350i,failed=5i,dlq_size=8i $M2 | ||
| queue_stats,app=worker,queue=sms pending=10i,processed=980i,failed=0i,dlq_size=0i $M3 | ||
| queue_stats,app=worker,queue=notifications pending=500i,processed=4000i,failed=12i,dlq_size=12i $M4 | ||
| EOF | ||
|
|
||
| echo "" | ||
| echo "✅ Seeding complete." | ||
| echo " Host: $INFLUX_HOST" | ||
| echo " Org: $ORG_NAME" | ||
| echo " Buckets: $BUCKET_NAME" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #!/bin/bash | ||
|
|
||
| sleep 5 | ||
|
|
||
| AUTH_TOKEN="apiv3_OgXAgbMRgiGXcAQaFLJoaw==" | ||
| DB_NAME="system-logs" | ||
|
|
||
| echo "Creating database: $DB_NAME" | ||
| influxdb3 create database $DB_NAME --token $AUTH_TOKEN | ||
|
|
||
| # --- Generate Timestamps --- | ||
| NOW=$(date +%s%N) | ||
| M1=$((NOW - 7200000000000)) # 2 hours ago | ||
| M2=$((NOW - 3600000000000)) # 1 hour ago | ||
| M3=$((NOW - 1800000000000)) # 30 min ago | ||
| M4=$((NOW - 900000000000)) # 15 min ago | ||
| M5=$((NOW - 300000000000)) # 5 min ago | ||
|
|
||
| echo "Seeding data..." | ||
|
|
||
| cat <<EOF | influxdb3 write --database $DB_NAME --token $AUTH_TOKEN | ||
| auth_events,service=ssh,status=fail,ip=192.168.1.50 attempt_count=5,severity=3 $M1 | ||
| auth_events,service=ssh,status=fail,ip=192.168.1.51 attempt_count=3,severity=3 $M2 | ||
| auth_events,service=ssh,status=fail,ip=10.0.0.99 attempt_count=8,severity=4 $M3 | ||
| auth_events,service=web,status=success,ip=10.0.0.15 attempt_count=1,severity=1 $M4 | ||
| auth_events,service=web,status=success,ip=172.16.0.5 attempt_count=1,severity=1 $M5 | ||
| auth_events,service=vpn,status=fail,ip=203.0.113.42 attempt_count=12,severity=5 $M2 | ||
| auth_events,service=vpn,status=success,ip=10.10.0.3 attempt_count=1,severity=1 $M3 | ||
| auth_events,service=ftp,status=fail,ip=198.51.100.7 attempt_count=2,severity=2 $M1 | ||
| auth_events,service=smtp,status=success,ip=10.0.1.20 attempt_count=1,severity=1 $M4 | ||
| auth_events,service=rdp,status=fail,ip=203.0.113.10 attempt_count=20,severity=5 $M5 | ||
| resource_usage,host=server-alpha,region=us-east cpu_util=45.2,mem_free_gb=12.5,disk_used_pct=55.0,load_1m=1.05,net_in_mbps=10.2 $M1 | ||
| resource_usage,host=server-alpha,region=us-east cpu_util=67.8,mem_free_gb=8.3,disk_used_pct=55.3,load_1m=2.80,net_in_mbps=45.6 $M2 | ||
| resource_usage,host=server-alpha,region=us-east cpu_util=88.9,mem_free_gb=2.1,disk_used_pct=55.5,load_1m=4.20,net_in_mbps=92.1 $M3 | ||
| resource_usage,host=server-alpha,region=us-east cpu_util=91.2,mem_free_gb=1.5,disk_used_pct=55.7,load_1m=5.10,net_in_mbps=98.4 $M4 | ||
| resource_usage,host=server-alpha,region=us-east cpu_util=75.4,mem_free_gb=4.2,disk_used_pct=55.8,load_1m=3.30,net_in_mbps=60.3 $M5 | ||
| resource_usage,host=server-beta,region=us-west cpu_util=12.1,mem_free_gb=30.4,disk_used_pct=22.0,load_1m=0.05,net_in_mbps=5.1 $M1 | ||
| resource_usage,host=server-beta,region=us-west cpu_util=18.5,mem_free_gb=28.9,disk_used_pct=22.1,load_1m=0.45,net_in_mbps=8.3 $M2 | ||
| resource_usage,host=server-beta,region=us-west cpu_util=35.7,mem_free_gb=25.1,disk_used_pct=22.2,load_1m=1.20,net_in_mbps=20.7 $M3 | ||
| resource_usage,host=server-gamma,region=eu-west cpu_util=55.3,mem_free_gb=16.0,disk_used_pct=70.1,load_1m=2.10,net_in_mbps=30.5 $M1 | ||
| resource_usage,host=server-gamma,region=eu-west cpu_util=60.1,mem_free_gb=14.5,disk_used_pct=70.5,load_1m=2.50,net_in_mbps=35.9 $M2 | ||
| resource_usage,host=server-gamma,region=eu-west cpu_util=72.4,mem_free_gb=10.2,disk_used_pct=71.0,load_1m=3.10,net_in_mbps=50.4 $M3 | ||
| resource_usage,host=server-delta,region=ap-south cpu_util=5.2,mem_free_gb=60.1,disk_used_pct=10.0,load_1m=0.02,net_in_mbps=1.2 $M4 | ||
| resource_usage,host=server-delta,region=ap-south cpu_util=8.9,mem_free_gb=58.4,disk_used_pct=10.1,load_1m=0.10,net_in_mbps=3.4 $M5 | ||
| syslog,host=server-alpha,level=ERROR,facility=kern pid=4821 $M3 | ||
| syslog,host=server-alpha,level=WARN,facility=kern pid=1 $M2 | ||
| syslog,host=server-beta,level=INFO,facility=sshd pid=9201 $M1 | ||
| syslog,host=server-gamma,level=ERROR,facility=nginx pid=3310 $M4 | ||
| syslog,host=server-delta,level=INFO,facility=cron pid=7741 $M5 | ||
| syslog,host=server-alpha,level=CRIT,facility=disk pid=1 $M5 | ||
| http_requests,app=api-gateway,method=GET,status=200 count=1500,latency_ms=45.2,error_rate=0.0 $M1 | ||
| http_requests,app=api-gateway,method=POST,status=201 count=320,latency_ms=120.5,error_rate=0.0 $M1 | ||
| http_requests,app=api-gateway,method=GET,status=500 count=12,latency_ms=5001.0,error_rate=1.0 $M2 | ||
| http_requests,app=api-gateway,method=GET,status=200 count=1800,latency_ms=42.1,error_rate=0.0 $M2 | ||
| http_requests,app=checkout-svc,method=POST,status=200 count=200,latency_ms=350.0,error_rate=0.0 $M3 | ||
| http_requests,app=checkout-svc,method=POST,status=500 count=25,latency_ms=6000.0,error_rate=1.0 $M3 | ||
| http_requests,app=checkout-svc,method=POST,status=200 count=190,latency_ms=400.0,error_rate=0.0 $M4 | ||
| db_queries,app=user-svc,db=postgres,op=SELECT duration_ms=5.2,rows_returned=10 $M1 | ||
| db_queries,app=user-svc,db=postgres,op=INSERT duration_ms=12.1,rows_returned=1 $M2 | ||
| db_queries,app=user-svc,db=redis,op=GET duration_ms=0.8,rows_returned=1 $M3 | ||
| db_queries,app=checkout-svc,db=postgres,op=SELECT duration_ms=250.0,rows_returned=500 $M4 | ||
| db_queries,app=checkout-svc,db=postgres,op=UPDATE duration_ms=80.5,rows_returned=1 $M5 | ||
| queue_stats,app=worker,queue=email pending=45,processed=1200,failed=3,dlq_size=3 $M1 | ||
| queue_stats,app=worker,queue=email pending=120,processed=1350,failed=5,dlq_size=8 $M2 | ||
| queue_stats,app=worker,queue=sms pending=10,processed=980,failed=0,dlq_size=0 $M3 | ||
| queue_stats,app=worker,queue=notifications pending=500,processed=4000,failed=12,dlq_size=12 $M4 | ||
| EOF | ||
|
|
||
| echo "✅ Done! Seeded all data into: $DB_NAME" |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.