📊

Grafana

Monitoring & Observability

分析和监控平台,配备美观的仪表盘,用于指标可视化。

Deployment Info

部署: 2-5 min
类别: Monitoring & Observability
支持: 24/7

Share this guide

Overview

Grafana is the leading open-source platform for monitoring and observability, turning your time-series data into beautiful, interactive dashboards and visualizations. Grafana connects to dozens of data sources including Prometheus, InfluxDB, Elasticsearch, PostgreSQL, MySQL, CloudWatch, and many more, allowing you to query, visualize, alert, and explore your metrics, logs, and traces from a single interface. Whether you're monitoring infrastructure, applications, IoT devices, or business metrics, Grafana provides the tools to create stunning dashboards that help you understand your data at a glance.

Key Features

Multi-Data Source Support

Query Prometheus, InfluxDB, Elasticsearch, MySQL, PostgreSQL, CloudWatch, and 100+ more

Beautiful Dashboards

Rich visualization library with graphs, gauges, heatmaps, tables, and custom panels

Alerting & Notifications

Flexible alerting with Slack, PagerDuty, email, webhooks, and more

Explore & Query

Ad-hoc queries and log exploration with intuitive query builders

Templating & Variables

Dynamic dashboards that adapt to different environments and filters

Plugins & Extensions

Extensive plugin ecosystem for data sources, panels, and applications

使用案例

• Infrastructure monitoring (servers, containers, Kubernetes)
• Application performance monitoring (APM)
• IoT and sensor data visualization
• Business analytics and KPI dashboards
• Log aggregation and analysis
• Network monitoring and traffic analysis
• Database performance monitoring

Installation Guide

**Ubuntu Installation:**
```bash
# Add APT repository
sudo apt-get install -y apt-transport-https software-properties-common
sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key
echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list

# Install
sudo apt-get update
sudo apt-get install grafana

# Start service
sudo systemctl start grafana-server
sudo systemctl enable grafana-server

# Access at http://localhost:3000
# Default login: admin/admin
```

**Docker Installation:**
```bash
docker run -d --name=grafana -p 3000:3000 \
-v grafana-storage:/var/lib/grafana \
grafana/grafana-oss:latest
```

**Docker Compose (with Prometheus):**
```yaml
version: '3'
services:
grafana:
image: grafana/grafana-oss:latest
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_INSTALL_PLUGINS=grafana-clock-panel
volumes:
- grafana-data:/var/lib/grafana

prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus-data:/prometheus

volumes:
grafana-data:
prometheus-data:
```

Configuration Tips

**grafana.ini Configuration:**
```ini
[server]
http_port = 3000
domain = grafana.yourdomain.com
root_url = https://grafana.yourdomain.com

[database]
type = postgres
host = localhost:5432
name = grafana
user = grafana
password = password

[security]
admin_user = admin
admin_password = secure_password

[smtp]
enabled = true
host = smtp.gmail.com:587
user = your-email@gmail.com
password = your-app-password
from_address = grafana@yourdomain.com
```

**Add Prometheus Data Source (API):**
```bash
curl -X POST http://admin:password@localhost:3000/api/datasources \
-H "Content-Type: application/json" \
-d '{
"name": "Prometheus",
"type": "prometheus",
"url": "http://localhost:9090",
"access": "proxy",
"isDefault": true
}'
```

**Dashboard JSON (Simple CPU Dashboard):**
```json
{
"dashboard": {
"title": "CPU Monitoring",
"panels": [{
"title": "CPU Usage",
"type": "graph",
"targets": [{
"expr": "100 - (avg(irate(node_cpu_seconds_total{mode=\"idle\"}[5m])) * 100)"
}]
}]
}
}
```

**Best Practices:**
- Use folders to organize dashboards
- Implement dashboard variables for flexibility
- Set up alerting rules with proper thresholds
- Use PostgreSQL/MySQL in production (not SQLite)
- Enable HTTPS with reverse proxy (Nginx/Caddy)
- Configure authentication (OAuth, LDAP, SAML)
- Regular backups of dashboards and config
- Monitor Grafana itself with Prometheus

请为这篇文章评分

-
Loading...

准备好部署您的应用程序了吗? ?

Get started in minutes with our simple VPS deployment process

注册无需信用卡 • 2-5分钟即可部署