Monitoring and Logging
Monitoring and Logging are critical aspects of DevOps that involve tracking and analyzing system behavior and performance. Tools like Prometheus and Grafana are commonly used for monitoring, and ELK (Elasticsearch, Logstash, Kibana) stack is popular for logging. Here's an example of using Prometheus and Grafana to monitor system metrics:
csharp
# prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
- job_name: 'my-app'
static_configs:
- targets: ['localhost:8080']
# dashboard.json
{
"title": "My App Dashboard",
"panels": [
{
"title": "CPU Usage",
"targets": [
{
"expr": "100 - (avg by (instance) (irate(node_cpu_seconds_total{mode='idle'}[5m])) * 100)",
"legendFormat": "{{instance}}",
"refId": "A"
}
],
"type": "gauge"
},
{
"title": "Memory Usage",
"targets": [
{
"expr": "sum(node_memory_MemTotal_bytes - node_memory_MemFree_bytes) / sum(node_memory_MemTotal_bytes) * 100",
"legendFormat": "Used",
"refId": "A"
},
{
"expr": "sum(node_memory_MemFree_bytes) / sum(node_memory_MemTotal_bytes) * 100",
"legendFormat": "Free",
"refId": "B"
}
],
"type": "gauge"
}
],
"time": {
"from": "now-6h",
"to": "now"
}
}
No comments:
Post a Comment