Skip to content

Commit

Permalink
add prometheus template
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenmu.zyl committed Oct 23, 2018
1 parent 427b55f commit 04d1724
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* [在Spring Boot中集成](./exporter/custom_app_support_prometheus.md)
* [小结](./exporter/SUMMARY.md)
* [第5章 数据与可视化](./grafana/README.md)
* 使用Console Template
* [使用Console Template](./grafana/console-template)
* [Grafana详解](./grafana/grafana-intro.md)
* [使用Panel可视化监控数据](./grafana/grafana-panels.md)
* [变化趋势:Graph面板](./grafana/use_graph_panel.md)
Expand Down
2 changes: 1 addition & 1 deletion SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* [在Spring Boot中集成](./exporter/custom_app_support_prometheus.md)
* [小结](./exporter/SUMMARY.md)
* [第5章 数据与可视化](./grafana/README.md)
* 使用Console Template
* [使用Console Template](./grafana/use-console-template.md)
* [Grafana详解](./grafana/grafana-intro.md)
* [使用Panel可视化监控数据](./grafana/grafana-panels.md)
* [变化趋势:Graph面板](./grafana/use_graph_panel.md)
Expand Down
Binary file added grafana/static/prom_graph_timecontrol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grafana/static/query_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 36 additions & 1 deletion grafana/use-console-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,41 @@ Prometheus在`console_libraries`目录中已经内置了一些基本的界面组

无论是`.lib`文件还是`.html`文件均使用了Go Template的语言,感兴趣的读者可以自行在Go语言官网了解更多内容`https://golang.org/pkg/text/template/`

## 定义图表

添加图表

```
<h1>Prometheus HTTP Request Rate</h1>
<h3>Queries</h3>
<div id="queryGraph"></div>
<script>
new PromConsole.Graph({
node: document.querySelector("#queryGraph"),
expr: "sum(rate(prometheus_http_request_duration_seconds_count{job='prometheus'}[5m]))",
name: "Queries",
yAxisFormatter: PromConsole.NumberFormatter.humanizeNoSmallPrefix,
yHoverFormatter: PromConsole.NumberFormatter.humanizeNoSmallPrefix,
yUnits: "/s",
yTitle: "Queries"
})
</script>
```

![](./static/query_graph.png)

添加查询链接:

```
<h3>Links</h3>
{{ template "prom_query_drilldown" (args "prometheus_build_info") }}
```

## 时间轴控制区域

## 定义图表
```
{{ template "prom_graph_timecontrol" . }}
```

![](./static/prom_graph_timecontrol.png)
33 changes: 21 additions & 12 deletions quickstart/install-prometheus-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@ Prometheus基于Golang编写,编译后的软件包,不依赖于任何的第

```
export VERSION=2.4.3
curl -LO https://github.com/prometheus/prometheus/releases/download/$VERSION/prometheus-$VERSION.darwin-amd64.tar.gz
curl -LO https://github.com/prometheus/prometheus/releases/download/v$VERSION/prometheus-$VERSION.darwin-amd64.tar.gz
```

解压,并将Prometheus相关的命令,添加到系统环境变量路径即可:

```
tar -xzf prometheus-${VERSION}.darwin-amd64.tar.gz
cp prometheus-${VERSION}.darwin-amd64/prometheus /usr/local/bin/
cp prometheus-${VERSION}.darwin-amd64/promtool /usr/local/bin/
sudo mkdir -p /data/prometheus
cd prometheus-${VERSION}.darwin-amd64
```

解压后当前目录会包含默认的Prometheus配置文件promethes.yml,拷贝配置文件到/etc/prometheus/prometheus.yml:
解压后当前目录会包含默认的Prometheus配置文件promethes.yml:

```
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
Expand Down Expand Up @@ -51,21 +49,32 @@ scrape_configs:
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- targets: ['localhost:9090']
```

Promtheus作为一个时间序列数据库,其采集的数据会以文件的形似存储在本地中,默认的存储路径为`data/`,因此我们需要先手动创建该目录:

```
mkdir -p data
```

启动prometheus服务:
用户也可以通过参数`--storage.tsdb.path="data/"`修改本地数据存储的路径。

启动prometheus服务,其会默认加载当前路径下的prometheus.yaml文件:

```
prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus
./prometheus
```

正常的情况下,你可以看到以下输出内容:

```
msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
level=info ts=2018-03-11T13:38:06.317645234Z caller=main.go:486 msg="Server is ready to receive web requests."
level=info ts=2018-03-11T13:38:06.317679086Z caller=manager.go:59 component="scrape manager" msg="Starting scrape manager..."
level=info ts=2018-10-23T14:55:14.499484Z caller=main.go:554 msg="Starting TSDB ..."
level=info ts=2018-10-23T14:55:14.499531Z caller=web.go:397 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2018-10-23T14:55:14.507999Z caller=main.go:564 msg="TSDB started"
level=info ts=2018-10-23T14:55:14.508068Z caller=main.go:624 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2018-10-23T14:55:14.509509Z caller=main.go:650 msg="Completed loading of configuration file" filename=prometheus.yml
level=info ts=2018-10-23T14:55:14.509537Z caller=main.go:523 msg="Server is ready to receive web requests."
```

## 使用容器安装
Expand Down
Binary file modified quickstart/static/prometheus-ui-graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 04d1724

Please sign in to comment.