前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS 7 安装osquery监控系统

CentOS 7 安装osquery监控系统

作者头像
shaonbean
发布2019-05-26 09:28:10
1.2K0
发布2019-05-26 09:28:10
举报
文章被收录于专栏:运维前线运维前线

版权声明:本文为木偶人shaon原创文章,转载请注明原文地址,非常感谢。 https://cloud.tencent.com/developer/article/1434658

osquery 简介

  • osquery是一个SQL驱动操作系统检测和分析工具。osquery支持像SQL语句一样查询系统的各项指标,可以用于OSX和Linux操作系统。它使得底层操作系统分析和监控性能更加直观
  • 项目主页:http://osquery.io/
  • 代码托管地址:https://github.com/facebook/osquer

osquery 安装

代码语言:javascript
复制
[root@linuxprobe~]# yum -y install https://osquery-packages.s3.amazonaws.com/centos7/noarch/osquery-s3-centos7-repo-1-0.0.noarch.rpm
[root@linuxprobe~]# yum -y install osquery 

osquery 使用文档: https://osquery.io/docs/tables/

代码语言:javascript
复制
# 使用例子
# run osquery shell
[root@linuxprobe~]# osqueryi
osquery - being built, with love, at Facebook
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using a virtual database. Need help, type '.help'
osquery> 
# show all column of tables for OS version
osquery> select * from os_version; 
+--------------+----------+-------+-------+-------+-------+----------+---------------+----------+
| name         | version  | major | minor | patch | build | platform | platform_like | codename |
+--------------+----------+-------+-------+-------+-------+----------+---------------+----------+
| CentOS Linux | 7 (Core) | 7     |       |       |       | centos   | rhel fedora   |          |
+--------------+----------+-------+-------+-------+-------+----------+---------------+----------+

# show some column of tables for System info
osquery> select hostname, cpu_brand, hardware_vendor, hardware_model from system_info; 
+----------------+-----------------------------------------+-----------------+-------------------------+
| hostname       | cpu_brand                               | hardware_vendor | hardware_model          |
+----------------+-----------------------------------------+-----------------+-------------------------+
| linuxprobe.org | Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz | VMware, Inc.    | VMware Virtual Platform |
+----------------+-----------------------------------------+-----------------+-------------------------+

# show some column of tables and also specify over 1000 of UID for User info
osquery> select uid, gid, username, shell from users where uid >= 1000; 
+-------+-------+-----------+---------------+
| uid   | gid   | username  | shell         |
+-------+-------+-----------+---------------+
| 1000  | 1000  | shaon     | /bin/bash     |
| 1001  | 1001  | wang      | /bin/bash     |
| 65534 | 65534 | nfsnobody | /sbin/nologin |
+-------+-------+-----------+---------------+

# show all column of tables for CPU Time
osquery> select * from cpu_time; 
+------+------+------+--------+-------+--------+-----+---------+-------+-------+------------+
| core | user | nice | system | idle  | iowait | irq | softirq | steal | guest | guest_nice |
+------+------+------+--------+-------+--------+-----+---------+-------+-------+------------+
| 0    | 912  | 0    | 3679   | 54015 | 2149   | 0   | 157     | 0     | 0     | 0          |
+------+------+------+--------+-------+--------+-----+---------+-------+-------+------------+

# to quit shell, push Ctrl+D 
osquery> 

定时监控设置

  • 创建osquery配置文件
代码语言:javascript
复制
 [root@linuxprobe~]# vi /etc/osquery/osquery.conf
# create new
{
  "options": {
    // select the osquery config plugin (filesystem is default)
    "config_plugin": "filesystem",

    // select the osquery logging plugin (filesystem is default)
    "logger_plugin": "filesystem",

    // the PATH of log direcroty
    "logger_path": "/var/log/osquery",

    // PID file of the daemon
    "pidfile": "/var/osquery/osquery.pidfile",

    // the number of threads for concurrent query
    "worker_threads": "2",

    // enable schedule profiling
    // if adding a query "select * from osquery_schedule" in schedule section,
    // it's possible to record the performances
    "enable_monitor": "true"
  },

  "schedule": {
    // for example, get CPU Time per 300 seconds
    "cpu_time": {
      "query": "SELECT * FROM cpu_time;",
      "interval": 300
    },
    // for example, get settings of resolv.conf per an hour
    "dns_resolvers": {
      "query": "SELECT * FROM dns_resolvers;",
      "interval": 3600
    }
  },

   "packs": {
     // possible to include other configration files
     "hardware-monitoring": "/usr/share/osquery/packs/hardware-monitoring.conf"
   }
}
  • 启动osquery
代码语言:javascript
复制
[root@linuxprobe ~]# systemctl start osqueryd 
[root@linuxprobe ~]#  systemctl enable osqueryd 
Created symlink from /etc/systemd/system/multi-user.target.wants/osqueryd.service to /usr/lib/systemd/system/osqueryd.service.
  • 查看osquery日志
代码语言:javascript
复制
[root@linuxprobe osquery]# less /var/log/osquery/osqueryd.results.log
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016年11月10日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • osquery 简介
  • osquery 安装
  • 定时监控设置
相关产品与服务
代码托管
CODING 代码托管(CODING Code Repositories,CODING-CR)是为开发者打造的云端便捷代码管理工具,旨在为更多的开发者带去便捷、高效的开发体验,全面支持 Git/SVN 代码托管,包括代码评审、分支管理、超大仓库等功能。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档