1.Install

1.1. influxdb

sudo yum install influxdb
sudo systemctl start influxdb
Copy the code

If the installation is complete, enter the following command to access the influxDB interface

> influx
Copy the code

1.2. Telegraf modified version

Wget https://dl.influxdata.com/telegraf/releases/telegraf-1.9.1_linux_amd64.tar.gz tar xf Telegraf - 1.9.1 _linux_amd64. Tar. Gz telegraf - versionCopy the code

1.2.3 Starting the Service

config: /etc/telegraf/telegraf.conf

sudo systemctl start telegraf
sudo systemctl status telegraf 
sudo systemctl enable telegraf
Copy the code

1.3. Modified version of Grafana

1.3.1 install grafana

Wget HTTP: / / https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.2-1.x86_64.rpmCopy the code

1.3.2 Starting the Service and Adding boot:

systemctl enable grafana-server
systemctl start grafana-server
Copy the code

1.3.3 Configuration Description

/etc/grafana/grafana.ini
Grafana-server.service grafana-server.service
# the default log file/var/log/grafana/grafana log
# the default database file/var/lib/grafana/grafana db
Copy the code

1.3.4 the add the plugin

Add the plug-in

sudo grafana-cli plugins install grafana-clock-panel
sudo systemctl restart grafana-server
Copy the code

2. Several properties of Grafana that need attention

2.1 Metric

For Mode there are three options:

  1. The default option is Time and means the x-axis represents time and that the data is grouped by time (for example, by hour or by minute).

  2. The Series option means that the data is grouped by series and not by time. The y-axis still represents the value.

  3. The Histogram option converts the graph into a histogram. A Histogram is a kind of bar chart that groups numbers into ranges, often called buckets or bins.

2.2 the Variables

Variables are shown as dropdown select boxes at the top of the dashboard. These dropdowns make it easy to change the data being displayed in your dashboard.

2.2.1 Time interval

  1. Select the New button to create a New template variable
  2. Select the Interval variable type, we can use this variable to express the time Interval, set Name and Label, Name is the variable Name, the actual reference with the $variable Name; The Label itself has no actual function. It is mainly used to display the Label on the interface so that users can understand it more easily.
  3. Can see in the Values, has a large number of preset time intervals, in which we can increase, such as 1 m (1 minute), 1 h (1 hour), 1 d (1 day) such as interval variables in the interface, we can see have been generated is called interval drop-down list box, list included we set the time interval in the default Values
  4. Set the interval for the sequential query to $t (t is the variable Name we set). Select a different time interval in the drop-down box and the chart will switch accordingly.

2.2.2 Drop-down List Based on query results

For details, see Setting interval variables

1. Select the Query type. 2sourceSelect the target data source for your Query. Select the target data source for your Query."find": "terms"."field": "status"}, where status is the target field of our query, which can be replaced by the field you need. Please refer to the official ES documentation for further syntax. Regex supports regular expression filtering for returned status values. 5. Sort Selects a Sort mode. 6. Preview of values controls whether All values are supported. Preview of values enables Preview of All values only in multi-select modeCopy the code

Take Nodename as an example

  1. set Custom Variables ,name as nodename
  2. add the parameter Var - nodename = "test",such as
Use Url http://servername:3000/dashboard/db/dashboard? Refresh = 10 s & var - nodename ="test"Copy the code

  1. In Query: use where clause as shown below:
WHERE nodename =$nodename
Copy the code

you can see the output

select * 
from table
where nodename ="test"
Copy the code

4. Frequently Asked Questions

4.1 How to get the parameter from the URL

for example, nodename

  1. set Custom Variables ,name as nodename
  2. add the parameter Var - nodename = "test",such as
Use Url http://servername:3000/dashboard/db/dashboard? Refresh = 10 s & var - nodename ="test"Copy the code

  1. In Query: use where clause as shown below:
WHERE nodename =$nodename
Copy the code

you can see the output

select * 
from table
where nodename ="test"
Copy the code

4.2 Nginx reverse proxy to Grafana

Grafana configures the nginx reverse proxy

Assign grafana to the location of /grafana/ of www.myserver.com

  1. Nginx configuration
location /grafana/ {
                proxy_pass http://grafana_server:3000/;
                proxy_set_header   Host $host;
        }
Copy the code
  1. Grafana configuration file modified
Grafana.ini = grafana.ini = grafana.ini
domain = www.myserver.com
root_url = %(protocol)s://%(domain)s/grafana
Copy the code

4.3 provisioning

Initialize the import panel. The procedure is as follows

  1. edit the config grafana.ini
# folder that contains provisioning config files that grafana will apply on startup and while running.; provisioning = conf/provisioningCopy the code
  1. add the dashborads.yaml and db.yaml file, location in /etc/grafana/provisioning/dashborads and /etc/grafana/provisioning/databases

5. influxDB+telegraf

5.1 Listening to Multiple Services

  1. Install the corresponding Telegraf on the machine you want to monitor
  2. Also, configure the reported influxDB machines and databases
#Configuration for influxdb server to send metrics to [[outputs. Influxdb]] urls = [http://1x.xxx:8086]# influxdb addressThe database = "telegraf_ali"Required # InfluxDB DatabaseRetention_policy = ""# Data retention policyWrite_consistency = "any"Data write policy, only applicable to cluster modeTimeout = "5 s"Write timeout policyThe username = "telegraf_ali"Database user namePassword = "gPHhbeh"# database password

#user_agent = "telegraf" # collector agent name
Copy the code

5.1.1 the TRY

  1. A Machine Deploymentinfluxdb+telegraf
> influx
> use telegraf;
> SHOW TAG VALUES FROM system WITH KEY=host
You can see information about a host
Copy the code
  1. B Machine Deploymenttelegraf
  2. In machine B, modifytelegraf influxdbAddress, using default telegraf
  3. Restart machine B’stelegrafMachine enters machine A
> influx
> use telegraf;
> SHOW TAG VALUES FROM system WITH KEY=host

Copy the code
  • If one host information is displayed and two hosts are displayed, the operation succeeds

POLICY

> CREATE RETENTION POLICY "2h0m0s" ON "telegraf" DURATION 2h REPLICATION 1 DEFAULT
> SHOW RETENTION POLICIES ON telegraf
name    duration shardGroupDuration replicaN default
----    -------- ------------------ -------- -------
autogen 0s       168h0m0s           1        false
2h0m0s  2h0m0s   1h0m0s             1        true
Copy the code
SELECT time,host,usage_system FROM "autogen".cpu limit2 name: CPU time host usage_system -------- ------------ 1526008670000000000 VM_42_233_centos 1.7262947210419817 1526008670000000000 VM_42_233_centos 1.30130130130254Copy the code
SELECT 100 - usage_idel FROM "autogen"."cpu" WHERE time > now() - 1m and "cpu"='cpu0'
Copy the code

5.2 the COMMAND

SHOW MEASUREMENTS -- Query the table in the current database SHOW FIELD KEYS -- query the fields in all tables in the current database SHOW series from pay -- query key data SHOW TAG KEYS from"pay"-- Check the key tag value SHOW tag VALUES FROM"pay" WITH KEY = "merId"SHOW tag VALUES FROM CPU WITH key IN ("region"."host") WHERE service = 'redis'
DROP SERIES FROM <measurement_name[,measurement_name]> WHERE <tag_key>='<tag_value>'-- Delete key SHOW CONTINUOUS QUERIES -- Check the consecutive execution of the command SHOW QUERIES -- Check the last execution of the command KILL QUERY <qid> -- End the command SHOW RETENTION POLICIES ON */ LIMIT 1 -- Query the first row of all tables in the current database SELECT * FROM pay order by time desclimit 2
select * from  db_name."POLICIES name"Measurement_name -- Specifies the table data in the data reserve under the database to be queried. Measurement_name specifies the table data in the data reserve under the database. Measurement_name Specifies the table data in the data reserve"query"Drop MEASUREMENT; drop MEASUREMENT"query"Delete FROM CPU delete FROM CPU WHERE time <'2000-01-01T00:00:00Z'
DELETE WHERE time < '2000-01-01T00:00:00Z'DROP the DATABASE"testMysql > DROP RETENTION POLICY DROP RETENTION POLICY"dbbak"ON myDB -- Delete reserved data to dBBAK data DROP SERIES from paywhere tag_key=' 'DROP SHARD 1 SHOW SHARD GROUPS SHOW SUBSCRIPTIONS DROP SHARD GROUPS SHOW SUBSCRIPTIONSCopy the code

5.3 grafana tools

- [Puppet](https://forge.puppet.com/puppet/grafana)
- [Ansible](https://github.com/cloudalchemy/ansible-grafana)
- [Chef](https://github.com/JonathanTron/chef-grafana)
- [Saltstack](https://github.com/salt-formulas/salt-formula-grafana)
- [Jsonnet](https://github.com/grafana/grafonnet-lib/)
- [quick install](https://github.com/samuelebistoletti/docker-statsd-influxdb-grafana)

Copy the code

5.3.1 quick install

Iptables No chain/target/match by that name

docker run -d-p 300:3000 grafana/grafana:5.1.0 Error Response from daemon: Cannot start container 565c06efde6cd4411e2596ef3d726817c58dd777bc5fd13762e0c34d86076b9e: iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d0/0 --dport 3888 -j DNAT --to-destination 192.168.42.11:3888! -i docker0: iptables: No chain/target/match by that nameCopy the code

5.3.2 Solution:

vim /etc/sysconfig/iptables

*nat
:PREROUTING ACCEPT [27:11935]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [598:57368]
:POSTROUTING ACCEPT [591:57092]
:DOCKER - [0:0]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -s172.17.0.0/16! -o docker0 -j MASQUERADE COMMIT *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :DOCKER - [0:0] -A INPUT -i lo -j ACCEPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT-s 10.0.0.0/8 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
-A INPUT -s 172.16.0.0/12 -j ACCEPT
-A INPUT -s192.168.0.0/16 -j ACCEPT -a INPUT -p icmp -m icmp --icmp-type 8 -j DROP -A INPUT -p TCP -m TCP --dport 80 -j ACCEPT -a INPUT -p tcp -m tcp --dport 3000 -j ACCEPT -A INPUT -p tcp -m tcp --dport 36091 -j ACCEPT -A INPUT -j DROP -A FORWARD -j  DROP -A OUTPUT -j ACCEPT COMMITCopy the code

6. remove

6.1 remove influxdb

Uninstall command:

[root@localhost shared]# rpm -q influxdb Influxdb 0.8.7-1. X86_64 [root @ localhost Shared]# rpm -e influxdb 
[root@localhost shared]# rpm -q influxdb 
package influxdb is not installed
Copy the code

Parameter Description:

RPM -e –nodeps: RPM -e –nodeps: RPM -e –nodeps: RPM -e –nodeps: RPM -e –nodeps: RPM -e –nodeps If there are multiple packages with the same name, run the RPM -e –allmatches –nodeps command to delete all packages with the same name and ignore the dependencies.

[root@localhost opt]# ls 
influxdb 
[root@localhost opt]# rm -rf influxdb 
[root@localhost opt]# ls
Copy the code

Handling Port Occupation

name=$(lsof -i:8086|tail -1|awk '" $1 "! =""{print $2}')
if [ -z $name ]
then
	echo "No process can be used to killed!"
	exit 0
fi
id=$(lsof -i:8086|tail -1|awk '" $1 "! =""{print $2}')
kill9 -$id
 
echo "Process name=$name($id) kill!"
exit 0
Copy the code

6.2 remove grafana

Remove the command

sudo yum remove grafana
Copy the code

6.3 remove the telegraf

sudo yum remove telegraf
Copy the code