在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):prometheus/pushgateway开源软件地址(OpenSource Url):https://github.com/prometheus/pushgateway开源编程语言(OpenSource Language):JavaScript 47.5%开源软件介绍(OpenSource Introduction):Prometheus PushgatewayThe Prometheus Pushgateway exists to allow ephemeral and batch jobs to expose their metrics to Prometheus. Since these kinds of jobs may not exist long enough to be scraped, they can instead push their metrics to a Pushgateway. The Pushgateway then exposes these metrics to Prometheus. Non-goalsFirst of all, the Pushgateway is not capable of turning Prometheus into a push-based monitoring system. For a general description of use cases for the Pushgateway, please read When To Use The Pushgateway. The Pushgateway is explicitly not an aggregator or distributed counter but rather a metrics cache. It does not have statsd-like semantics. The metrics pushed are exactly the same as you would present for scraping in a permanently running program. If you need distributed counting, you could either use the actual statsd in combination with the Prometheus statsd exporter, or have a look at Weavework's aggregation gateway. With more experience gathered, the Prometheus project might one day be able to provide a native solution, separate from or possibly even as part of the Pushgateway. For machine-level metrics, the textfile collector of the Node exporter is usually more appropriate. The Pushgateway is intended for service-level metrics. The Pushgateway is not an event store. While you can use Prometheus as a data source for Grafana annotations, tracking something like release events has to happen with some event-logging framework. A while ago, we decided to not implement a “timeout” or TTL for pushed metrics because almost all proposed use cases turned out to be anti-patterns we strongly discourage. You can follow a more recent discussion on the prometheus-developers mailing list. Run itDownload binary releases for your platform from the release page and unpack the tarball. If you want to compile yourself from the sources, you need a working Go
setup. Then use the provided Makefile (type For the most basic setup, just start the binary. To change the address
to listen on, use the Using DockerYou can deploy the Pushgateway using the prom/pushgateway Docker image. For example: docker pull prom/pushgateway
docker run -d -p 9091:9091 prom/pushgateway Use itConfigure the Pushgateway as a target to scrapeThe Pushgateway has to be configured as a target to scrape by Prometheus, using
one of the usual methods. However, you should always set LibrariesPrometheus client libraries should have a feature to push the registered metrics to a Pushgateway. Usually, a Prometheus client passively presents metric for scraping by a Prometheus server. A client library that supports pushing has a push function, which needs to be called by the client code. It will then actively push the metrics to a Pushgateway, using the API described below. Command lineUsing the Prometheus text protocol, pushing metrics is so easy that no
separate CLI is provided. Simply use a command-line HTTP tool like
Note that in the text protocol, each line has to end with a line-feed character (aka 'LF' or '\n'). Ending a line in other ways, e.g. with 'CR' aka '\r', 'CRLF' aka '\r\n', or just the end of the packet, will result in a protocol error. Pushed metrics are managed in groups, identified by a grouping key of any
number of labels, of which the first must be the For implications of special characters in label values see the URL section below. Examples:
About the job and instance labelsThe Prometheus server will attach a However, this behavior is usually undesired when scraping a
Pushgateway. Generally, you would like to retain the This leaves us with the case where the metrics pushed to the Pushgateway do not
feature an About metric inconsistenciesThe Pushgateway exposes all pushed metrics together with its own metrics via
the same Inconsistent help strings are tolerated, though. The Pushgateway will pick a winning help string and log about it at info level. Legacy note: The help string of Pushgateway's own The consistency check performed during a push is the same as it happens anyway
during a scrape. In common use cases, scrapes happen more often than
pushes. Therefore, the performance cost of the push-time check isn't
relevant. However, if a large amount of metrics on the Pushgateway is combined
with frequent pushes, the push duration might become prohibitively long. In
this case, you might consider using the command line flag
About timestampsIf you push metrics at time t1, you might be tempted to believe that Prometheus will scrape them with that same timestamp t1. Instead, what Prometheus attaches as a timestamp is the time when it scrapes the Pushgateway. Why so? In the world view of Prometheus, a metric can be scraped at any time. A metric that cannot be scraped has basically ceased to exist. Prometheus is somewhat tolerant, but if it cannot get any samples for a metric in 5min, it will behave as if that metric does not exist anymore. Preventing that is actually one of the reasons to use a Pushgateway. The Pushgateway will make the metrics of your ephemeral job scrapable at any time. Attaching the time of pushing as a timestamp would defeat that purpose because 5min after the last push, your metric will look as stale to Prometheus as if it could not be scraped at all anymore. (Prometheus knows only one timestamp per sample, there is no way to distinguish a 'time of pushing' and a 'time of scraping'.) As there aren't any use cases where it would make sense to attach a different timestamp, and many users attempting to incorrectly do so (despite no client library supporting this), the Pushgateway rejects any pushes with timestamps. If you think you need to push a timestamp, please see When To Use The Pushgateway. In order to make it easier to alert on failed pushers or those that have not
run recently, the Pushgateway will add in the metrics APIAll pushes are done via HTTP. The interface is vaguely REST-like. URLThe default port the Pushgateway is listening to is 9091. The path looks like
If
For other special characters, the usual URI component encoding works, too, but the base64 might be more convenient. Ideally, client libraries take care of the suffixing and encoding. Examples:
|
HTTP_METHOD | API_VERSION | HANDLER | DESCRIPTION |
---|---|---|---|
PUT | v1 | wipe | Safely deletes all metrics from the Pushgateway. |
For example to wipe all metrics from the Pushgateway:
curl -X PUT http://pushgateway.example.org:9091/api/v1/admin/wipe
The query API allows accessing pushed metrics and build and runtime information.
/api/<API_VERSION>/<HANDLER>
HTTP_METHOD | API_VERSION | HANDLER | DESCRIPTION |
---|---|---|---|
GET | v1 | status | Returns build information, command line flags, and the start time in JSON format. |
GET | v1 | metrics | Returns the pushed metric families in JSON format. |
For example :
curl -X GET http://pushgateway.example.org:9091/api/v1/status | jq
{
"status": "success",
"data": {
"build_information": {
"branch": "master",
"buildDate": "20200310-20:14:39",
"buildUser": "[email protected]",
"goVersion": "go1.13.6",
"revision": "eba0ec4100873d23666bcf4b8b1d44617d6430c4",
"version": "1.1.0"
},
"flags": {
"log.format": "logfmt",
"log.level": "info",
"persistence.file": "",
"persistence.interval": "5m0s",
"push.disable-consistency-check": "false",
"web.enable-admin-api": "false",
"web.enable-lifecycle": "false",
"web.external-url": "",
"web.listen-address": ":9091",
"web.route-prefix": "",
"web.telemetry-path": "/metrics"
},
"start_time": "2020-03-11T01:44:49.9189758+05:30"
}
}
curl -X GET http://pushgateway.example.org:9091/api/v1/metrics | jq
{
"status": "success",
"data": [
{
"labels": {
"job": "batch"
},
"last_push_successful": true,
"my_job_duration_seconds": {
"time_stamp": "2020-03-11T02:02:27.716605811+05:30",
"type": "GAUGE",
"help": "Duration of my batch jon in seconds",
"metrics": [
{
"labels": {
"instance": "",
"job": "batch"
},
"value": "0.2721322309989773"
}
]
},
"push_failure_time_seconds": {
"time_stamp": "2020-03-11T02:02:27.716605811+05:30",
"type": "GAUGE",
"help": "Last Unix time when changing this group in the Pushgateway failed.",
"metrics": [
{
"labels": {
"instance": "",
"job": "batch"
},
"value": "0"
}
]
},
"push_time_seconds": {
"time_stamp": "2020-03-11T02:02:27.716605811+05:30",
"type": "GAUGE",
"help": "Last Unix time when changing this group in the Pushgateway succeeded.",
"metrics": [
{
"labels": {
"instance": "",
"job": "batch"
},
"value": "1.5838723477166057e+09"
}
]
}
}
]
}
The Pushgateway provides a set of management API to ease automation and integrations.
HTTP_METHOD | PATH | DESCRIPTION |
---|---|---|
GET | /-/healthy | Returns 200 whenever the Pushgateway is healthy. |
GET | /-/ready | Returns 200 whenever the Pushgateway is ready to serve traffic. |
--web.enable-lifecycle
flag.HTTP_METHOD | PATH | DESCRIPTION |
---|---|---|
PUT | /-/quit | Triggers a graceful shutdown of Pushgateway. |
Alternatively, a graceful shutdown can be triggered by sending a SIGTERM
to the Pushgateway process.
The Pushgateway exposes the following metrics via the configured
--web.telemetry-path
(default: /metrics
):
push_time_seconds
and
push_failure_time_seconds
as explained above.process_...
go_...
promhttp_metric_handler_requests_...
# HELP pushgateway_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which pushgateway was built.
# TYPE pushgateway_build_info gauge
pushgateway_build_info{branch="master",goversion="go1.10.2",revision="8f88ccb0343fc3382f6b93a9d258797dcb15f770",version="0.5.2"} 1
# HELP pushgateway_http_push_duration_seconds HTTP request duration for pushes to the Pushgateway.
# TYPE pushgateway_http_push_duration_seconds summary
pushgateway_http_push_duration_seconds{method="post",quantile="0.1"} 0.000116755
pushgateway_http_push_duration_seconds{method="post",quantile="0.5"} 0.000192608
pushgateway_http_push_duration_seconds{method="post",quantile="0.9"} 0.000327593
pushgateway_http_push_duration_seconds_sum{method="post"} 0.001622878
pushgateway_http_push_duration_seconds_count{method="post"} 8
# HELP pushgateway_http_push_size_bytes HTTP request size for pushes to the Pushgateway.
# TYPE pushgateway_http_push_size_bytes summary
pushgateway_http_push_size_bytes{method="post",quantile="0.1"} 166
pushgateway_http_push_size_bytes{method="post",quantile="0.5"} 182
pushgateway_http_push_size_bytes{method="post",quantile="0.9"} 196
pushgateway_http_push_size_bytes_sum{method="post"} 1450
pushgateway_http_push_size_bytes_count{method="post"} 8
# HELP pushgateway_http_requests_total Total HTTP requests processed by the Pushgateway, excluding scrapes.
# TYPE pushgateway_http_requests_total counter
pushgateway_http_requests_total{code="200",handler="static",method="get"} 5
pushgateway_http_requests_total{code="200",handler="status",method="get"} 8
pushgateway_http_requests_total{code="202",handler="delete",method="delete"} 1
pushgateway_http_requests_total{code="202",handler="push",method="post"} 6
pushgateway_http_requests_total{code="400",handler="push",method="post"} 2
It is in general a good idea to alert on push_time_seconds
being much farther
behind than expected. This will catch both failed pushes as well as pushers
being down completely.
To detect failed pushes much earlier, alert on push_failure_time_seconds > push_time_seconds
.
Pushes can also fail because they are malformed. In this case, they never reach
any metric group and therefore won't set any push_failure_time_seconds
metrics. Those pushes are still counted as
pushgateway_http_requests_total{code="400",handler="push"}
. You can alert on
the rate
of this metric, but you have to inspect the logs to identify the
offending pusher.
The Pushgateway supports TLS and basic authentication. This enables better control of the various HTTP endpoints.
To use TLS and/or basic authentication, you need to pass a configuration file
using the --web.config.file
parameter. The format of the file is described
in the exporter-toolkit repository.
Note that the TLS and basic authentication settings affect all HTTP endpoints: /metrics for scraping, the API to push metrics via /metrics/..., the admin API via /api/..., and the web UI.
The normal binary embeds the web files in the resources
directory.
For development purposes, it is handy to have a running binary use
those files directly (so that you can see the effect of changes immediately).
To switch to direct usage, add -tags dev
to the flags
entry in
.promu.yml
, and then make build
. Switch back to "normal" mode by
reverting the changes to .promu.yml
and typing make assets
.
Relevant style guidelines are the Go Code Review Comments and the Formatting and style section of Peter Bourgon's Go: Best Practices for Production Environments.
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论