Tech & DevOps HubEspace Tech & DevOps

Explorez le monde du Dev, du Cloud et des outils DevOps à travers nos articles et discussions Explore the world of development, the cloud and DevOps tools
 FR      EN
Monitoring (elk/promQL)
Elastic
Create API key
curl -u admin:password -X POST 'https://clustername:9200/_security/api_key' -H 'Content-Type: application/json' -d '{"name": "devops-api", "expiration": "1d"}'

Generates access key for automations.
Get cluster state
curl 'https://clustername:9200/_cluster/health?pretty'

Displays nodes, indices, health and status.
Bulk operations
curl -X POST 'https://clustername:9200/_bulk' -H 'Content-Type: application/json' -d '
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "user" : "John Doe" }
{ "delete" : { "_index" : "test", "_id" : "2" } }'

Performs multiple indexing operations.
Search match query
curl -X GET 'https://clustername:9200/indexname/_search' -H 'Content-Type: application/json' -d '{"query": {"match": {"user": "Jane"}}}'

Returns matching documents.
Index document
curl -X POST -H 'Content-Type: application/json' 'https://clustername:9200/maindex/_doc/1' -d '{"user":"Jane","action":"login"}'

Adds or replaces a document.
Show index mapping
curl 'https://clustername:9200/indexname/_mapping?pretty'

Displays mapping: fields and types.
List aliases
curl 'https://clustername:9200/_cat/aliases?pretty'

Shows aliases for routing and indexing.
List indices
curl "https://clusterName:9200/_cat/indices?pretty"

Displays all indices.
List indices (extended)
curl 'https://clustername:9200/_cat/indices?pretty'

Shows index size, docs count and status.
Get document by ID
curl 'https://clustername:9200/maindex/_doc/1?pretty'

Returns full document.
Restore index
curl -X POST 'https://clustername:9200/_snapshot/repo1/snap1/_restore' -H 'Content-Type: application/json' -d '{"indices": "maindex"}'

Restores index from snapshot.
Delete document by ID
curl -X DELETE 'https://clustername:9200/maindex/_doc/1?pretty'

Deletes a document safely.
Use API key
curl -H 'Authorization: ApiKey <base64-API_KEY>' 'https://clustername:9200/_cluster/health?pretty'

Authenticates using an API key.
Check cluster health
curl "https://clusterName:9200/_cluster/health?pretty"

Shows global Elasticsearch cluster health.
Grafana
Create dashboard via API
curl -X POST -H "Authorization: Bearer <API_KEY>" -H "Content-Type: application/json" "http://localhost:3000/api/dashboards/db" --data-binary @new_dashboard.json

Creates dashboard from JSON payload.
Create service token
curl -X POST -H "Authorization: Bearer <API_KEY>" -H "Content-Type: application/json" '"http://localhost:3000/api/serviceaccounts/{id}/tokens" '--data '{"name":"api-token","secondsToLive":86400}'

Generates an API token valid 24h.
Create datasource
curl -X POST -H "Authorization: Bearer <API_KEY>" -H "Content-Type: application/json" '"http://localhost:3000/api/datasources" '--data-binary @my_datasource.json

Creates a datasource (Prometheus, Loki, etc.).
Export dashboard config
curl -H "Authorization: Bearer <API_KEY>" "http://localhost:3000/api/dashboards/uid/E3D98A6A"

Returns JSON configuration of dashboard.
List folders
curl -H "Authorization: Bearer <API_KEY>" "http://localhost:3000/api/folders"

Returns all dashboard folders.
List organizations
curl -H "Authorization: Bearer <API_KEY>" "http://localhost:3000/api/orgs"

Shows all organizations and IDs.
List dashboards
curl -H "Authorization: Bearer <API_KEY>" "http://localhost:3000/api/search?type=dash-db"

Displays all dashboards.
List datasources
curl -H "Authorization: Bearer <API_KEY>" "http://localhost:3000/api/datasources"

Shows all datasources with configuration.
List Grafana users
curl -H "Authorization: Bearer <API_KEY>" "http://localhost:3000/api/users"

Retrieves all Grafana users via API.
Test Grafana API
curl -H "Authorization: Bearer <API_KEY>" "http://localhost:3000/api/health"

Returns database and version info.
Prometheus
Export Spring Boot metrics
management.endpoints.web.exposure.include=prometheus

Enables Prometheus metrics exposure.
Query CPU usage
curl "http://localhost:9090/api/v1/query?query=node_cpu_seconds_total"

Retrieves total CPU metric per instance.
List active alerts
curl http://localhost:9093/api/v2/alerts

Returns active alerts in JSON format.
Reload Prometheus config
kill -HUP $(pidof prometheus)

Reloads Prometheus configuration without restart.
Check Prometheus readiness
curl http://localhost:9090/-/ready

Returns Prometheus readiness status.
PromQL
Create simple alert
- alert: InstanceDown
 expr: up == 0
 for: 1m

Triggers alert if instance is down for over 1 minute.
Top 5 pods CPU
topk(5, rate(container_cpu_usage_seconds_total[5m]))

Shows highest CPU-consuming pods.
Memory usage in %
(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100

Computes memory usage percentage.
Top 5 CPU pods
topk(5, rate(container_cpu_usage_seconds_total[5m]))

Identifies pods to investigate for optimization.