Merge branch 'master' into dist/eole/2.6.2/master

This commit is contained in:
Philippe Caseiro 2018-06-05 14:32:12 +02:00
commit 0614d2863a
4 changed files with 154 additions and 27 deletions

View File

@ -36,10 +36,6 @@
<variable name='prometheusScrapeTimeout' type='string' description="Temps d'attente avant que la récupération de données échoue">
<value>10s</value>
</variable>
<variable name='ajout_client_prometheus' type='oui/non' description="Ajouter un nouveau client à Prometheus">
<value>non</value>
</variable>
<variable name='nouveau_node_exporter' type='string' description="url/IP du nouveau node exporter" multi="True" mandatory='True'/>
<variable name='job_name_node' type='string' description="Nom du job pour les noeuds" mode='expert'>
<value>node</value>
</variable>
@ -47,6 +43,25 @@
<value>/etc/prometheus/nodes</value>
</variable>
</family>
<family name='Clients prometheus'>
<variable name='ajout_client_prometheus' type='oui/non' description="Ajouter un nouveau client à Prometheus">
<value>non</value>
</variable>
<!-- Client standard -->
<variable name='prCli' type='string' description='Nom du client prometheus' multi='True'/>
<variable name='prCliIP' type='ip' description="Adresse IP du client prometheus"/>
<variable name='prCliSonde' type='string' description="Sonde a utiliser pour ce client">
<value>Node Exporter</value>
</variable>
<variable name='addPrOpenCli' type='oui/non' description="Ajouter un client personnalisé">
<value>non</value>
</variable>
<!-- Client libre -->
<variable name='prOpenCli' type='string' description='Nom du client personnalisé prometheus' multi='True'/>
<variable name='prOpenCliIP' type='ip' description="Adresse IP"/>
<variable name='prOpenCliPort' type='number' description="Port d'écoute de la sonde"/>
</family>
<family name="grafana">
<variable name='grafana_domain' type='string' description="Nom de Domaine ou IP pour accèder à l'interface Grafana" mandatory='True'>
<value>localhost</value>
@ -66,6 +81,20 @@
</family>
</variables>
<constraints>
<group master='prCli'>
<slave>prCliIP</slave>
<slave>prCliSonde</slave>
</group>
<group master='prOpenCli'>
<slave>prOpenCliIP</slave>
<slave>prOpenCliPort</slave>
</group>
<check name='valid_enum' target='prCliSonde'>
<param>['Node Exporter','Port']</param>
</check>
<condition name='disabled_if_in' source='activer_prometheus'>
<param>non</param>
<target type='family'>prometheus</target>
@ -79,7 +108,15 @@
</condition>
<condition name='disabled_if_in' source='ajout_client_prometheus'>
<param>non</param>
<target type='variable'>nouveau_node_exporter</target>
<target type='variable'>prCli</target>
<target type='variable'>prCliIP</target>
<target type='variable'>prCliSonde</target>
</condition>
<condition name='disabled_if_in' source='addPrOpenCli'>
<param>non</param>
<target type='variable'>prOpenCli</target>
<target type='variable'>prOpenCliIP</target>
<target type='variable'>prOpenCliPort</target>
</condition>
</constraints>
<help>

View File

@ -1,12 +0,0 @@
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
User=root
Restart=on-failure
ExecStart=/usr/bin/prometheus --config.file=/etc/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target

91
postservice/88_grafana Executable file
View File

@ -0,0 +1,91 @@
#!/usr/bin/env bash
function importDataSource()
{
local grURL="${1}/api/datasources" # Grafana API URL
local dsName=${2} # Datasource Name
local dsURL="${3}" # Datasource URL
local dsType="prometheus" # Datasource type
cmd="curl"
data=$(cat <<__EOF__
{"name":"${dsName}","type":"${dsType}","url":"${dsURL}","access":"direct"}
__EOF__
)
echo -ne "\tCreating datasource for Prometheus "
res=$(${cmd} "${grURL}" -H "Content-Type: application-json" --data-binary "${data}" 2>&1 )
excode=${?}
case $res in
*"already exists"*)
echo " ... [Exists]"
;;
*"Datasource added"*)
echo " ... [OK]"
;;
*)
echo " ... Ooops ${res}"
;;
esac
}
function importDashboardFromMarket()
{
local grURL="${1}/api/dashboards/import" # API URL to create new Dashboard
local dsName="${2}" # Datasource name (to link dashboard to data)
local dhID="${3}" # Dashboard ID in the market
local dhRev="${4}" # Dashboard Revision to download
local tmpFile=$(mktemp)
local dhFile=$(mktemp)
# URL To download the json file for dashboard
local pubDashBoardURL="https://grafana.com/api/dashboards/${dhID}/revisions/${dhRev}/download"
local cmd="curl"
local dh=$(${cmd} --silent ${pubDashBoardURL} 2>&1)
cat <<_EOF_ > ${tmpFile}
{
"inputs": [ { "name":"DS_LOCALHOST", "type":"datasource", "pluginId":"prometheus", "value":"${dsName}" } ],
"dashboard": { "title": "Surveillance Système", ${dh:1:-1} },
"folderId": 0,
"overwrite": true
}
_EOF_
res=$(${cmd} "${grURL}" -H "Content-Type: application-json" --data-binary "@${tmpFile}" 2>&1 )
excode=${?}
case $res in
*"\"imported\":true"*)
echo " ... [Overwrited]"
;;
*"Datasource added"*)
echo " ... [OK]"
;;
*)
echo " ... Ooops ${res}"
;;
esac
# rm -rf ${tmpFile}
}
grafanaHost=$(CreoleGet srvGrafanaIP 192.168.30.57)
grafanaPort=$(CreoleGet srvGrafanaPort 3000)
grafanaUser="admin"
grafanaPasswd=$(CreoleGet grafana_admin_passwd admin)
grafanaURL="http://${grafanaUser}:${grafanaPasswd}@${grafanaHost}:${grafanaPort}"
datasource_name=$(CreoleGet promDataSource "prometheus")
promHost=$(CreoleGet adresse_ip_eth0)
promPort='9090'
datasourceURL="http://${promHost}:${promPort}"
importDataSource ${grafanaURL} ${datasource_name} ${datasourceURL}
echo
echo -ne "\tImporting Node Exporter Full Dashboard "
importDashboardFromMarket ${grafanaURL} ${datasource_name} 1860 11
rm -rf ${dashBoardFile}

View File

@ -12,23 +12,34 @@ scrape_configs:
honor_labels: true
static_configs:
- targets: ['%%nom_domaine_machine:9090']
- targets: ['%%nom_domaine_machine:9090'%slurp
%if %%getVar('activerSndNodeExpoter','non') == 'oui'
- targets: ['%%nom_domaine_machine:9100']
, '%%nom_domaine_machine:9100'%slurp
%end if
]
- job_name: '%%job_name_node'
file_sd_configs:
- files: [ "%%job_file_config/*.yml" ]
%if %%is_empty('ajout_client_prometheus') or %%is_empty('addPrOpenCli')
# Nothing to configure
%else
static_configs:
%if %%getVar('ajout_client_prometheus','non') == 'oui'
%if not %%is_empty(%%nouveau_node_exporter)
%for %%client_prometheus in %%nouveau_node_exporter
- targets: ['%%client_prometheus:9100']
- targets: [ "%%adresse_ip_eth0:9100"%slurp
%if %%getVar('ajout_client_prometheus','non') == 'oui'
%for %%cliPr in %%getVar('prCli',[])
%if %%cliPr.prCliSonde == 'Node Exporter'
, '%%cliPr.prCliIP:9100'%slurp
%end if
%end for
%end if
%if %%getVar('addPrOpenCli','non') == 'oui'
%for %%cliOpen in %%getVar('prOpenCli',[])
, '%%cliOpen.prOpenCliIP:%%cliOpen.prOpenCliPort'%slurp
%end for
%end if
]
%end if
#alerting:
# alertmanagers:
# - scheme: https