File tree Expand file tree Collapse file tree 8 files changed +122
-5
lines changed
Expand file tree Collapse file tree 8 files changed +122
-5
lines changed Original file line number Diff line number Diff line change 1+ // +build !js wasm
2+
3+ // Copyright 2015 The Prometheus Authors
4+ // Licensed under the Apache License, Version 2.0 (the "License");
5+ // you may not use this file except in compliance with the License.
6+ // You may obtain a copy of the License at
7+ //
8+ // http://www.apache.org/licenses/LICENSE-2.0
9+ //
10+ // Unless required by applicable law or agreed to in writing, software
11+ // distributed under the License is distributed on an "AS IS" BASIS,
12+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ // See the License for the specific language governing permissions and
14+ // limitations under the License.
15+
16+ package prometheus
17+
18+ import "os"
19+
20+ func getPIDFn () func () (int , error ) {
21+ pid := os .Getpid ()
22+ return func () (int , error ) {
23+ return pid , nil
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ // +build js,!wasm
2+
3+ // Copyright 2015 The Prometheus Authors
4+ // Licensed under the Apache License, Version 2.0 (the "License");
5+ // you may not use this file except in compliance with the License.
6+ // You may obtain a copy of the License at
7+ //
8+ // http://www.apache.org/licenses/LICENSE-2.0
9+ //
10+ // Unless required by applicable law or agreed to in writing, software
11+ // distributed under the License is distributed on an "AS IS" BASIS,
12+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ // See the License for the specific language governing permissions and
14+ // limitations under the License.
15+
16+ package prometheus
17+
18+ func getPIDFn () func () (int , error ) {
19+ return func () (int , error ) {
20+ return 1 , nil
21+ }
22+ }
Original file line number Diff line number Diff line change @@ -246,7 +246,8 @@ func (c *baseGoCollector) Describe(ch chan<- *Desc) {
246246// Collect returns the current state of all metrics of the collector.
247247func (c * baseGoCollector ) Collect (ch chan <- Metric ) {
248248 ch <- MustNewConstMetric (c .goroutinesDesc , GaugeValue , float64 (runtime .NumGoroutine ()))
249- n , _ := runtime .ThreadCreateProfile (nil )
249+
250+ n := getRuntimeNumThreads ()
250251 ch <- MustNewConstMetric (c .threadsDesc , GaugeValue , float64 (n ))
251252
252253 var stats debug.GCStats
Original file line number Diff line number Diff line change 1+ // Copyright 2018 The Prometheus Authors
2+ // Licensed under the Apache License, Version 2.0 (the "License");
3+ // you may not use this file except in compliance with the License.
4+ // You may obtain a copy of the License at
5+ //
6+ // http://www.apache.org/licenses/LICENSE-2.0
7+ //
8+ // Unless required by applicable law or agreed to in writing, software
9+ // distributed under the License is distributed on an "AS IS" BASIS,
10+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+ // See the License for the specific language governing permissions and
12+ // limitations under the License.
13+
14+ // +build !js wasm
15+
16+ package prometheus
17+
18+ import "runtime"
19+
20+ // getRuntimeNumThreads returns the number of open OS threads.
21+ func getRuntimeNumThreads () float64 {
22+ n , _ := runtime .ThreadCreateProfile (nil )
23+ return float64 (n )
24+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2018 The Prometheus Authors
2+ // Licensed under the Apache License, Version 2.0 (the "License");
3+ // you may not use this file except in compliance with the License.
4+ // You may obtain a copy of the License at
5+ //
6+ // http://www.apache.org/licenses/LICENSE-2.0
7+ //
8+ // Unless required by applicable law or agreed to in writing, software
9+ // distributed under the License is distributed on an "AS IS" BASIS,
10+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+ // See the License for the specific language governing permissions and
12+ // limitations under the License.
13+
14+ // +build js,!wasm
15+
16+ package prometheus
17+
18+ // getRuntimeNumThreads returns the number of open OS threads.
19+ func getRuntimeNumThreads () float64 {
20+ return 1
21+ }
Original file line number Diff line number Diff line change @@ -103,8 +103,7 @@ func NewProcessCollector(opts ProcessCollectorOpts) Collector {
103103 }
104104
105105 if opts .PidFn == nil {
106- pid := os .Getpid ()
107- c .pidFn = func () (int , error ) { return pid , nil }
106+ c .pidFn = getPIDFn ()
108107 } else {
109108 c .pidFn = opts .PidFn
110109 }
Original file line number Diff line number Diff line change 1+ // Copyright 2019 The Prometheus Authors
2+ // Licensed under the Apache License, Version 2.0 (the "License");
3+ // you may not use this file except in compliance with the License.
4+ // You may obtain a copy of the License at
5+ //
6+ // http://www.apache.org/licenses/LICENSE-2.0
7+ //
8+ // Unless required by applicable law or agreed to in writing, software
9+ // distributed under the License is distributed on an "AS IS" BASIS,
10+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+ // See the License for the specific language governing permissions and
12+ // limitations under the License.
13+
14+ // +build js
15+
16+ package prometheus
17+
18+ func canCollectProcess () bool {
19+ return false
20+ }
21+
22+ func (c * processCollector ) processCollect (ch chan <- Metric ) {
23+ // noop on this platform
24+ return
25+ }
Original file line number Diff line number Diff line change 1111// See the License for the specific language governing permissions and
1212// limitations under the License.
1313
14- //go:build !windows
15- // +build !windows
14+ //go:build !windows && !js
15+ // +build !windows,!js
1616
1717package prometheus
1818
You can’t perform that action at this time.
0 commit comments