File tree Expand file tree Collapse file tree 8 files changed +128
-6
lines changed Expand file tree Collapse file tree 8 files changed +128
-6
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2015 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
+ //go:build !js || wasm
15
+ // +build !js wasm
16
+
17
+ package prometheus
18
+
19
+ import "os"
20
+
21
+ func getPIDFn () func () (int , error ) {
22
+ pid := os .Getpid ()
23
+ return func () (int , error ) {
24
+ return pid , nil
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2015 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
+ //go:build js && !wasm
15
+ // +build js,!wasm
16
+
17
+ package prometheus
18
+
19
+ func getPIDFn () func () (int , error ) {
20
+ return func () (int , error ) {
21
+ return 1 , nil
22
+ }
23
+ }
Original file line number Diff line number Diff line change @@ -246,8 +246,9 @@ func (c *baseGoCollector) Describe(ch chan<- *Desc) {
246
246
// Collect returns the current state of all metrics of the collector.
247
247
func (c * baseGoCollector ) Collect (ch chan <- Metric ) {
248
248
ch <- MustNewConstMetric (c .goroutinesDesc , GaugeValue , float64 (runtime .NumGoroutine ()))
249
- n , _ := runtime .ThreadCreateProfile (nil )
250
- ch <- MustNewConstMetric (c .threadsDesc , GaugeValue , float64 (n ))
249
+
250
+ n := getRuntimeNumThreads ()
251
+ ch <- MustNewConstMetric (c .threadsDesc , GaugeValue , n )
251
252
252
253
var stats debug.GCStats
253
254
stats .PauseQuantiles = make ([]time.Duration , 5 )
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
+ //go:build !js || wasm
15
+ // +build !js wasm
16
+
17
+ package prometheus
18
+
19
+ import "runtime"
20
+
21
+ // getRuntimeNumThreads returns the number of open OS threads.
22
+ func getRuntimeNumThreads () float64 {
23
+ n , _ := runtime .ThreadCreateProfile (nil )
24
+ return float64 (n )
25
+ }
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
+ //go:build js && !wasm
15
+ // +build js,!wasm
16
+
17
+ package prometheus
18
+
19
+ // getRuntimeNumThreads returns the number of open OS threads.
20
+ func getRuntimeNumThreads () float64 {
21
+ return 1
22
+ }
Original file line number Diff line number Diff line change @@ -103,8 +103,7 @@ func NewProcessCollector(opts ProcessCollectorOpts) Collector {
103
103
}
104
104
105
105
if opts .PidFn == nil {
106
- pid := os .Getpid ()
107
- c .pidFn = func () (int , error ) { return pid , nil }
106
+ c .pidFn = getPIDFn ()
108
107
} else {
109
108
c .pidFn = opts .PidFn
110
109
}
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
+ //go:build js
15
+ // +build js
16
+
17
+ package prometheus
18
+
19
+ func canCollectProcess () bool {
20
+ return false
21
+ }
22
+
23
+ func (c * processCollector ) processCollect (ch chan <- Metric ) {
24
+ // noop on this platform
25
+ return
26
+ }
Original file line number Diff line number Diff line change 11
11
// See the License for the specific language governing permissions and
12
12
// limitations under the License.
13
13
14
- //go:build !windows
15
- // +build !windows
14
+ //go:build !windows && !js
15
+ // +build !windows,!js
16
16
17
17
package prometheus
18
18
You can’t perform that action at this time.
0 commit comments