@@ -60,6 +60,43 @@ metrics.account_balance("1234567890").set(-12.2);
6060metrics . errors (). inc ();
6161```
6262
63+ #### Sample Output
64+
65+ ``` text
66+ # HELP app_account_balance The balance of the account, in dollars. Uses a floating point number.
67+ # TYPE app_account_balance gauge
68+ app_account_balance{account_id="1234567890",host="localhost",port="8080"} -12.2
69+
70+ # HELP app_current_active_users The current number of active users.
71+ # TYPE app_current_active_users gauge
72+ app_current_active_users{host="localhost",port="8080",service="service-1"} 20
73+
74+ # HELP app_errors The total number of errors.
75+ # TYPE app_errors counter
76+ app_errors{host="localhost",port="8080"} 1
77+
78+ # HELP app_http_requests_duration The duration of HTTP requests.
79+ # TYPE app_http_requests_duration histogram
80+ app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.005"} 0
81+ app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.01"} 0
82+ app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.025"} 0
83+ app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.05"} 0
84+ app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.1"} 0
85+ app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.25"} 0
86+ app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.5"} 0
87+ app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="1"} 1
88+ app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="2.5"} 1
89+ app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="5"} 1
90+ app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="+Inf"} 1
91+ app_http_requests_duration_sum{host="localhost",method="GET",path="/",port="8080"} 1
92+ app_http_requests_duration_count{host="localhost",method="GET",path="/",port="8080"} 1
93+
94+ # HELP app_http_requests_total The total number of HTTP requests.
95+ # TYPE app_http_requests_total counter
96+ app_http_requests_total{host="localhost",method="GET",path="/",port="8080"} 2
97+ app_http_requests_total{host="localhost",method="POST",path="/",port="8080"} 2
98+ ```
99+
63100### Static Metrics
64101
65102You can also generate a static ` LazyLock ` instance by using the ` static ` attribute. When enabled, the builder methods and ` Default ` implementation are made private, ensuring the only way to access the metrics is through the static instance:
@@ -106,39 +143,49 @@ ExporterBuilder::new()
106143 . expect (" Failed to install exporter" );
107144```
108145
109- #### Sample Output
146+ ### Process Metrics
110147
111- ``` text
112- # HELP app_account_balance The balance of the account, in dollars. Uses a floating point number.
113- # TYPE app_account_balance gauge
114- app_account_balance{account_id="1234567890",host="localhost",port="8080"} -12.2
148+ When the ` process ` feature is enabled, the ` ProcessCollector ` can be used to collect metrics about the current process.
115149
116- # HELP app_current_active_users The current number of active users.
117- # TYPE app_current_active_users gauge
118- app_current_active_users{host="localhost",port="8080",service="service-1"} 20
150+ ``` rust
151+ use prometric :: process :: ProcessCollector ;
152+ use prometric_derive :: metrics;
119153
120- # HELP app_errors The total number of errors.
121- # TYPE app_errors counter
122- app_errors{host="localhost",port="8080"} 1
154+ let collector = ProcessCollector :: default ();
155+ collector . collect ();
156+ ```
123157
124- # HELP app_http_requests_duration The duration of HTTP requests.
125- # TYPE app_http_requests_duration histogram
126- app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.005"} 0
127- app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.01"} 0
128- app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.025"} 0
129- app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.05"} 0
130- app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.1"} 0
131- app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.25"} 0
132- app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="0.5"} 0
133- app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="1"} 1
134- app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="2.5"} 1
135- app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="5"} 1
136- app_http_requests_duration_bucket{host="localhost",method="GET",path="/",port="8080",le="+Inf"} 1
137- app_http_requests_duration_sum{host="localhost",method="GET",path="/",port="8080"} 1
138- app_http_requests_duration_count{host="localhost",method="GET",path="/",port="8080"} 1
158+ #### Sample Output
139159
140- # HELP app_http_requests_total The total number of HTTP requests.
141- # TYPE app_http_requests_total counter
142- app_http_requests_total{host="localhost",method="GET",path="/",port="8080"} 2
143- app_http_requests_total{host="localhost",method="POST",path="/",port="8080"} 2
144- ```
160+ ``` text
161+ # HELP process_cpu_usage The CPU usage of the process as a percentage.
162+ # TYPE process_cpu_usage gauge
163+ process_cpu_usage 0.7814099788665771
164+ # HELP process_disk_written_bytes_total The total written bytes to disk by the process.
165+ # TYPE process_disk_written_bytes_total gauge
166+ process_disk_written_bytes_total 0
167+ # HELP process_max_cpu_freq The maximum CPU frequency of all cores in MHz.
168+ # TYPE process_max_cpu_freq gauge
169+ process_max_cpu_freq 4464
170+ # HELP process_max_fds The maximum number of open file descriptors of the process.
171+ # TYPE process_max_fds gauge
172+ process_max_fds 10240
173+ # HELP process_min_cpu_freq The minimum CPU frequency of all cores in MHz.
174+ # TYPE process_min_cpu_freq gauge
175+ process_min_cpu_freq 4464
176+ # HELP process_open_fds The number of open file descriptors of the process.
177+ # TYPE process_open_fds gauge
178+ process_open_fds 45
179+ # HELP process_resident_memory_bytes The resident memory of the process in bytes. (RSS)
180+ # TYPE process_resident_memory_bytes gauge
181+ process_resident_memory_bytes 4603904
182+ # HELP process_resident_memory_usage The resident memory usage of the process as a percentage of the total memory available.
183+ # TYPE process_resident_memory_usage gauge
184+ process_resident_memory_usage 0.00013399124145507813
185+ # HELP process_start_time_seconds The start time of the process in UNIX seconds.
186+ # TYPE process_start_time_seconds gauge
187+ process_start_time_seconds 1762338704
188+ # HELP process_threads The number of OS threads used by the process (Linux only).
189+ # TYPE process_threads gauge
190+ process_threads 1
191+ ```
0 commit comments