├── DEBIAN ├── control ├── postinst ├── postrm └── prerm ├── LICENSE ├── README.md ├── etc └── init.d │ └── system-api ├── lib └── systemd │ └── system │ └── system-api.service └── opt └── system-api ├── bin └── sys-api-server ├── config ├── application.properties └── configuration.yml ├── data └── .placeholder ├── lib └── server-0.31.2-all.jar └── sample-queries ├── CreateMonitorMutation.graphql ├── DockerCommandMutation.graphql ├── DockerQuery.graphql ├── Events.graphql ├── IntrospectionQuery.graphql ├── ListMonitorsQuery.graphql ├── ReadLogsOnContainerQuery.graphql └── SampleQuery.graphql /DEBIAN/control: -------------------------------------------------------------------------------- 1 | Package: system-api 2 | Version: 0.31.2 3 | Depends: openjdk-21-jre, daemon 4 | Section: utils 5 | Priority: optional 6 | Architecture: all 7 | Maintainer: Krillsson 8 | Description: System API (sys-API) provide both GraphQL and RESTful API's to your computers hardware. 9 | -------------------------------------------------------------------------------- /DEBIAN/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | systemctl daemon-reload 3 | echo "Enabling System API daemon service." 4 | if [[ -f "/lib/systemd/system/system-api.service" ]]; then 5 | systemctl enable system-api.service 6 | fi 7 | if [[ -f "/etc/init.d/system-api" ]]; then 8 | update-rc.d system-api defaults 9 | fi 10 | ln -s /opt/system-api/config/application.properties /etc/application.properties 11 | ln -s /opt/system-api/bin/sys-api-server /usr/bin/sys-api-server 12 | -------------------------------------------------------------------------------- /DEBIAN/postrm: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | systemctl daemon-reload 3 | rm -f /usr/bin/sys-api-server /etc/application.properties /var/run/system-api.pid 4 | -------------------------------------------------------------------------------- /DEBIAN/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Shutting down System API daemon service." 3 | if [[ -f "/lib/systemd/system/system-api.service" ]] || [[ -f "/etc/systemd/system/system-api.service" ]]; then 4 | systemctl stop system-api 5 | systemctl disable system-api.service 6 | elif [[ -f "/etc/init.d/system-api" ]]; then 7 | service system-api stop 8 | update-rc.d -f system-api remove 9 | fi 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | :computer: System API 2 | ===================== 3 | [![Coverage Status](https://coveralls.io/repos/github/Krillsson/sys-api/badge.svg?branch=develop)](https://coveralls.io/github/Krillsson/sys-api?branch=develop) 4 | [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=com.krillsson%3Asys-api&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=com.krillsson%3Asys-api) 5 | 6 | System API (sys-API) provide both GraphQL and RESTful API's to your computers hardware. 7 | 8 | It publishes and monitors values from [OSHI](https://github.com/oshi/oshi) with the help of [Spring](https://spring.io). On Windows the information is supplemented with 9 | [OpenHardwareMonitor](https://github.com/openhardwaremonitor/openhardwaremonitor) with a bit of help from [OhmJni4Net](https://github.com/Krillsson/ohmjni4net). 10 | 11 | >This is the server backend for the Android app Monitee. 12 | > 13 | >:warning: Latest compatible version is [0.17.2](https://github.com/Krillsson/sys-API/releases/tag/0.17.2) :warning: 14 | > 15 | >Get it on Play Store 16 | 17 | ## What can it do? 18 | 19 | Query for: 20 | - CPU usage & info 21 | - Memory usage 22 | - List running processes 23 | - List all network interfaces 24 | - Show info from sensors and fans 25 | - Motherboard information 26 | - List docker containers 27 | - Start/stop docker containers 28 | 29 | ### Monitoring 30 | 31 | Currently, you can monitor 32 | 33 | - CPU load 34 | - CPU temperature 35 | - Memory usage 36 | - Network up 37 | - Network upload/download rate 38 | - Drive space 39 | - Drive read/write rate 40 | - Process ID CPU or Memory 41 | - Docker container in running state 42 | - Connectivity 43 | - External IP changed 44 | 45 | ### GraphQL 46 | 47 | GraphQL is available through the `/graphql` endpoint. It supports the exact same features as the REST-API. Checkout the [schema](server/src/main/resources/schema.graphqls). 48 | 49 | A web-UI for trying out the GraphQL-API is also available at `:8080/`. If you don't want to expose this functionality. It can be disabled via the configuration. 50 | 51 | ```yaml 52 | graphQLPlayGround: 53 | enabled: false 54 | ``` 55 | 56 | If the server is protected by Basic Auth, you need to configure GraphQL Playground to send the `authorization` header. Here's an example with the default credentials: 57 | 58 | ```json 59 | { 60 | "authorization": "Basic dXNlcjpwYXNzd29yZA==" 61 | } 62 | ``` 63 | 64 | ## REST-API 65 | 66 | The `/system` endpoint contains accumulated information about the whole system. Then if you want information for just a specific part of the system you can use the part specific endpoint. 67 | So for example the cpu temperature and usage is under `/cpu`. Some things are excluded from `/system`, such as `/system/jvm` and `/processes` since they contain so much information. 68 | 69 | ### Building UIs 70 | 71 | The general idea is that each item has a root endpoint that contain static information, like a processors name or the names of the disks. Then each and every item has a `/load` endpoint that gives you the current 72 | load of that item and a `/load/history` that gives you the load history over time. Disks or network interfaces always have mappable names or ID's between the root and load/history content. 73 | 74 | History endpoints also have the ability to limit it's output. 75 | 76 | Example: `v2/system/load/history?fromDate=2018-09-23T15:11:55.661&toDate=2018-09-23T15:21:25.659` 77 | 78 | So if you are building a UI on top of this API you can query the root endpoint once or seldom. And then if you want to display load over time you can query the history endpoint once and 79 | then continuously poll the load endpoint and append the results to the history collections. 80 | 81 | ### Monitoring 82 | 83 | Currently, you can monitor 84 | 85 | - CPU load 86 | - CPU temperature 87 | - Memory usage 88 | - Network up or down 89 | 90 | #### Configuring monitors 91 | 92 | You add a monitor by doing a POST call to `/monitors` with the body of `com.krillsson.sysapi.dto.monitor.Monitor`: 93 | 94 | ```json 95 | { 96 | "inertiaInSeconds": "10", 97 | "type": "CPU|CPU_TEMP|DRIVE|GPU|MEMORY|NETWORK_UP", 98 | "threshold": "123" 99 | } 100 | ``` 101 | 102 | If you exclude the `"id"` field from the JSON the API will create a new monitor. If you include an ID the API will update the monitor of that ID if it exists or return NOT FOUND/404 if it does not exist. 103 | 104 | The response for this call will be the UUID of the monitor that was created: 105 | 106 | ```json 107 | { 108 | "id": "4bd27b5a-b3a2-4716-a7bb-8f0bf9815849" 109 | } 110 | ``` 111 | 112 | You can then use this ID to delete or update a monitor. 113 | 114 | _Inertia_: the amount of time in seconds the threshold should be crossed for before triggering a event. The same goes for when 115 | transitioning back to below the threshold. 116 | 117 | _Note_: The `NETWORK_UP` ignores the threshold and uses 1 as value for up and 0 for down. 118 | 119 | _Note_: The cpu, gpu and cpu temp monitors checks if the load goes _above_ the thresholds while the drive and memory onces 120 | monitors considers a violation to be when the value drops below a threshold. 121 | 122 | #### Querying for events 123 | 124 | Call the `/events` endpoints to get the currently ongoing threshold violations (events). 125 | 126 | The response will be an array of `com.krillsson.sysapi.dto.monitor.MonitorEvent`: 127 | 128 | ```json 129 | [ 130 | { 131 | "id": "9723c720-4fa0-4497-a08d-8117aa343713", 132 | "monitorId": "4bd27b5a-b3a2-4716-a7bb-8f0bf9815849", 133 | "time": 1532602649608, 134 | "type": "CPU|CPU_TEMP|DRIVE|GPU|MEMORY|NETWORK_UP", 135 | "monitorStatus": "START|STOP", 136 | "threshold": 123, 137 | "value": 122 138 | } 139 | ] 140 | ``` 141 | 142 | The `"id"` in the response above can be used to delete the events associated with that ID. If you remove a _START_ event 143 | with a particular ID, the _STOP_ event for that event will be discarded. 144 | 145 | ## Running 146 | 147 | Download the [release](https://github.com/Droid-MAX/system-api/releases). 148 | 149 | - Debian/Ubuntu: download the package and use dpkg to install it. 150 | 151 | - Service Manage: 152 | 153 | Start: `sudo service system-api start` 154 | 155 | Stop: `sudo service system-api stop` 156 | 157 | Status: `sudo service system-api status` 158 | 159 | Reload: `sudo service system-api reload` 160 | 161 | Restart: `sudo service system-api restart` 162 | 163 | and service default boot. 164 | 165 | - Log File path: `/var/log/syslog` 166 | 167 | Download the [latest release](https://github.com/Krillsson/sys-api/releases/latest). 168 | 169 | - Windows: unzip the package somewhere convenient and then right click the `.bat` file and choose _Run as administrator_ 170 | - *nix: untar or unzip the package and run the `.sh` file from a terminal 171 | 172 | A GUI in JavaFX is in the making 173 | 174 | ### Concerned about memory usage 175 | 176 | Change the launcher script to this: `java -Xmx256m -Xms128m -jar system-api.jar server configuration.yml` 177 | 178 | ## Configuration 179 | 180 | The configuration.yml file is a [Dropwizard configuration file](https://dropwizard.github.io/dropwizard/manual/configuration.html). 181 | 182 | configuration.yml path is `/etc/configuration.yml` 183 | 184 | Basic Authentication: 185 | 186 | user: 187 | username: [change me] 188 | password: [change me] 189 | 190 | Disable the OhmJni extension on Windows: 191 | 192 | windows: 193 | enableOhmJniWrapper: false 194 | 195 | ### Enable HTTPS 196 | 197 | Forward HTTP to HTTPS: 198 | 199 | forwardHttps: true 200 | 201 | ## Development 202 | 203 | Setup 204 | ```sh 205 | git clone [this repo] sys-api 206 | ``` 207 | ```sh 208 | mvn clean install 209 | ``` 210 | ```sh 211 | cd server 212 | java -jar target/system-api.jar server configuration.yml 213 | ``` 214 | Test 215 | 216 | ```sh 217 | curl -i --user user:password -H "Accept: application/json" -X GET http://localhost:8080/v2/system 218 | ``` 219 | 220 | Package for distribution in a *.zip*, *tar.gz* and *tar.bz2*: 221 | 222 | ```sh 223 | mvn clean package 224 | ``` 225 | 226 | And the resulting files should be located in */server/target/* 227 | 228 | License 229 | ------- 230 | 231 | Licensed under the Apache License, Version 2.0 (the "License"); 232 | you may not use this file except in compliance with the License. 233 | You may obtain a copy of the License at 234 | 235 | http://www.apache.org/licenses/LICENSE-2.0 236 | 237 | Unless required by applicable law or agreed to in writing, software 238 | distributed under the License is distributed on an "AS IS" BASIS, 239 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 240 | See the License for the specific language governing permissions and 241 | limitations under the License. -------------------------------------------------------------------------------- /etc/init.d/system-api: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: system-api 4 | # Required-Start: $network $local_fs $remote_fs 5 | # Required-Stop: $remote_fs 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Short-Description: System API daemon 9 | # Description: System API daemon 10 | ### END INIT INFO 11 | 12 | DESC=system-api 13 | NAME=system-api 14 | DAEMON=/usr/bin/sys-api-server 15 | CONFILE=/etc/application.properties 16 | PIDFILE=/var/run/$NAME.pid 17 | SCRIPTNAME=/etc/init.d/$NAME 18 | 19 | DAEMON_OPTS="--spring.config.location=file:$CONFILE" 20 | 21 | # Exit if the package is not installed 22 | [ -x $DAEMON ] || exit 0 23 | 24 | # Read configuration variable file if it is present 25 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME 26 | 27 | # Load the VERBOSE setting and other rcS variables 28 | . /lib/init/vars.sh 29 | 30 | # Define LSB log_* functions. 31 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. 32 | . /lib/lsb/init-functions 33 | 34 | # 35 | # Function that starts the daemon/service 36 | # 37 | do_start() 38 | { 39 | # Return 40 | # 0 if daemon has been started 41 | # 1 if daemon was already running 42 | # 2 if daemon could not be started 43 | # 3 if configuration file not ready for daemon 44 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ 45 | || return 1 46 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background -m -- $DAEMON_OPTS \ 47 | || return 2 48 | # Add code here, if necessary, that waits for the process to be ready 49 | # to handle requests from services started subsequently which depend 50 | # on this one. As a last resort, sleep for some time. 51 | } 52 | 53 | # 54 | # Function that stops the daemon/service 55 | # 56 | do_stop() 57 | { 58 | # Return 59 | # 0 if daemon has been stopped 60 | # 1 if daemon was already stopped 61 | # 2 if daemon could not be stopped 62 | # other if a failure occurred 63 | start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE 64 | RETVAL="$?" 65 | [ "$RETVAL" = 2 ] && return 2 66 | # Wait for children to finish too if this is a daemon that forks 67 | # and if the daemon is only ever run from this initscript. 68 | # If the above conditions are not satisfied then add some other code 69 | # that waits for the process to drop all resources that could be 70 | # needed by services started subsequently. A last resort is to 71 | # sleep for some time. 72 | start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON 73 | [ "$?" = 2 ] && return 2 74 | # Many daemons don't delete their pidfiles when they exit. 75 | rm -f $PIDFILE 76 | return "$RETVAL" 77 | } 78 | 79 | # 80 | # Function that sends a SIGHUP to the daemon/service 81 | # 82 | do_reload() { 83 | # 84 | # If the daemon can reload its configuration without 85 | # restarting (for example, when it is sent a SIGHUP), 86 | # then implement that here. 87 | # 88 | start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE 89 | return 0 90 | } 91 | 92 | case "$1" in 93 | start) 94 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME" 95 | do_start 96 | case "$?" in 97 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 98 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 99 | esac 100 | ;; 101 | stop) 102 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" 103 | do_stop 104 | case "$?" in 105 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 106 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 107 | esac 108 | ;; 109 | status) 110 | status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? 111 | ;; 112 | reload|force-reload) 113 | # 114 | # If do_reload() is not implemented then leave this commented out 115 | # and leave 'force-reload' as an alias for 'restart'. 116 | # 117 | log_daemon_msg "Reloading $DESC" "$NAME" 118 | do_reload 119 | log_end_msg $? 120 | ;; 121 | restart|force-reload) 122 | # 123 | # If the "reload" option is implemented then remove the 124 | # 'force-reload' alias 125 | # 126 | log_daemon_msg "Restarting $DESC" "$NAME" 127 | do_stop 128 | case "$?" in 129 | 0|1) 130 | do_start 131 | case "$?" in 132 | 0) log_end_msg 0 ;; 133 | 1) log_end_msg 1 ;; # Old process is still running 134 | *) log_end_msg 1 ;; # Failed to start 135 | esac 136 | ;; 137 | *) 138 | # Failed to stop 139 | log_end_msg 1 140 | ;; 141 | esac 142 | ;; 143 | *) 144 | #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 145 | echo "Usage: $SCRIPTNAME {start|stop|status|reload|restart|force-reload}" >&2 146 | exit 3 147 | ;; 148 | esac 149 | -------------------------------------------------------------------------------- /lib/systemd/system/system-api.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=System API daemon 3 | After=network.target syslog.target 4 | 5 | [Service] 6 | Type=simple 7 | ExecStart=/usr/bin/sys-api-server --spring.config.location=file:/etc/application.properties 8 | ExecReload=/bin/kill -HUP $MAINPID 9 | KillMode=process 10 | Restart=always 11 | RestartPreventExitStatus=23 12 | 13 | [Install] 14 | WantedBy=multi-user.target 15 | -------------------------------------------------------------------------------- /opt/system-api/bin/sys-api-server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## sys-api-server start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="/opt/system-api" 39 | cd "`dirname \"$PRG\"`/.." >/dev/null 40 | APP_HOME="/opt/system-api" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="sys-api-server" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and SERVER_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx512m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH="$APP_HOME/lib/server-0.31.2-all.jar" 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=`expr $i + 1` 158 | done 159 | case $i in 160 | 0) set -- ;; 161 | 1) set -- "$args0" ;; 162 | 2) set -- "$args0" "$args1" ;; 163 | 3) set -- "$args0" "$args1" "$args2" ;; 164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=`save "$@"` 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $SERVER_OPTS -jar "\"$CLASSPATH\"" "$APP_ARGS" 182 | 183 | exec "$JAVACMD" "$@" 184 | -------------------------------------------------------------------------------- /opt/system-api/config/application.properties: -------------------------------------------------------------------------------- 1 | ######################################### 2 | ### sys-API spring configuration ### 3 | ######################################### 4 | 5 | # Application ports 6 | http.port=8080 7 | server.port=8443 8 | server.ssl.enabled=true 9 | # GraphQL query web UI at http://localhost:8080/graphiql 10 | spring.graphql.graphiql.enabled=true 11 | 12 | # Log level for the application 13 | logging.level.root=INFO 14 | # Package level log levels 15 | logging.level.com.sun.jna=WARN 16 | logging.level.oshi=WARN 17 | com.krillsson.sysapi.core.webservicecheck=DEBUG 18 | logging.level.org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration=ERROR 19 | 20 | #Internal stuff 21 | spring.application.name=sysapi 22 | spring.jpa.database-platform=org.hibernate.community.dialect.SQLiteDialect 23 | spring.datasource.url=jdbc:sqlite:data/database.sqlite 24 | spring.datasource.driver-class-name=org.sqlite.JDBC 25 | spring.datasource.max-active=1 26 | spring.datasource.hikari.maximum-pool-size=1 27 | spring.task.scheduling.pool.size=5 28 | spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 29 | # docker java client fixes 30 | spring.jackson.mapper.ACCEPT_CASE_INSENSITIVE_ENUMS=true 31 | spring.jackson.mapper.ACCEPT_CASE_INSENSITIVE_PROPERTIES=true 32 | spring.jackson.mapper.ACCEPT_CASE_INSENSITIVE_VALUES=true -------------------------------------------------------------------------------- /opt/system-api/config/configuration.yml: -------------------------------------------------------------------------------- 1 | ######################################### 2 | ### sys-API user configuration ### 3 | ######################################### 4 | metricsConfig: 5 | monitor: 6 | interval: 45 7 | unit: SECONDS 8 | history: 9 | interval: 30 10 | unit: MINUTES 11 | purging: 12 | olderThan: 14 13 | unit: DAYS 14 | purgeEvery: 1 15 | purgeEveryUnit: DAYS 16 | cache: 17 | enabled: false 18 | duration: 5 19 | unit: SECONDS 20 | user: 21 | username: user 22 | password: password 23 | windows: 24 | enableOhmJniWrapper: true 25 | eventLog: 26 | enabled: true 27 | serviceManagement: 28 | enabled: true 29 | linux: 30 | journalLogs: 31 | enabled: true 32 | systemDaemonServiceManagement: 33 | enabled: true 34 | # web interface for running queries 35 | graphQLPlayGround: 36 | enabled: false 37 | # docker management and metrics support 38 | docker: 39 | enabled: true 40 | # cache: 41 | # enabled: true 42 | # duration: 2 43 | # unit: SECONDS 44 | # uncomment if you'd like to manually specify docker host 45 | # host: unix:///var/run/docker.sock or unix:///run/podman/podman.sock 46 | # resolve external IP and monitor internet connectivity 47 | connectivityCheck: 48 | enabled: true 49 | address: https://ifconfig.me 50 | updateCheck: 51 | enabled: true 52 | address: https://api.github.com 53 | user: krillsson 54 | repo: sys-api 55 | # advertise service in local network for easier client setup 56 | mDNS: 57 | enabled: true 58 | upnp: 59 | enabled: true 60 | forwardHttpToHttps: false 61 | selfSignedCertificates: 62 | enabled: true 63 | ## automatically put external IP in CN 64 | populateCN: true 65 | ## automatically put internal IPs in SAN 66 | populateSAN: true 67 | ## manually populate CN and SAN below 68 | # commonName: sys-api.org 69 | # subjectAlternativeNames: [192.168.0.24, 10.8.0.24] -------------------------------------------------------------------------------- /opt/system-api/data/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Droid-MAX/system-api/dae9b659e7f6581b68476b915c2051b4f614333c/opt/system-api/data/.placeholder -------------------------------------------------------------------------------- /opt/system-api/lib/server-0.31.2-all.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Droid-MAX/system-api/dae9b659e7f6581b68476b915c2051b4f614333c/opt/system-api/lib/server-0.31.2-all.jar -------------------------------------------------------------------------------- /opt/system-api/sample-queries/CreateMonitorMutation.graphql: -------------------------------------------------------------------------------- 1 | mutation createMonitorMutation($input: CreateConditionalMonitorInput!) { 2 | createConditionalValueMonitor(input: $input) { 3 | monitorId 4 | } 5 | } 6 | 7 | #{ 8 | #"input": { 9 | #"type": "CPU_LOAD", 10 | #"inertiaInSeconds": 3, 11 | #"threshold": 5.0 12 | #} 13 | #} -------------------------------------------------------------------------------- /opt/system-api/sample-queries/DockerCommandMutation.graphql: -------------------------------------------------------------------------------- 1 | mutation DockerCommandMutation($input:PerformDockerContainerCommandInput!) { 2 | performDockerContainerCommand(input: $input) { 3 | ... on PerformDockerContainerCommandOutputFailed { 4 | reason 5 | } 6 | ... on PerformDockerContainerCommandOutputSucceeded { 7 | containerId 8 | } 9 | } 10 | } 11 | 12 | 13 | #{ 14 | #"input": { 15 | #"containerId": : "", 16 | #"command": "STOP" 17 | #} 18 | #} -------------------------------------------------------------------------------- /opt/system-api/sample-queries/DockerQuery.graphql: -------------------------------------------------------------------------------- 1 | query docker { 2 | docker { 3 | ... on DockerUnavailable { 4 | reason 5 | isDisabled 6 | } 7 | ... on DockerAvailable { 8 | containers { 9 | names 10 | state 11 | id 12 | image 13 | status 14 | ports { 15 | publicPort 16 | privatePort 17 | } 18 | mounts{ 19 | source 20 | destination 21 | } 22 | config { 23 | env 24 | cmd 25 | exposedPorts{ 26 | port 27 | portProtocol 28 | } 29 | } 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /opt/system-api/sample-queries/Events.graphql: -------------------------------------------------------------------------------- 1 | query Events { 2 | ongoingEvents { 3 | id 4 | startTime 5 | startValue { 6 | ... on NumericalValue { 7 | number 8 | } 9 | ... on ConditionalValue { 10 | condition 11 | } 12 | ... on FractionalValue { 13 | fraction 14 | } 15 | } 16 | monitor { 17 | type 18 | threshold { 19 | ... on NumericalValue { 20 | number 21 | } 22 | ... on ConditionalValue { 23 | condition 24 | } 25 | ... on FractionalValue { 26 | fraction 27 | } 28 | } 29 | } 30 | } 31 | pastEvents { 32 | id 33 | startTime 34 | endTime 35 | endValue { 36 | ... on NumericalValue { 37 | number 38 | } 39 | ... on ConditionalValue { 40 | condition 41 | } 42 | ... on FractionalValue { 43 | fraction 44 | } 45 | } 46 | monitor { 47 | type 48 | threshold { 49 | ... on NumericalValue { 50 | number 51 | } 52 | ... on ConditionalValue { 53 | condition 54 | } 55 | ... on FractionalValue { 56 | fraction 57 | } 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /opt/system-api/sample-queries/IntrospectionQuery.graphql: -------------------------------------------------------------------------------- 1 | query IntrospectionQuery { 2 | __schema { 3 | queryType { 4 | name 5 | } 6 | mutationType { 7 | name 8 | } 9 | subscriptionType { 10 | name 11 | } 12 | types { 13 | ...FullType 14 | } 15 | directives { 16 | name 17 | description 18 | args { 19 | ...InputValue 20 | } 21 | locations 22 | } 23 | } 24 | } 25 | 26 | fragment FullType on __Type { 27 | kind 28 | name 29 | description 30 | fields(includeDeprecated: true) { 31 | name 32 | description 33 | args { 34 | ...InputValue 35 | } 36 | type { 37 | ...TypeRef 38 | } 39 | isDeprecated 40 | deprecationReason 41 | } 42 | inputFields { 43 | ...InputValue 44 | } 45 | interfaces { 46 | ...TypeRef 47 | } 48 | enumValues(includeDeprecated: true) { 49 | name 50 | description 51 | isDeprecated 52 | deprecationReason 53 | } 54 | possibleTypes { 55 | ...TypeRef 56 | } 57 | } 58 | 59 | fragment InputValue on __InputValue { 60 | name 61 | description 62 | type { 63 | ...TypeRef 64 | } 65 | defaultValue 66 | } 67 | 68 | fragment TypeRef on __Type { 69 | kind 70 | name 71 | ofType { 72 | kind 73 | name 74 | ofType { 75 | kind 76 | name 77 | ofType { 78 | kind 79 | name 80 | ofType { 81 | kind 82 | name 83 | } 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /opt/system-api/sample-queries/ListMonitorsQuery.graphql: -------------------------------------------------------------------------------- 1 | query ListMonitorsQuery { 2 | monitors { 3 | type 4 | id 5 | monitoredItemId 6 | currentValue { 7 | ...MonitoredValue 8 | } 9 | threshold { 10 | ...MonitoredValue 11 | } 12 | history { 13 | date 14 | value { 15 | ...MonitoredValue 16 | } 17 | } 18 | } 19 | } 20 | 21 | fragment MonitoredValue on MonitoredValue { 22 | ... on NumericalValue { 23 | number 24 | } 25 | ... on ConditionalValue { 26 | condition 27 | } 28 | ... on FractionalValue { 29 | fraction 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /opt/system-api/sample-queries/ReadLogsOnContainerQuery.graphql: -------------------------------------------------------------------------------- 1 | query ReadLogsOnContainerQuery { 2 | docker { 3 | ... on DockerAvailable { 4 | readLogsForContainer(containerId: ""){ 5 | ...on ReadLogsForContainerOutputSucceeded{ 6 | lines 7 | } 8 | ...on ReadLogsForContainerOutputFailed { 9 | reason 10 | } 11 | } 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /opt/system-api/sample-queries/SampleQuery.graphql: -------------------------------------------------------------------------------- 1 | query SampleQuery { 2 | system { 3 | operatingSystem{ 4 | manufacturer 5 | family 6 | versionInfo{ 7 | version 8 | } 9 | } 10 | hostname 11 | memory { 12 | physicalMemory { 13 | manufacturer 14 | capacityBytes 15 | memoryType 16 | } 17 | metrics { 18 | usedPercent 19 | } 20 | } 21 | networkInterfaces { 22 | name 23 | speed 24 | metrics { 25 | readWriteRate { 26 | receiveBytesPerSecond 27 | sendBytesPerSecond 28 | } 29 | } 30 | } 31 | connectivity { 32 | connected 33 | externalIp 34 | previousExternalIp 35 | } 36 | processes(limit: 10) { 37 | name 38 | user 39 | memoryPercent 40 | cpuPercent 41 | } 42 | processor { 43 | name 44 | metrics { 45 | temperatures 46 | usagePercentage 47 | coreLoads { 48 | percentage 49 | } 50 | } 51 | } 52 | } 53 | } 54 | --------------------------------------------------------------------------------