Automation Tools Saltstack Mine custom collection minion information

Source: Internet
Author: User
Tags config flush sleep haproxy saltstack

What is mine doing? Is that you define the collection module in mine, he will collect the data, where it is stored, do not know, but certainly the client Minino Local. Interested friends can check Saltstack code.


Paste it down here first, official DOC usage:

The code is as follows Copy Code
Mine.delete:

Remove specific function contents of minion. Returns True on success.

CLI Example:

Salt ' * ' mine.delete ' network.interfaces '


Mine.flush:

Remove all mine contents of minion. Returns True on success.

CLI Example:

Salt ' * ' Mine.flush


Mine.get:

Get data from the mine based on the target, function and Expr_form

Targets can be matched based to any standard matching system so can be
Matched on the master via these keywords::

Glob
Pcre
Grain
Grain_pcre

CLI Example:

Salt ' * ' mine.get ' * ' network.interfaces
Salt ' * ' mine.get ' os:fedora ' network.interfaces grain


Mine.send:

Send a specific function to the mine.

CLI Example:

Salt ' * ' Mine.send network.interfaces eth0


Mine.update:

Execute the configured functions and send the data back up to the master
The functions to is executed are merged from the Master Config, Pillar and
Minion config under the option "Function_cache":

Mine_functions:
Network.ip_addrs:




Configuration is very simple, run to the Minion end, configure the file, open a few modules of detection.

The code is as follows Copy Code
[Root@vm-10-154-252-46 utils]# Tail/etc/salt/minion

Mine_functions:

Test.ping: []

Network.dig:

-Www.naver.com

Network.usage: []


Mine_interval:1


Then we ran to master to catch the data.


[root@vm-10-154-252-82 ~/clusterops/templates] $salt ' 10.154.252.46 ' mine.get ' * ' Network.dig

10.154.252.46:

----------

10.154.252.46:



; <<>> DiG 9.8.2rc1-redhat-9.8.2-0.10.rc1.el6 <<>> www.baidu.com

;; Global options: +cmd

;; Got Answer:

;; ->>header<<-opcode:query, Status:noerror, id:5279

;; Flags:qr Rd RA; Query:1, Answer:3, Authority:5, Additional:2

;; Question section:

; www.baidu.com. In A


;; ANSWER section:

www.baidu.com. 186 in CNAME www.a.shifen.com.

Www.a.shifen.com. 149 in a 220.181.111.188

Www.a.shifen.com. 149 in a 220.181.112.244

;; Authority section:

a.shifen.com. 186 in NS ns3.a.shifen.com.

a.shifen.com. 186 in NS ns1.a.shifen.com.

a.shifen.com. 186 in NS ns5.a.shifen.com.

a.shifen.com. 186 in NS ns2.a.shifen.com.

a.shifen.com. 186 in NS ns4.a.shifen.com.

;; ADDITIONAL section:

Ns5.a.shifen.com in a 119.75.219.43

Ns2.a.shifen.com. 186 in a 180.149.133.241



;; Query Time:1 msec

;; server:10.150.0.253#53 (10.150.0.253)

;; When:wed 2 14:42:55 2014

;; MSG SIZE rcvd:212


[Root@vm-10-154-252-82 ~/clusterops/templates]$




What I defined earlier was a minute to generate the data. The log end of the Minon can be reflected.

The code is as follows Copy Code
2014-07-03 09:15:05,054 [Salt.loaded.int.module.mine
2014-07-03 09:15:05,186 [Salt.loaded.int.module.mine
2014-07-03 09:16:05,149 [Salt.loaded.int.module.mine
2014-07-03 09:16:05,274 [Salt.loaded.int.module.mine
2014-07-03 09:17:05,242 [Salt.loaded.int.module.mine
2014-07-03 09:17:05,366 [Salt.loaded.int.module.mine
2014-07-03 09:18:05,336 [Salt.loaded.int.module.mine
2014-07-03 09:18:05,463 [Salt.loaded.int.module.mine
2014-07-03 09:19:05,430 [Salt.loaded.int.module.mine
2014-07-03 09:19:05,554 [Salt.loaded.int.module.mine
2014-07-03 09:20:05,523 [Salt.loaded.int.module.mine
2014-07-03 09:20:05,648 [Salt.loaded.int.module.mine
2014-07-03 09:21:05,619 [Salt.loaded.int.module.mine
2014-07-03 09:21:05,748 [Salt.loaded.int.module.mine
2014-07-03 09:22:05,713 [Salt.loaded.int.module.mine
2014-07-03 09:22:05,843 [Salt.loaded.int.module.mine
2014-07-03 09:23:05,808 [Salt.loaded.int.module.mine
2014-07-03 09:23:05,938 [Salt.loaded.int.module.mine
2014-07-03 09:24:05,901 [Salt.loaded.int.module.mine
2014-07-03 09:24:06,026 [Salt.loaded.int.module.mine
2014-07-03 09:25:05,995 [Salt.loaded.int.module.mine
2014-07-03 09:25:06,120 [Salt.loaded.int.module.mine
2014-07-03 09:26:05,088 [Salt.loaded.int.module.mine
2014-07-03 09:26:05,214 [Salt.loaded.int.module.mine
2014-07-03 09:27:05,183 [Salt.loaded.int.module.mine
2014-07-03 09:27:05,319 [Salt.loaded.int.module.mine
2014-07-03 09:28:05,287 [Salt.loaded.int.module.mine
2014-07-03 09:28:05,418 [Salt.loaded.int.module.mine
2014-07-03 09:29:05,373 [Salt.loaded.int.module.mine
2014-07-03 09:29:05,502 [Salt.loaded.int.module.mine
2014-07-03 09:30:05,466 [Salt.loaded.int.module.mine
2014-07-03 09:30:05,591 [Salt.loaded.int.module.mine
2014-07-03 09:31:05,560 [Salt.loaded.int.module.mine
2014-07-03 09:31:05,689 [Salt.loaded.int.module.mine
2014-07-03 09:32:05,655 [Salt.loaded.int.module.mine
2014-07-03 09:32:05,785 [Salt.loaded.int.module.mine
2014-07-03 09:33:05,749 [Salt.loaded.int.module.mine
2014-07-03 09:33:05,874 [Salt.loaded.int.module.mine
2014-07-03 09:34:05,845 [Salt.loaded.int.module.mine
2014-07-03 09:34:05,969 [Salt.loaded.int.module.mine
2014-07-03 09:35:05,937 [Salt.loaded.int.module.mine
2014-07-03 09:35:06,068 [Salt.loaded.int.module.mine
2014-07-03 09:36:05,017 [Salt.loaded.int.module.mine
2014-07-03 09:36:05,141 [Salt.loaded.int.module.mine
2014-07-03 09:37:05,113 [Salt.loaded.int.module.mine
2014-07-03 09:37:05,238 [Salt.loaded.int.module.mine
2014-07-03 09:38:05,208 [Salt.loaded.int.module.mine
2014-07-03 09:38:05,336 [Salt.loaded.int.module.mine
2014-07-03 09:39:05,304 [Salt.loaded.int.module.mine
2014-07-03 09:39:05,428 [Salt.loaded.int.module.mine
2014-07-03 09:40:05,687 [Salt.loaded.int.module.mine
2014-07-03 09:40:05,810 [Salt.loaded.int.module.mine
2014-07-03 09:41:05,781 [Salt.loaded.int.module.mine
2014-07-03 09:41:05,908 [Salt.loaded.int.module.mine


We can also use Mine.send to send data.

The code is as follows Copy Code
[root@vm-10-154-252-82 ~/clusterops/templates] $salt ' 10.154.252.46 ' mine.send network.dig youku.com

10.154.252.46:

True

[Root@vm-10-154-252-82 ~/clusterops/templates]$




We have redefined the rules of mine.

The code is as follows Copy Code

Mine_functions:
Test.ping: []
Cmd.run:
-DATE;DF



We define a collection of time features to determine if the data he gets is a minute interval, and you even mine.get just get the data he had previously generated, not real time.







Some friends still doubt these things can also use the Direct Push module to achieve, but you see below, I defined the Sleep 10s, if the module to take the value, it must sleep 10 seconds before the data can be obtained. But here master gets the data, and it comes back very instantly. Of course, the data was made a minute ago. This is enough for some occasions.



It says, what's the occasion? To a simple rendering haproxy configuration.

The code is as follows Copy Code
/srv/pillar/ Top.sls:

Base:

  ' g@roles:web ':

   -Web

/SRV/PILLAR/WEB.SLS:

Mine_functions:

  Network.ip_addrs: [eth0]


/etc/salt/minion.d/mine.conf:

Mine _interval:5


/srv/salt/haproxy.sls:

Haproxy_config:

  file:

  &nb Sp -Managed

   -Name:/etc/haproxy/config

   -Source:salt://haproxy_co Nfig

   -Template:jinja


/srv/salt/haproxy_config:

<...file contents s Nipped...>


{% for server, Addrs in salt[' Mine.get '] (' roles:web ', ' Network.ip_addrs ', expr_form= ' grain ') . Items ()%}

Server {{server}} {{addrs[0]}}:80 check

{% endfor%}


<...file Contents Snipped...>



Renders the configuration based on some of the characteristics of the Monin client, and it is estimated that you have learned to use the rendering configuration based on grains, but grains data is not timely, although there are ways to make it timely.  

I'm only here to illustrate the scenario where mine and grains are configured through JINJA2 rendering.   It seems to me that grains is more suitable for a long, long time to change. Mine suitable for the change of larger.

Everyone show down saltstack grains data, almost all of which are system and hardware information.

/table>
  code is as follows copy code
[root@vm-10-154-252 -82 ~/clusterops] $salt ' 10.154.252.46 ' grains.item ProductName
10.154.252.46:
  Productname:openstack Nova
[root@vm-10-154-252-82 ~/clusterops] $salt ' 10.154.252.46 ' Grains.item lang
10.154.252.46:
  Lang : Python Erlang
[root@vm-10-154-252-82 ~/clusterops]$
[root@vm-10-154-252-82 ~/clusterops]$
[ root@vm-10-154-252-82 ~/clusterops]$
[root@vm-10-154-252-82 ~/clusterops] $salt ' 10.154.252.46 ' Sys.reload_ Modules
10.154.252.46:
    True
[root@vm-10-154-252-82 ~/clusterops]$




With mine, we can define what we are interested in. You can assign different configuration options based on the load and memory conditions currently used by minon .... Pillar and mine I think we should be able to distinguish.

The code is as follows Copy Code
[root@vm-10-154-252-82 ~/clusterops] $time salt ' 10.154.252.46 ' mine.get ' * ' Status.meminfo|more
10.154.252.46:
----------
10.154.252.46:
----------
Active:
----------
Unit
Kb
Value
506876
Active (anon):
----------
Unit
Kb
Value
94456
Active (file):
----------
Unit
Kb
Value
412420
Anonhugepages:
----------
Unit
Kb
Value
20480
Anonpages:
----------
Unit
Kb
Value
94232
Bounce:
----------



To sum up, we must distinguish between the direct push module and the mine, and the difference between grains and mine. The beholder, the benevolent. You want to use it, or you need your own control.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.