@@ -110,7 +110,11 @@ c.labels('post', '/submit').inc()
110110
111111## Exporting
112112
113- Metrics are exposed over HTTP, to be read by the Prometheus server. For example:
113+ There are several options for exporting metrics.
114+
115+ ## HTTP handler
116+
117+ Metrics are usuall exposed over HTTP, to be read by the Prometheus server. For example:
114118
115119``` python
116120from prometheus_client import MetricsHandler
@@ -121,3 +125,22 @@ httpd.serve_forever()
121125```
122126
123127Visit [ http://localhost:8000/ ] ( http://localhost:8000/ ) to view the metrics.
128+
129+ ## Node exporter textfile collector
130+
131+ The [ textfile collector] ( https://github.com/prometheus/node_exporter#textfile-collector )
132+ allows machine-level statistics to be exported out via the Node exporter.
133+
134+ This is useful for monitoring cronjobs, or for writing cronjobs to expose metrics
135+ about your system that the Node exporter does not support or would not make sense
136+ to perform at every scrape (for example, anything involving subprocesses).
137+
138+ ``` python
139+ from prometheus_client import CollectorRegistry,Gauge,write_to_textfile
140+ registry = CollectorRegistry()
141+ g = Gauge(' raid_status' , ' 1 if raid array is okay' , registry = registry)
142+ g.set(1 )
143+ write_to_textfile(' /configured/textfile/path/raid.prom' , registry)
144+ ```
145+
146+ A separate registry is used, as the default registry may contain other metrics.
0 commit comments