I've been interested in the topic of devOps recently, so I studied the open source project related to monitor and flipped into an article on medium. In the actual project, I saw colleagues in the devOps group using similar monitoring, so I wanted to enjoy it and learn about monitoring visualization.
Monitored service configuration
There is a spring-boot project locally and it also relies on jolokia (mainly to expose JMX mbeans through HTTP)
Project configuration is also indispensable
endpoints: enabled: true jmx: enabled: true jolokia: enabled: truemanagement: security: enabled: false
Visit the URL to see if it is OK
http://localhost:8080/jolokia/read/org.springframework.boot:name=metricsEndpoint,type=Endpoint/Data
Build a monitoring system
If you can see the data, it means that the server side configuration is fine. How do we build Telegraf + InfluxDB + Grafana? This three components work together in this way. Telegraf actually collects information. For example, visit the URL above every 10 seconds to get metrics, store the collected data in InfluxDB, and then Grafana does data visualization.
But if it is too troublesome to install it manually, please help the universal github and find a very good project (https://github.com/samuelebistoletti/docker-statsd-influxdb-grafana), directly fork and modify some configurations to serve your project. If you don't understand the relevant configuration, you can run it directly first and then go in through ssh to find out.
ssh root@localhost -p 22022
In terms of configuration, the main thing is to modify Telegraf, because it connects to different projects. What kind of information you need to collect, such as CPU, disk, net, etc., must be equipped in Telegraf. For simplicity, I only set up three inputs.
# /etc/telegraf/telegraf.conf[[inputs.jolokia]] context = "/jolokia"[[inputs.jolokia.servers]] name = "springbootapp" host = "{app ip address}" port = "8080"[[inputs.jolokia.metrics]] name = "metrics" mbean = "org.springframework.boot:name=metricsEndpoint,type=Endpoint" attribute = "Data"[[inputs.jolokia.metrics]] name = "tomcat_max_threads" mbean = "Tomcat:name=/"http-nio-8080/",type=ThreadPool" attribute = "maxThreads"[[inputs.jolokia.metrics]] name = "tomcat_current_threads_busy" mbean = "Tomcat:name=/"http-nio-8080/",type=ThreadPool" attribute = "currentThreadsBusy"In fact, it is spring-boot standard metrics and tomcat Threads.
After completion, restart the service /etc/init.d/telegraf restart
View monitoring data
We visit InfluxDB to see if there is any data http://localhost:3004/, and switch the database to Telegraf. Enter the following command to try
SHOW MEASUREMENTSSELECT * FROM jolokiaSELECT * FROM cpuSELECT * FROM memSELECT * FROM diskio
For example, if you enter SELECT * FROM jolokia , you can see what data is exposed by spring-boot. From the time column, it can also be seen that Telegraf is collected every 10 seconds. If it is too frequent, it will also be a pressure on the server.
The above basically covers some metrics of CPU, memory and storage.
In fact, you can also configure network-related configurations. If you are interested, you can see the official telegraf.conf, which contains examples of configuring [[inputs.net]].
Data visualization
Once the data is available, the next step is visualization.
Follow the Github mentioned above to enter http://localhost:3003/,
Using the wizard click on Add data sourceChoose a name for the source and flag it as DefaultChoose InfluxDB as typeChoose direct as accessFill remaining fields as follows and click on Add without altering other fieldsUrl: http://localhost:8086Database: telegrafUser: telegrafPassword: telegraf
After adding InfluxDB, create a new Dashboard and quickly ADD a few graphs.
For demonstration, I added three, using the following three sets of query statements to render three charts
SELECT MEAN(usage_system) + MEAN(usage_user) AS cpu_total FROM cpu WHERE $timeFilter GROUP BY time($interval)SELECT means("total") as "total" FROM "mem" WHERE $timeFilter GROUP BY time($interval) fill(null)SELECT means("used") as "used" FROM "mem" WHERE $timeFilter GROUP BY time($interval) fill(null)SELECT mean("metrics_heap.used") as "heap_usage" FROM "jolokia" WHERE $timeFilter GROUP BY time($interval) fill(null)The first one is CPU usage; the second one is memory usage, the green line is Total, the yellow line is Used; the third one is the use of jvm heap provided by Jolokia, and you can see the GC situation.
I have also configured Tomcat collection just now, and it is also perfect to see the Thread situation of Tomcat.
SELECT mean("tomcat_max_threads") FROM "jolokia" WHERE $timeFilter GROUP BY time($interval) fill(null)SELECT mean("tomcat_current_threads_busy") FROM "jolokia" WHERE $timeFilter GROUP BY time($interval) fill(null)summary
The above is the Spring boot monitoring introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!