|
41 | 41 | </p> |
42 | 42 | </div> |
43 | 43 | </div> |
44 | | - <div class="level-item has-text-centered" v-if="cpuCount"> |
| 44 | + <div class="level-item has-text-centered" v-if="processCpuLoad"> |
45 | 45 | <div> |
46 | | - <p class="heading">CPUs</p> |
47 | | - <p v-text="cpuCount"/> |
| 46 | + <p class="heading">Process CPU Usage</p> |
| 47 | + <p v-text="processCpuLoad.toFixed(2)"/> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | | - <div class="level-item has-text-centered" v-if="systemLoad"> |
| 50 | + <div class="level-item has-text-centered" v-if="systemCpuLoad"> |
51 | 51 | <div> |
52 | | - <p class="heading">System Load (last 1m)</p> |
53 | | - <p v-text="systemLoad.toFixed(2)"/> |
| 52 | + <p class="heading">System CPU Usage</p> |
| 53 | + <p v-text="systemCpuLoad.toFixed(2)"/> |
| 54 | + </div> |
| 55 | + </div> |
| 56 | + <div class="level-item has-text-centered" v-if="systemCpuCount"> |
| 57 | + <div> |
| 58 | + <p class="heading">CPUs</p> |
| 59 | + <p v-text="systemCpuCount"/> |
54 | 60 | </div> |
55 | 61 | </div> |
56 | 62 | </div> |
|
59 | 65 | </template> |
60 | 66 |
|
61 | 67 | <script> |
| 68 | + import subscribing from '@/mixins/subscribing'; |
62 | 69 | import Instance from '@/services/instance'; |
| 70 | + import {Observable} from '@/utils/rxjs'; |
63 | 71 | import processUptime from './process-uptime'; |
64 | 72 |
|
65 | 73 | export default { |
|
69 | 77 | required: true |
70 | 78 | } |
71 | 79 | }, |
| 80 | + mixins: [subscribing], |
72 | 81 | components: {processUptime}, |
73 | 82 | data: () => ({ |
74 | 83 | hasLoaded: false, |
75 | 84 | error: null, |
76 | 85 | pid: null, |
77 | 86 | uptime: null, |
78 | | - systemLoad: null, |
79 | | - cpuCount: null |
| 87 | + systemCpuLoad: null, |
| 88 | + processCpuLoad: null, |
| 89 | + systemCpuCount: null |
80 | 90 | }), |
81 | 91 | created() { |
| 92 | + this.fetchPid(); |
82 | 93 | this.fetchUptime(); |
83 | 94 | this.fetchCpuCount(); |
84 | | - this.fetchSystemLoad(); |
85 | | - this.fetchPid(); |
86 | 95 | }, |
87 | 96 | methods: { |
88 | 97 | async fetchUptime() { |
|
94 | 103 | } |
95 | 104 | this.hasLoaded = true; |
96 | 105 | }, |
97 | | - async fetchSystemLoad() { |
98 | | - try { |
99 | | - this.systemLoad = await this.fetchMetric('system.load.average.1m'); |
100 | | - } catch (error) { |
101 | | - console.warn('Fetching System Load failed:', error); |
| 106 | + async fetchPid() { |
| 107 | + if (this.instance.hasEndpoint('env')) { |
| 108 | + try { |
| 109 | + const response = await this.instance.fetchEnv('PID'); |
| 110 | + this.pid = response.data.property.value; |
| 111 | + } catch (error) { |
| 112 | + console.warn('Fetching PID failed:', error); |
| 113 | + } |
| 114 | + this.hasLoaded = true; |
102 | 115 | } |
103 | | - this.hasLoaded = true; |
104 | 116 | }, |
105 | 117 | async fetchCpuCount() { |
106 | 118 | try { |
107 | | - this.cpuCount = await this.fetchMetric('system.cpu.count'); |
| 119 | + this.systemCpuCount = await this.fetchMetric('system.cpu.count'); |
108 | 120 | } catch (error) { |
109 | 121 | console.warn('Fetching Cpu Count failed:', error); |
110 | 122 | } |
111 | 123 | this.hasLoaded = true; |
112 | 124 | }, |
| 125 | + createSubscription() { |
| 126 | + const vm = this; |
| 127 | + return Observable.timer(0, 2500) |
| 128 | + .concatMap(this.fetchCpuLoadMetrics) |
| 129 | + .subscribe({ |
| 130 | + next: data => { |
| 131 | + vm.processCpuLoad = data.processCpuLoad; |
| 132 | + vm.systemCpuLoad = data.systemCpuLoad; |
| 133 | + }, |
| 134 | + error: error => { |
| 135 | + vm.hasLoaded = true; |
| 136 | + console.warn('Fetching CPU Usage metrics failed:', error); |
| 137 | + vm.error = error; |
| 138 | + } |
| 139 | + }); |
| 140 | + }, |
| 141 | + async fetchCpuLoadMetrics() { |
| 142 | + const fetchProcessCpuLoad = this.fetchMetric('process.cpu.usage'); |
| 143 | + const fetchSystemCpuLoad = this.fetchMetric('system.cpu.usage'); |
| 144 | + let processCpuLoad; |
| 145 | + let systemCpuLoad; |
| 146 | + try { |
| 147 | + processCpuLoad = await fetchProcessCpuLoad |
| 148 | + } catch (error) { |
| 149 | + console.warn('Fetching Process CPU Load failed:', error); |
| 150 | + } |
| 151 | + try { |
| 152 | + systemCpuLoad = await fetchSystemCpuLoad |
| 153 | + } catch (error) { |
| 154 | + console.warn('Fetching Sytem CPU Load failed:', error); |
| 155 | + } |
| 156 | + return { |
| 157 | + processCpuLoad, |
| 158 | + systemCpuLoad |
| 159 | + }; |
| 160 | + }, |
113 | 161 | async fetchMetric(name) { |
114 | 162 | const response = await this.instance.fetchMetric(name); |
115 | 163 | return response.data.measurements[0].value; |
116 | | - }, |
117 | | - async fetchPid() { |
118 | | - if (this.instance.hasEndpoint('env')) { |
119 | | - try { |
120 | | - const response = await this.instance.fetchEnv('PID'); |
121 | | - this.pid = response.data.property.value; |
122 | | - } catch (error) { |
123 | | - console.warn('Fetching PID failed:', error); |
124 | | - } |
125 | | - this.hasLoaded = true; |
126 | | - } |
127 | 164 | } |
128 | 165 | } |
129 | 166 | } |
|
0 commit comments